Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Get rid of user-specified refs
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jan 5, 2017
1 parent 59803d3 commit 0c0064c
Show file tree
Hide file tree
Showing 44 changed files with 645 additions and 69 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ mason_use(pixelmatch VERSION 0.10.0 HEADER_ONLY)
mason_use(geojson VERSION 0.4.0 HEADER_ONLY)
mason_use(polylabel VERSION 1.0.2 HEADER_ONLY)

add_definitions(-DRAPIDJSON_HAS_STDSTRING=1)

if(WITH_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
Expand Down
3 changes: 3 additions & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ set(MBGL_CORE_FILES
src/mbgl/style/cross_faded_property_evaluator.cpp
src/mbgl/style/cross_faded_property_evaluator.hpp
src/mbgl/style/function.cpp
src/mbgl/style/group_by_layout.cpp
src/mbgl/style/group_by_layout.hpp
src/mbgl/style/layer.cpp
src/mbgl/style/layer_impl.cpp
src/mbgl/style/layer_impl.hpp
Expand Down Expand Up @@ -260,6 +262,7 @@ set(MBGL_CORE_FILES
include/mbgl/style/conversion/property_value.hpp
include/mbgl/style/conversion/source.hpp
include/mbgl/style/conversion/tileset.hpp
src/mbgl/style/conversion/stringify.hpp

# style/layers
include/mbgl/style/layers/background_layer.hpp
Expand Down
2 changes: 2 additions & 0 deletions cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ set(MBGL_TEST_FILES

# style/conversion
test/style/conversion/geojson_options.test.cpp
test/style/conversion/stringify.test.cpp

# style
test/style/filter.test.cpp
test/style/functions.test.cpp
test/style/group_by_layout.test.cpp
test/style/source.test.cpp
test/style/style.test.cpp
test/style/style_layer.test.cpp
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class Layer : public mbgl::util::noncopyable {

// Private implementation
const std::unique_ptr<Impl> baseImpl;

friend std::string layoutKey(const Layer&);
};

} // namespace style
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/util/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Color {
static Color blue() { return { 0.0f, 0.0f, 1.0f, 1.0f }; };

static optional<Color> parse(const std::string&);
std::string stringify() const;
};

inline bool operator==(const Color& colorA, const Color& colorB) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"express": "^4.11.1",
"lodash": "^4.16.4",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#49e8b407bdbbe6f7c92dbcb56d3d51f425fc2653",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#2bdca923fc4190156b5a22af71be29442451db54",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#7bf5725a2dfe848463db85ff2c85a0f9551d18bf",
"mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
"pixelmatch": "^4.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/annotation/style_sourced_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ void StyleSourcedAnnotationImpl::updateStyle(Style& style) const {
return;

if (sourceLayer->is<LineLayer>()) {
std::unique_ptr<Layer> layer = sourceLayer->baseImpl->copy(layerID, "", AnnotationManager::SourceID);
std::unique_ptr<Layer> layer = sourceLayer->baseImpl->copy(layerID, AnnotationManager::SourceID);
layer->as<LineLayer>()->setSourceLayer(layerID);
layer->as<LineLayer>()->setVisibility(VisibilityType::Visible);
style.addLayer(std::move(layer), sourceLayer->getID());
} else if (sourceLayer->is<FillLayer>()) {
std::unique_ptr<Layer> layer = sourceLayer->baseImpl->copy(layerID, "", AnnotationManager::SourceID);
std::unique_ptr<Layer> layer = sourceLayer->baseImpl->copy(layerID, AnnotationManager::SourceID);
layer->as<FillLayer>()->setSourceLayer(layerID);
layer->as<FillLayer>()->setVisibility(VisibilityType::Visible);
style.addLayer(std::move(layer), sourceLayer->getID());
Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/layout/symbol_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <mbgl/layout/clip_lines.hpp>
#include <mbgl/renderer/symbol_bucket.hpp>
#include <mbgl/style/filter_evaluator.hpp>
#include <mbgl/style/layer.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
#include <mbgl/text/glyph_atlas.hpp>
#include <mbgl/text/get_anchors.hpp>
Expand All @@ -26,7 +27,7 @@ namespace mbgl {

using namespace style;

SymbolLayout::SymbolLayout(std::string bucketName_,
SymbolLayout::SymbolLayout(std::vector<std::unique_ptr<Layer>> layers_,
std::string sourceLayerName_,
uint32_t overscaling_,
float zoom_,
Expand All @@ -36,7 +37,7 @@ SymbolLayout::SymbolLayout(std::string bucketName_,
style::SymbolLayoutProperties::Evaluated layout_,
float textMaxSize_,
SpriteAtlas& spriteAtlas_)
: bucketName(std::move(bucketName_)),
: layers(std::move(layers_)),
sourceLayerName(std::move(sourceLayerName_)),
overscaling(overscaling_),
zoom(zoom_),
Expand Down Expand Up @@ -253,7 +254,7 @@ void SymbolLayout::addFeature(const SymbolFeature& feature,
? SymbolPlacementType::Point
: layout.get<SymbolPlacement>();
const float textRepeatDistance = symbolSpacing / 2;
IndexedSubfeature indexedFeature = {feature.index, sourceLayerName, bucketName, symbolInstances.size()};
IndexedSubfeature indexedFeature = {feature.index, sourceLayerName, layers.at(0)->getID(), symbolInstances.size()};

auto addSymbolInstance = [&] (const GeometryCoordinates& line, Anchor& anchor) {
// https://github.com/mapbox/vector-tile-spec/tree/master/2.1#41-layers
Expand Down
5 changes: 3 additions & 2 deletions src/mbgl/layout/symbol_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class SymbolBucket;

namespace style {
class Filter;
class Layer;
} // namespace style

struct Anchor;

class SymbolLayout {
public:
SymbolLayout(std::string bucketName_,
SymbolLayout(std::vector<std::unique_ptr<style::Layer>>,
std::string sourceLayerName_,
uint32_t overscaling,
float zoom,
Expand Down Expand Up @@ -55,7 +56,7 @@ class SymbolLayout {

State state = Pending;

const std::string bucketName;
const std::vector<std::unique_ptr<style::Layer>> layers;
const std::string sourceLayerName;

private:
Expand Down
256 changes: 256 additions & 0 deletions src/mbgl/style/conversion/stringify.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
#pragma once

#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/ignore.hpp>
#include <mbgl/util/rapidjson.hpp>

#include <array>
#include <vector>
#include <unordered_map>

namespace mbgl {
namespace style {
namespace conversion {

template <class Writer>
void stringify(Writer& writer, NullValue) {
writer.Null();
}

template <class Writer>
void stringify(Writer& writer, bool v) {
writer.Bool(v);
}

template <class Writer>
void stringify(Writer& writer, uint64_t v) {
writer.Uint64(v);
}

template <class Writer>
void stringify(Writer& writer, int64_t v) {
writer.Int64(v);
}

template <class Writer>
void stringify(Writer& writer, double v) {
writer.Double(v);
}

template <class Writer>
void stringify(Writer& writer, const std::string& v) {
writer.String(v);
}

template <class Writer, class T, class Enable = std::enable_if_t<std::is_enum<T>::value>>
void stringify(Writer& writer, const T& v) {
writer.String(Enum<T>::toString(v));
}

template <class Writer>
void stringify(Writer& writer, const Color& v) {
writer.String(v.stringify());
}

template <class Writer>
void stringify(Writer& writer, const std::array<float, 2>& v) {
writer.StartArray();
writer.Double(v[0]);
writer.Double(v[1]);
writer.EndArray();
}

template <class Writer>
void stringify(Writer& writer, const std::array<float, 4>& v) {
writer.StartArray();
writer.Double(v[0]);
writer.Double(v[1]);
writer.Double(v[2]);
writer.Double(v[3]);
writer.EndArray();
}

template <class Writer>
void stringify(Writer&, const Value&);

template <class Writer, class T>
void stringify(Writer& writer, const std::vector<T>& v) {
writer.StartArray();
for (const auto& e : v) {
stringify(writer, e);
}
writer.EndArray();
}

template <class Writer, class T>
void stringify(Writer& writer, const std::unordered_map<std::string, T>& m) {
writer.StartObject();
for (const auto& p : m) {
writer.Key(p.first.data(), static_cast<unsigned>(p.first.size()));
stringify(writer, p.second);
}
writer.EndObject();
}

template <class Writer>
void stringify(Writer& writer, const Value& v) {
Value::visit(v, [&] (const auto& v_) { stringify(writer, v_); });
}

template <class Writer>
class StringifyFilter {
public:
Writer& writer;

void operator()(const NullFilter&) {
writer.Null();
}

void operator()(const EqualsFilter& f) {
stringifyBinaryFilter(f, "==");
}

void operator()(const NotEqualsFilter& f) {
stringifyBinaryFilter(f, "!=");
}

void operator()(const LessThanFilter& f) {
stringifyBinaryFilter(f, "<");
}

void operator()(const LessThanEqualsFilter& f) {
stringifyBinaryFilter(f, "<=");
}

void operator()(const GreaterThanFilter& f) {
stringifyBinaryFilter(f, ">");
}

void operator()(const GreaterThanEqualsFilter& f) {
stringifyBinaryFilter(f, ">=");
}

void operator()(const InFilter& f) {
stringifySetFilter(f, "in");
}

void operator()(const NotInFilter& f) {
stringifySetFilter(f, "!in");
}

void operator()(const AllFilter& f) {
stringifyCompoundFilter(f, "all");
}

void operator()(const AnyFilter& f) {
stringifyCompoundFilter(f, "any");
}

void operator()(const NoneFilter& f) {
stringifyCompoundFilter(f, "none");
}

void operator()(const HasFilter& f) {
stringifyUnaryFilter(f, "has");
}

void operator()(const NotHasFilter& f) {
stringifyUnaryFilter(f, "!has");
}

private:
template <class F>
void stringifyBinaryFilter(const F& f, const char * op) {
writer.StartArray();
writer.String(op);
writer.String(f.key);
stringify(writer, f.value);
writer.EndArray();
}

template <class F>
void stringifySetFilter(const F& f, const char * op) {
writer.StartArray();
writer.String(op);
writer.String(f.key);
for (const auto& value : f.values) {
stringify(writer, value);
}
writer.EndArray();
}

template <class F>
void stringifyCompoundFilter(const F& f, const char * op) {
writer.StartArray();
writer.String(op);
for (const auto& filter : f.filters) {
Filter::visit(filter, *this);
}
writer.EndArray();
}

template <class F>
void stringifyUnaryFilter(const F& f, const char * op) {
writer.StartArray();
writer.String(op);
writer.String(f.key);
writer.EndArray();
}
};

template <class Writer>
void stringify(Writer& writer, const Filter& f) {
Filter::visit(f, StringifyFilter<Writer> { writer });
}

template <class Writer>
void stringify(Writer& writer, const Undefined&) {
assert(false); // Should be omitted entirely instead.
writer.Null();
}

template <class Writer, class T>
void stringify(Writer& writer, const Function<T>& f) {
writer.StartObject();
writer.Key("base");
writer.Double(f.getBase());
writer.Key("stops");
writer.StartArray();
for (const auto& stop : f.getStops()) {
writer.StartArray();
writer.Double(stop.first);
stringify(writer, stop.second);
writer.EndArray();
}
writer.EndArray();
writer.EndObject();
}

template <class Writer, class T>
void stringify(Writer& writer, const PropertyValue<T>& v) {
v.evaluate([&] (const auto& v_) { stringify(writer, v_); });
}

template <class Property, class Writer, class T>
void stringify(Writer& writer, const PropertyValue<T>& value) {
if (value) {
writer.Key(Property::key);
stringify(writer, value);
}
}

template <class Writer, class... Ps>
void stringify(Writer& writer, const LayoutProperties<Ps...>& ps) {
writer.StartObject();
util::ignore({ (stringify<Ps>(writer, ps.unevaluated.template get<Ps>()), 0)... });
writer.EndObject();
}

} // namespace conversion
} // namespace style
} // namespace mbgl
Loading

0 comments on commit 0c0064c

Please sign in to comment.