diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-12-14 16:07:15 -0800 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-12-14 16:43:35 -0800 |
commit | 95cef66e229f3ae346a66ea87f95a8a660c3108f (patch) | |
tree | 55a571023c47fb893314dbc98bc7d4cc6cca6273 | |
parent | 9b8f5d3be1d25a0eefe7f9f22544d439f54d92b1 (diff) | |
download | qtlocation-mapboxgl-95cef66e229f3ae346a66ea87f95a8a660c3108f.tar.gz |
[core] change RapidJSON usage to use CrtAllocator and bump GeoJSON VT
36 files changed, 165 insertions, 168 deletions
diff --git a/scripts/android/configure.sh b/scripts/android/configure.sh index 7c5e3e926a..2e3e7b9d7c 100644 --- a/scripts/android/configure.sh +++ b/scripts/android/configure.sh @@ -8,7 +8,7 @@ LIBUV_VERSION=1.7.5 ZLIB_VERSION=system NUNICODE_VERSION=1.6 LIBZIP_VERSION=0.11.2 -GEOJSONVT_VERSION=3.0.1 +GEOJSONVT_VERSION=3.1.0 VARIANT_VERSION=1.0 RAPIDJSON_VERSION=1.0.2 diff --git a/scripts/ios/configure.sh b/scripts/ios/configure.sh index 3826d93571..ee6d60de2f 100644 --- a/scripts/ios/configure.sh +++ b/scripts/ios/configure.sh @@ -4,6 +4,6 @@ BOOST_VERSION=1.59.0 SQLITE_VERSION=system LIBUV_VERSION=1.7.5 ZLIB_VERSION=system -GEOJSONVT_VERSION=3.0.1 +GEOJSONVT_VERSION=3.1.0 VARIANT_VERSION=1.0 RAPIDJSON_VERSION=1.0.2 diff --git a/scripts/linux/configure.sh b/scripts/linux/configure.sh index 0da9f8c3cd..1c2dff9d27 100644 --- a/scripts/linux/configure.sh +++ b/scripts/linux/configure.sh @@ -10,7 +10,7 @@ SQLITE_VERSION=3.9.1 LIBUV_VERSION=1.7.5 ZLIB_VERSION=system NUNICODE_VERSION=1.6 -GEOJSONVT_VERSION=3.0.1 +GEOJSONVT_VERSION=3.1.0 VARIANT_VERSION=1.0 RAPIDJSON_VERSION=1.0.2 GTEST_VERSION=1.7.0 diff --git a/scripts/osx/configure.sh b/scripts/osx/configure.sh index 871b09c941..138738bb44 100644 --- a/scripts/osx/configure.sh +++ b/scripts/osx/configure.sh @@ -10,7 +10,7 @@ SQLITE_VERSION=3.9.1 LIBUV_VERSION=1.7.5 ZLIB_VERSION=system NUNICODE_VERSION=1.6 -GEOJSONVT_VERSION=3.0.1 +GEOJSONVT_VERSION=3.1.0 VARIANT_VERSION=1.0 RAPIDJSON_VERSION=1.0.2 GTEST_VERSION=1.7.0 diff --git a/src/mbgl/layer/background_layer.cpp b/src/mbgl/layer/background_layer.cpp index cea4c2c9b9..25fbe620e5 100644 --- a/src/mbgl/layer/background_layer.cpp +++ b/src/mbgl/layer/background_layer.cpp @@ -7,7 +7,7 @@ std::unique_ptr<StyleLayer> BackgroundLayer::clone() const { return std::make_unique<BackgroundLayer>(*this); } -void BackgroundLayer::parsePaints(const JSVal& layer) { +void BackgroundLayer::parsePaints(const JSValue& layer) { paint.opacity.parse("background-opacity", layer); paint.color.parse("background-color", layer); paint.pattern.parse("background-pattern", layer); diff --git a/src/mbgl/layer/background_layer.hpp b/src/mbgl/layer/background_layer.hpp index 4a34289193..063331fade 100644 --- a/src/mbgl/layer/background_layer.hpp +++ b/src/mbgl/layer/background_layer.hpp @@ -17,8 +17,8 @@ class BackgroundLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; - void parseLayout(const JSVal&) override {}; - void parsePaints(const JSVal&) override; + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; void cascade(const StyleCascadeParameters&) override; bool recalculate(const StyleCalculationParameters&) override; diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/layer/circle_layer.cpp index 9001723439..23fbc06d86 100644 --- a/src/mbgl/layer/circle_layer.cpp +++ b/src/mbgl/layer/circle_layer.cpp @@ -8,7 +8,7 @@ std::unique_ptr<StyleLayer> CircleLayer::clone() const { return std::make_unique<CircleLayer>(*this); } -void CircleLayer::parsePaints(const JSVal& layer) { +void CircleLayer::parsePaints(const JSValue& layer) { paint.radius.parse("circle-radius", layer); paint.color.parse("circle-color", layer); paint.opacity.parse("circle-opacity", layer); diff --git a/src/mbgl/layer/circle_layer.hpp b/src/mbgl/layer/circle_layer.hpp index 80a94c7401..03169ca065 100644 --- a/src/mbgl/layer/circle_layer.hpp +++ b/src/mbgl/layer/circle_layer.hpp @@ -24,8 +24,8 @@ class CircleLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; - void parseLayout(const JSVal&) override {}; - void parsePaints(const JSVal&) override; + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; void cascade(const StyleCascadeParameters&) override; bool recalculate(const StyleCalculationParameters&) override; diff --git a/src/mbgl/layer/custom_layer.hpp b/src/mbgl/layer/custom_layer.hpp index efdc5f397b..ccc1a4b485 100644 --- a/src/mbgl/layer/custom_layer.hpp +++ b/src/mbgl/layer/custom_layer.hpp @@ -24,8 +24,8 @@ public: private: std::unique_ptr<StyleLayer> clone() const final; - void parseLayout(const JSVal&) final {} - void parsePaints(const JSVal&) final {} + void parseLayout(const JSValue&) final {} + void parsePaints(const JSValue&) final {} void cascade(const StyleCascadeParameters&) final {} bool recalculate(const StyleCalculationParameters&) final; diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/layer/fill_layer.cpp index cde5c26837..6a5a9de4f3 100644 --- a/src/mbgl/layer/fill_layer.cpp +++ b/src/mbgl/layer/fill_layer.cpp @@ -8,7 +8,7 @@ std::unique_ptr<StyleLayer> FillLayer::clone() const { return std::make_unique<FillLayer>(*this); } -void FillLayer::parsePaints(const JSVal& layer) { +void FillLayer::parsePaints(const JSValue& layer) { paint.antialias.parse("fill-antialias", layer); paint.opacity.parse("fill-opacity", layer); paint.color.parse("fill-color", layer); diff --git a/src/mbgl/layer/fill_layer.hpp b/src/mbgl/layer/fill_layer.hpp index 93514ee425..ee079a5c8a 100644 --- a/src/mbgl/layer/fill_layer.hpp +++ b/src/mbgl/layer/fill_layer.hpp @@ -21,8 +21,8 @@ class FillLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; - void parseLayout(const JSVal&) override {}; - void parsePaints(const JSVal&) override; + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; void cascade(const StyleCascadeParameters&) override; bool recalculate(const StyleCalculationParameters&) override; diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp index 136721fb01..1c6c1dc8d6 100644 --- a/src/mbgl/layer/line_layer.cpp +++ b/src/mbgl/layer/line_layer.cpp @@ -9,14 +9,14 @@ std::unique_ptr<StyleLayer> LineLayer::clone() const { return std::make_unique<LineLayer>(*this); } -void LineLayer::parseLayout(const JSVal& value) { +void LineLayer::parseLayout(const JSValue& value) { layout.cap.parse("line-cap", value); layout.join.parse("line-join", value); layout.miterLimit.parse("line-miter-limit", value); layout.roundLimit.parse("line-round-limit", value); } -void LineLayer::parsePaints(const JSVal& layer) { +void LineLayer::parsePaints(const JSValue& layer) { paint.opacity.parse("line-opacity", layer); paint.color.parse("line-color", layer); paint.translate.parse("line-translate", layer); diff --git a/src/mbgl/layer/line_layer.hpp b/src/mbgl/layer/line_layer.hpp index b1917b4ca3..027f7a9c06 100644 --- a/src/mbgl/layer/line_layer.hpp +++ b/src/mbgl/layer/line_layer.hpp @@ -40,8 +40,8 @@ class LineLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; - void parseLayout(const JSVal&) override; - void parsePaints(const JSVal&) override; + void parseLayout(const JSValue&) override; + void parsePaints(const JSValue&) override; void cascade(const StyleCascadeParameters&) override; bool recalculate(const StyleCalculationParameters&) override; diff --git a/src/mbgl/layer/raster_layer.cpp b/src/mbgl/layer/raster_layer.cpp index 3ce9ed36e8..401097073d 100644 --- a/src/mbgl/layer/raster_layer.cpp +++ b/src/mbgl/layer/raster_layer.cpp @@ -7,7 +7,7 @@ std::unique_ptr<StyleLayer> RasterLayer::clone() const { return std::make_unique<RasterLayer>(*this); } -void RasterLayer::parsePaints(const JSVal& layer) { +void RasterLayer::parsePaints(const JSValue& layer) { paint.opacity.parse("raster-opacity", layer); paint.hueRotate.parse("raster-hue-rotate", layer); paint.brightnessMin.parse("raster-brightness-min", layer); diff --git a/src/mbgl/layer/raster_layer.hpp b/src/mbgl/layer/raster_layer.hpp index fc571617ab..bf912bad4a 100644 --- a/src/mbgl/layer/raster_layer.hpp +++ b/src/mbgl/layer/raster_layer.hpp @@ -21,8 +21,8 @@ class RasterLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; - void parseLayout(const JSVal&) override {}; - void parsePaints(const JSVal&) override; + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; void cascade(const StyleCascadeParameters&) override; bool recalculate(const StyleCalculationParameters&) override; diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp index dd810941d9..25dfeeae0a 100644 --- a/src/mbgl/layer/symbol_layer.cpp +++ b/src/mbgl/layer/symbol_layer.cpp @@ -9,7 +9,7 @@ std::unique_ptr<StyleLayer> SymbolLayer::clone() const { return std::make_unique<SymbolLayer>(*this); } -void SymbolLayer::parseLayout(const JSVal& value) { +void SymbolLayer::parseLayout(const JSValue& value) { layout.placement.parse("symbol-placement", value); layout.spacing.parse("symbol-spacing", value); layout.avoidEdges.parse("symbol-avoid-edges", value); @@ -45,7 +45,7 @@ void SymbolLayer::parseLayout(const JSVal& value) { layout.text.optional.parse("text-optional", value); } -void SymbolLayer::parsePaints(const JSVal& layer) { +void SymbolLayer::parsePaints(const JSValue& layer) { paint.icon.opacity.parse("icon-opacity", layer); paint.icon.color.parse("icon-color", layer); paint.icon.haloColor.parse("icon-halo-color", layer); diff --git a/src/mbgl/layer/symbol_layer.hpp b/src/mbgl/layer/symbol_layer.hpp index 42d0bb9c74..730bd2ad4a 100644 --- a/src/mbgl/layer/symbol_layer.hpp +++ b/src/mbgl/layer/symbol_layer.hpp @@ -86,8 +86,8 @@ class SymbolLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; - void parseLayout(const JSVal&) override; - void parsePaints(const JSVal&) override; + void parseLayout(const JSValue&) override; + void parsePaints(const JSValue&) override; void cascade(const StyleCascadeParameters&) override; bool recalculate(const StyleCalculationParameters&) override; diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 7dd5709c43..142564334f 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -77,7 +77,7 @@ void Source::load() { return; } - rapidjson::Document d; + rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d; d.Parse<0>(res.data->c_str()); if (d.HasParseError()) { diff --git a/src/mbgl/map/source_info.cpp b/src/mbgl/map/source_info.cpp index 8f1b42ea93..07346ea690 100644 --- a/src/mbgl/map/source_info.cpp +++ b/src/mbgl/map/source_info.cpp @@ -11,12 +11,12 @@ namespace mbgl { namespace { -void parse(const rapidjson::Value& value, std::vector<std::string>& target, const char* name) { +void parse(const JSValue& value, std::vector<std::string>& target, const char* name) { if (!value.HasMember(name)) { return; } - const rapidjson::Value& property = value[name]; + const JSValue& property = value[name]; if (!property.IsArray()) { return; } @@ -32,12 +32,12 @@ void parse(const rapidjson::Value& value, std::vector<std::string>& target, cons } } -void parse(const rapidjson::Value& value, std::string& target, const char* name) { +void parse(const JSValue& value, std::string& target, const char* name) { if (!value.HasMember(name)) { return; } - const rapidjson::Value& property = value[name]; + const JSValue& property = value[name]; if (!property.IsString()) { return; } @@ -45,12 +45,12 @@ void parse(const rapidjson::Value& value, std::string& target, const char* name) target = { property.GetString(), property.GetStringLength() }; } -void parse(const rapidjson::Value& value, uint16_t& target, const char* name) { +void parse(const JSValue& value, uint16_t& target, const char* name) { if (!value.HasMember(name)) { return; } - const rapidjson::Value& property = value[name]; + const JSValue& property = value[name]; if (!property.IsUint()) { return; } @@ -64,12 +64,12 @@ void parse(const rapidjson::Value& value, uint16_t& target, const char* name) { } template <size_t N> -void parse(const rapidjson::Value& value, std::array<float, N>& target, const char* name) { +void parse(const JSValue& value, std::array<float, N>& target, const char* name) { if (!value.HasMember(name)) { return; } - const rapidjson::Value& property = value[name]; + const JSValue& property = value[name]; if (!property.IsArray() || property.Size() != N) { return; } @@ -90,7 +90,7 @@ void parse(const rapidjson::Value& value, std::array<float, N>& target, const ch // Destructor in implementation file because header only contains forward declarations. SourceInfo::~SourceInfo() = default; -void SourceInfo::parseTileJSONProperties(const rapidjson::Value& value) { +void SourceInfo::parseTileJSONProperties(const JSValue& value) { parse(value, tiles, "tiles"); parse(value, min_zoom, "minzoom"); parse(value, max_zoom, "maxzoom"); @@ -99,7 +99,7 @@ void SourceInfo::parseTileJSONProperties(const rapidjson::Value& value) { parse(value, bounds, "bounds"); } -void SourceInfo::parseGeoJSON(const rapidjson::Value& value) { +void SourceInfo::parseGeoJSON(const JSValue& value) { using namespace mapbox::geojsonvt; try { diff --git a/src/mbgl/map/source_info.hpp b/src/mbgl/map/source_info.hpp index 81c79bd823..38fa411bcf 100644 --- a/src/mbgl/map/source_info.hpp +++ b/src/mbgl/map/source_info.hpp @@ -6,9 +6,9 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/constants.hpp> +#include <mbgl/util/rapidjson.hpp> #include <mapbox/variant.hpp> -#include <rapidjson/document.h> #include <array> #include <vector> @@ -38,8 +38,8 @@ public: std::string source_id = ""; std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> geojsonvt; - void parseTileJSONProperties(const rapidjson::Value&); - void parseGeoJSON(const rapidjson::Value&); + void parseTileJSONProperties(const JSValue&); + void parseGeoJSON(const JSValue&); std::string tileURL(const TileID& id, float pixelRatio) const; }; diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp index 3b6464be9e..59dce93241 100644 --- a/src/mbgl/sprite/sprite_parser.cpp +++ b/src/mbgl/sprite/sprite_parser.cpp @@ -4,9 +4,7 @@ #include <mbgl/platform/log.hpp> #include <mbgl/util/image.hpp> - -#include <rapidjson/document.h> -#include <rapidjson/error/en.h> +#include <mbgl/util/rapidjson.hpp> #include <cmath> #include <limits> @@ -59,7 +57,7 @@ SpriteImagePtr createSpriteImage(const PremultipliedImage& image, namespace { -inline uint16_t getUInt16(const rapidjson::Value& value, const char* name, const uint16_t def = 0) { +inline uint16_t getUInt16(const JSValue& value, const char* name, const uint16_t def = 0) { if (value.HasMember(name)) { auto& v = value[name]; if (v.IsUint() && v.GetUint() <= std::numeric_limits<uint16_t>::max()) { @@ -73,7 +71,7 @@ inline uint16_t getUInt16(const rapidjson::Value& value, const char* name, const return def; } -inline double getDouble(const rapidjson::Value& value, const char* name, const double def = 0) { +inline double getDouble(const JSValue& value, const char* name, const double def = 0) { if (value.HasMember(name)) { auto& v = value[name]; if (v.IsNumber()) { @@ -86,7 +84,7 @@ inline double getDouble(const rapidjson::Value& value, const char* name, const d return def; } -inline bool getBoolean(const rapidjson::Value& value, const char* name, const bool def = false) { +inline bool getBoolean(const JSValue& value, const char* name, const bool def = false) { if (value.HasMember(name)) { auto& v = value[name]; if (v.IsBool()) { @@ -102,8 +100,6 @@ inline bool getBoolean(const rapidjson::Value& value, const char* name, const bo } // namespace SpriteParseResult parseSprite(const std::string& image, const std::string& json) { - using namespace rapidjson; - Sprites sprites; PremultipliedImage raster; @@ -113,7 +109,7 @@ SpriteParseResult parseSprite(const std::string& image, const std::string& json) return std::string("Could not parse sprite image"); } - Document doc; + JSDocument doc; doc.Parse<0>(json.c_str()); if (doc.HasParseError()) { @@ -123,9 +119,9 @@ SpriteParseResult parseSprite(const std::string& image, const std::string& json) } else if (!doc.IsObject()) { return std::string("Sprite JSON root must be an object"); } else { - for (Value::ConstMemberIterator itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) { + for (JSValue::ConstMemberIterator itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) { const std::string name = { itr->name.GetString(), itr->name.GetStringLength() }; - const Value& value = itr->value; + const JSValue& value = itr->value; if (value.IsObject()) { const uint16_t x = getUInt16(value, "x", 0); diff --git a/src/mbgl/style/filter_expression.cpp b/src/mbgl/style/filter_expression.cpp index a93674410c..e8231b82e0 100644 --- a/src/mbgl/style/filter_expression.cpp +++ b/src/mbgl/style/filter_expression.cpp @@ -18,7 +18,7 @@ Value parseFeatureType(const Value& value) { } template <class Expression> -FilterExpression parseBinaryFilter(const rapidjson::Value& value) { +FilterExpression parseBinaryFilter(const JSValue& value) { FilterExpression empty; if (value.Size() < 3) { @@ -43,7 +43,7 @@ FilterExpression parseBinaryFilter(const rapidjson::Value& value) { } template <class Expression> -FilterExpression parseSetFilter(const rapidjson::Value& value) { +FilterExpression parseSetFilter(const JSValue& value) { FilterExpression empty; if (value.Size() < 2) { @@ -69,7 +69,7 @@ FilterExpression parseSetFilter(const rapidjson::Value& value) { } template <class Expression> -FilterExpression parseCompoundFilter(const rapidjson::Value& value) { +FilterExpression parseCompoundFilter(const JSValue& value) { Expression expression; for (rapidjson::SizeType i = 1; i < value.Size(); ++i) { expression.expressions.push_back(parseFilterExpression(value[i])); @@ -77,7 +77,7 @@ FilterExpression parseCompoundFilter(const rapidjson::Value& value) { return expression; } -FilterExpression parseFilterExpression(const rapidjson::Value& value) { +FilterExpression parseFilterExpression(const JSValue& value) { FilterExpression empty; if (!value.IsArray()) { diff --git a/src/mbgl/style/filter_expression.hpp b/src/mbgl/style/filter_expression.hpp index 7fe244632f..cc5bc1a3d5 100644 --- a/src/mbgl/style/filter_expression.hpp +++ b/src/mbgl/style/filter_expression.hpp @@ -2,8 +2,7 @@ #define MBGL_STYLE_FILTER_EXPRESSION #include <mbgl/style/value.hpp> - -#include <rapidjson/document.h> +#include <mbgl/util/rapidjson.hpp> #include <string> #include <vector> @@ -25,7 +24,7 @@ typedef mapbox::util::variant< struct NoneExpression > FilterExpression; -FilterExpression parseFilterExpression(const rapidjson::Value&); +FilterExpression parseFilterExpression(const JSValue&); template <class Extractor> bool evaluate(const FilterExpression&, const Extractor&); diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index 65ce06a153..e27bab3af2 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -3,20 +3,18 @@ #include <mbgl/style/property_parsing.hpp> #include <mbgl/style/function.hpp> -#include <utility> +#include <mbgl/util/rapidjson.hpp> -#include <rapidjson/document.h> +#include <utility> namespace mbgl { -using JSVal = rapidjson::Value; - template <typename T> class LayoutProperty { public: explicit LayoutProperty(T v) : value(std::move(v)) {} - void parse(const char * name, const JSVal& layout) { + void parse(const char * name, const JSValue& layout) { if (layout.HasMember(name)) { parsedValue = parseProperty<Function<T>>(name, layout[name]); } diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 3fb0a194f0..930f12c992 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -9,16 +9,13 @@ #include <mbgl/style/style_calculation_parameters.hpp> #include <mbgl/util/interpolate.hpp> #include <mbgl/util/std.hpp> - -#include <rapidjson/document.h> +#include <mbgl/util/rapidjson.hpp> #include <map> #include <utility> namespace mbgl { -using JSVal = rapidjson::Value; - template <typename T, typename Result = T> class PaintProperty { public: @@ -34,7 +31,7 @@ public: transitions(other.transitions) { } - void parse(const char* name, const JSVal& layer) { + void parse(const char* name, const JSValue& layer) { mbgl::util::erase_if(values, [] (const auto& p) { return p.first != ClassID::Fallback; }); std::string transitionName = { name }; diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp index 63e1fe57e9..2c73d84a93 100644 --- a/src/mbgl/style/property_parsing.cpp +++ b/src/mbgl/style/property_parsing.cpp @@ -11,7 +11,7 @@ namespace mbgl { template <> -optional<bool> parseProperty(const char* name, const JSVal& value) { +optional<bool> parseProperty(const char* name, const JSValue& value) { if (!value.IsBool()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a boolean", name); return {}; @@ -21,7 +21,7 @@ optional<bool> parseProperty(const char* name, const JSVal& value) { } template <> -optional<float> parseProperty(const char* name, const JSVal& value) { +optional<float> parseProperty(const char* name, const JSValue& value) { if (!value.IsNumber()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a number, or a number function", name); return {}; @@ -31,7 +31,7 @@ optional<float> parseProperty(const char* name, const JSVal& value) { } template <> -optional<std::string> parseProperty(const char* name, const JSVal& value) { +optional<std::string> parseProperty(const char* name, const JSValue& value) { if (std::string { "text-font" } == name) { if (!value.IsArray()) { Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name); @@ -40,7 +40,7 @@ optional<std::string> parseProperty(const char* name, const JSVal& value) { std::string result = ""; for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { - const JSVal& stop = value[i]; + const JSValue& stop = value[i]; if (stop.IsString()) { result += stop.GetString(); if (i < value.Size()-1) { @@ -63,7 +63,7 @@ optional<std::string> parseProperty(const char* name, const JSVal& value) { } template <> -optional<Color> parseProperty(const char* name, const JSVal& value) { +optional<Color> parseProperty(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -81,7 +81,7 @@ optional<Color> parseProperty(const char* name, const JSVal& value) { } template <> -optional<TranslateAnchorType> parseProperty(const char* name, const JSVal& value) { +optional<TranslateAnchorType> parseProperty(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -91,7 +91,7 @@ optional<TranslateAnchorType> parseProperty(const char* name, const JSVal& value } template <> -optional<RotateAnchorType> parseProperty<RotateAnchorType>(const char* name, const JSVal& value) { +optional<RotateAnchorType> parseProperty<RotateAnchorType>(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -101,7 +101,7 @@ optional<RotateAnchorType> parseProperty<RotateAnchorType>(const char* name, con } template <> -optional<CapType> parseProperty<CapType>(const char* name, const JSVal& value) { +optional<CapType> parseProperty<CapType>(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -111,7 +111,7 @@ optional<CapType> parseProperty<CapType>(const char* name, const JSVal& value) { } template <> -optional<JoinType> parseProperty<JoinType>(const char* name, const JSVal& value) { +optional<JoinType> parseProperty<JoinType>(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -121,7 +121,7 @@ optional<JoinType> parseProperty<JoinType>(const char* name, const JSVal& value) } template <> -optional<PlacementType> parseProperty<PlacementType>(const char* name, const JSVal& value) { +optional<PlacementType> parseProperty<PlacementType>(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -131,7 +131,7 @@ optional<PlacementType> parseProperty<PlacementType>(const char* name, const JSV } template <> -optional<TextAnchorType> parseProperty<TextAnchorType>(const char* name, const JSVal& value) { +optional<TextAnchorType> parseProperty<TextAnchorType>(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -141,7 +141,7 @@ optional<TextAnchorType> parseProperty<TextAnchorType>(const char* name, const J } template <> -optional<TextJustifyType> parseProperty<TextJustifyType>(const char* name, const JSVal& value) { +optional<TextJustifyType> parseProperty<TextJustifyType>(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -151,7 +151,7 @@ optional<TextJustifyType> parseProperty<TextJustifyType>(const char* name, const } template <> -optional<TextTransformType> parseProperty<TextTransformType>(const char* name, const JSVal& value) { +optional<TextTransformType> parseProperty<TextTransformType>(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -161,7 +161,7 @@ optional<TextTransformType> parseProperty<TextTransformType>(const char* name, c } template <> -optional<RotationAlignmentType> parseProperty<RotationAlignmentType>(const char* name, const JSVal& value) { +optional<RotationAlignmentType> parseProperty<RotationAlignmentType>(const char* name, const JSValue& value) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); return {}; @@ -171,7 +171,7 @@ optional<RotationAlignmentType> parseProperty<RotationAlignmentType>(const char* } template <> -optional<std::array<float, 2>> parseProperty(const char* name, const JSVal& value) { +optional<std::array<float, 2>> parseProperty(const char* name, const JSValue& value) { if (value.IsArray() && value.Size() == 2 && value[rapidjson::SizeType(0)].IsNumber() && value[rapidjson::SizeType(1)].IsNumber()) { @@ -186,7 +186,7 @@ optional<std::array<float, 2>> parseProperty(const char* name, const JSVal& valu } template <> -optional<std::vector<float>> parseProperty(const char* name, const JSVal& value) { +optional<std::vector<float>> parseProperty(const char* name, const JSValue& value) { if (!value.IsArray()) { Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", name); return {}; @@ -195,7 +195,7 @@ optional<std::vector<float>> parseProperty(const char* name, const JSVal& value) std::vector<float> result; for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { - const JSVal& part = value[i]; + const JSValue& part = value[i]; if (!part.IsNumber()) { Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", name); @@ -209,7 +209,7 @@ optional<std::vector<float>> parseProperty(const char* name, const JSVal& value) } template <> -optional<PropertyTransition> parseProperty(const char *, const JSVal& value) { +optional<PropertyTransition> parseProperty(const char *, const JSValue& value) { PropertyTransition transition; if (value.IsObject()) { bool parsed = false; @@ -231,7 +231,7 @@ optional<PropertyTransition> parseProperty(const char *, const JSVal& value) { // --- Function --- template <typename T> -optional<std::vector<std::pair<float, T>>> parseStops(const char* name, const JSVal& value) { +optional<std::vector<std::pair<float, T>>> parseStops(const char* name, const JSValue& value) { if (!value.IsArray()) { Log::Warning(Event::ParseStyle, "stops function must specify a stops array"); return {}; @@ -240,7 +240,7 @@ optional<std::vector<std::pair<float, T>>> parseStops(const char* name, const JS std::vector<std::pair<float, T>> stops; for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { - const JSVal& stop = value[i]; + const JSValue& stop = value[i]; if (!stop.IsArray()) { Log::Warning(Event::ParseStyle, "function argument must be a numeric value"); @@ -252,7 +252,7 @@ optional<std::vector<std::pair<float, T>>> parseStops(const char* name, const JS return {}; } - const JSVal& z = stop[rapidjson::SizeType(0)]; + const JSValue& z = stop[rapidjson::SizeType(0)]; if (!z.IsNumber()) { Log::Warning(Event::ParseStyle, "zoom level in stop must be a number"); return {}; @@ -270,7 +270,7 @@ optional<std::vector<std::pair<float, T>>> parseStops(const char* name, const JS } template <typename T> -optional<Function<T>> parseFunction(const char* name, const JSVal& value) { +optional<Function<T>> parseFunction(const char* name, const JSValue& value) { if (!value.IsObject()) { auto constant = parseProperty<T>(name, value); if (!constant) { @@ -287,7 +287,7 @@ optional<Function<T>> parseFunction(const char* name, const JSVal& value) { float base = 1.0f; if (value.HasMember("base")) { - const JSVal& value_base = value["base"]; + const JSValue& value_base = value["base"]; if (!value_base.IsNumber()) { Log::Warning(Event::ParseStyle, "base must be numeric"); @@ -306,64 +306,64 @@ optional<Function<T>> parseFunction(const char* name, const JSVal& value) { return { Function<T>(*stops, base) }; } -template <> optional<Function<std::array<float, 2>>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<std::array<float, 2>>> parseProperty(const char* name, const JSValue& value) { return parseFunction<std::array<float, 2>>(name, value); } -template <> optional<Function<std::string>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<std::string>> parseProperty(const char* name, const JSValue& value) { return parseFunction<std::string>(name, value); } -template <> optional<Function<TranslateAnchorType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<TranslateAnchorType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<TranslateAnchorType>(name, value); } -template <> optional<Function<RotateAnchorType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<RotateAnchorType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<RotateAnchorType>(name, value); } -template <> optional<Function<CapType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<CapType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<CapType>(name, value); } -template <> optional<Function<JoinType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<JoinType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<JoinType>(name, value); } -template <> optional<Function<PlacementType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<PlacementType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<PlacementType>(name, value); } -template <> optional<Function<TextAnchorType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<TextAnchorType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<TextAnchorType>(name, value); } -template <> optional<Function<TextJustifyType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<TextJustifyType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<TextJustifyType>(name, value); } -template <> optional<Function<TextTransformType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<TextTransformType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<TextTransformType>(name, value); } -template <> optional<Function<RotationAlignmentType>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<RotationAlignmentType>> parseProperty(const char* name, const JSValue& value) { return parseFunction<RotationAlignmentType>(name, value); } -template <> optional<Function<bool>> parseProperty(const char* name, const JSVal& value) { +template <> optional<Function<bool>> parseProperty(const char* name, const JSValue& value) { return parseFunction<bool>(name, value); } -template<> optional<Function<float>> parseProperty(const char* name, const JSVal& value) { +template<> optional<Function<float>> parseProperty(const char* name, const JSValue& value) { return parseFunction<float>(name, value); } -template<> optional<Function<Color>> parseProperty(const char* name, const JSVal& value) { +template<> optional<Function<Color>> parseProperty(const char* name, const JSValue& value) { return parseFunction<Color>(name, value); } template <typename T> -optional<Function<Faded<T>>> parseFadedFunction(const JSVal& value) { +optional<Function<Faded<T>>> parseFadedFunction(const JSValue& value) { if (!value.HasMember("stops")) { Log::Warning(Event::ParseStyle, "function must specify a function type"); return {}; @@ -379,7 +379,7 @@ optional<Function<Faded<T>>> parseFadedFunction(const JSVal& value) { } template <> -optional<Function<Faded<std::vector<float>>>> parseProperty(const char* name, const JSVal& value) { +optional<Function<Faded<std::vector<float>>>> parseProperty(const char* name, const JSValue& value) { if (value.IsObject()) { return parseFadedFunction<std::vector<float>>(value); } @@ -392,7 +392,7 @@ optional<Function<Faded<std::vector<float>>>> parseProperty(const char* name, co } template <> -optional<Function<Faded<std::string>>> parseProperty(const char* name, const JSVal& value) { +optional<Function<Faded<std::string>>> parseProperty(const char* name, const JSValue& value) { if (value.IsObject()) { return parseFadedFunction<std::string>(value); } diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp index d287468e79..8df95e1d66 100644 --- a/src/mbgl/style/property_parsing.hpp +++ b/src/mbgl/style/property_parsing.hpp @@ -3,20 +3,19 @@ #include <mbgl/style/types.hpp> +#include <mbgl/util/rapidjson.hpp> + #include <mapbox/optional.hpp> -#include <rapidjson/document.h> #include <functional> namespace mbgl { -using JSVal = rapidjson::Value; - template <typename T> using optional = mapbox::util::optional<T>; template <typename T> -optional<T> parseProperty(const char* name, const JSVal&); +optional<T> parseProperty(const char* name, const JSValue&); } // namespace mbgl diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 10e5c02d82..a328b890d8 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -42,7 +42,7 @@ Style::Style(MapData& data_) } void Style::setJSON(const std::string& json, const std::string&) { - rapidjson::Document doc; + rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc; doc.Parse<0>((const char *const)json.c_str()); if (doc.HasParseError()) { Log::Error(Event::ParseStyle, "Error parsing style JSON at %i: %s", doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError())); diff --git a/src/mbgl/style/style_layer.hpp b/src/mbgl/style/style_layer.hpp index 4f9649a28b..052b4c3566 100644 --- a/src/mbgl/style/style_layer.hpp +++ b/src/mbgl/style/style_layer.hpp @@ -5,8 +5,7 @@ #include <mbgl/style/filter_expression.hpp> #include <mbgl/renderer/render_pass.hpp> #include <mbgl/util/noncopyable.hpp> - -#include <rapidjson/document.h> +#include <mbgl/util/rapidjson.hpp> #include <memory> #include <string> @@ -19,8 +18,6 @@ class StyleCalculationParameters; class StyleBucketParameters; class Bucket; -using JSVal = rapidjson::Value; - class StyleLayer { public: virtual ~StyleLayer() = default; @@ -35,8 +32,8 @@ public: // Create a copy of this layer. virtual std::unique_ptr<StyleLayer> clone() const = 0; - virtual void parseLayout(const JSVal& value) = 0; - virtual void parsePaints(const JSVal& value) = 0; + virtual void parseLayout(const JSValue& value) = 0; + virtual void parsePaints(const JSValue& value) = 0; // If the layer has a ref, the ref. Otherwise, the id. const std::string& bucketName() const; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 06f81a8ab2..fa0dcc1aaa 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -14,7 +14,7 @@ namespace mbgl { StyleParser::~StyleParser() = default; -void StyleParser::parse(const JSVal& document) { +void StyleParser::parse(const JSValue& document) { if (document.HasMember("version")) { int version = document["version"].GetInt(); if (version != 8) { @@ -31,30 +31,30 @@ void StyleParser::parse(const JSVal& document) { } if (document.HasMember("sprite")) { - const JSVal& sprite = document["sprite"]; + const JSValue& sprite = document["sprite"]; if (sprite.IsString()) { spriteURL = { sprite.GetString(), sprite.GetStringLength() }; } } if (document.HasMember("glyphs")) { - const JSVal& glyphs = document["glyphs"]; + const JSValue& glyphs = document["glyphs"]; if (glyphs.IsString()) { glyphURL = { glyphs.GetString(), glyphs.GetStringLength() }; } } } -void StyleParser::parseSources(const JSVal& value) { +void StyleParser::parseSources(const JSValue& value) { if (!value.IsObject()) { Log::Warning(Event::ParseStyle, "sources must be an object"); return; } - rapidjson::Value::ConstMemberIterator itr = value.MemberBegin(); + JSValue::ConstMemberIterator itr = value.MemberBegin(); for (; itr != value.MemberEnd(); ++itr) { - const JSVal& nameVal = itr->name; - const JSVal& sourceVal = itr->value; + const JSValue& nameVal = itr->name; + const JSValue& sourceVal = itr->value; std::unique_ptr<Source> source = std::make_unique<Source>(); @@ -65,7 +65,7 @@ void StyleParser::parseSources(const JSVal& value) { continue; } - const JSVal& typeVal = sourceVal["type"]; + const JSValue& typeVal = sourceVal["type"]; if (!typeVal.IsString()) { Log::Warning(Event::ParseStyle, "source type must have one of the enum values"); continue; @@ -98,10 +98,10 @@ void StyleParser::parseSources(const JSVal& value) { } } -bool StyleParser::parseVectorSource(Source& source, const JSVal& sourceVal) { +bool StyleParser::parseVectorSource(Source& source, const JSValue& sourceVal) { // A vector tile source either specifies the URL of a TileJSON file... if (sourceVal.HasMember("url")) { - const JSVal& urlVal = sourceVal["url"]; + const JSValue& urlVal = sourceVal["url"]; if (!urlVal.IsString()) { Log::Warning(Event::ParseStyle, "source url must be a string"); @@ -118,9 +118,9 @@ bool StyleParser::parseVectorSource(Source& source, const JSVal& sourceVal) { return true; } -bool StyleParser::parseRasterSource(Source& source, const JSVal& sourceVal) { +bool StyleParser::parseRasterSource(Source& source, const JSValue& sourceVal) { if (sourceVal.HasMember("tileSize")) { - const JSVal& tileSizeVal = sourceVal["tileSize"]; + const JSValue& tileSizeVal = sourceVal["tileSize"]; if (!tileSizeVal.IsUint()) { Log::Warning(Event::ParseStyle, "source tileSize must be an unsigned integer"); @@ -138,7 +138,7 @@ bool StyleParser::parseRasterSource(Source& source, const JSVal& sourceVal) { // A raster tile source either specifies the URL of a TileJSON file... if (sourceVal.HasMember("url")) { - const JSVal& urlVal = sourceVal["url"]; + const JSValue& urlVal = sourceVal["url"]; if (!urlVal.IsString()) { Log::Warning(Event::ParseStyle, "source url must be a string"); @@ -155,13 +155,13 @@ bool StyleParser::parseRasterSource(Source& source, const JSVal& sourceVal) { return true; } -bool StyleParser::parseGeoJSONSource(Source& source, const JSVal& sourceVal) { +bool StyleParser::parseGeoJSONSource(Source& source, const JSValue& sourceVal) { if (!sourceVal.HasMember("data")) { Log::Warning(Event::ParseStyle, "GeoJSON source must have a data value"); return false; } - const JSVal& dataVal = sourceVal["data"]; + const JSValue& dataVal = sourceVal["data"]; if (dataVal.IsString()) { // We need to load an external GeoJSON file source.info.url = { dataVal.GetString(), dataVal.GetStringLength() }; @@ -176,7 +176,7 @@ bool StyleParser::parseGeoJSONSource(Source& source, const JSVal& sourceVal) { return true; } -void StyleParser::parseLayers(const JSVal& value) { +void StyleParser::parseLayers(const JSValue& value) { std::vector<std::string> ids; if (!value.IsArray()) { @@ -185,7 +185,7 @@ void StyleParser::parseLayers(const JSVal& value) { } for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { - const JSVal& layerValue = value[i]; + const JSValue& layerValue = value[i]; if (!layerValue.IsObject()) { Log::Warning(Event::ParseStyle, "layer must be an object"); @@ -197,7 +197,7 @@ void StyleParser::parseLayers(const JSVal& value) { continue; } - const JSVal& id = layerValue["id"]; + const JSValue& id = layerValue["id"]; if (!id.IsString()) { Log::Warning(Event::ParseStyle, "layer id must be a string"); continue; @@ -209,7 +209,7 @@ void StyleParser::parseLayers(const JSVal& value) { continue; } - layersMap.emplace(layerID, std::pair<const JSVal&, std::unique_ptr<StyleLayer>> { layerValue, nullptr }); + layersMap.emplace(layerID, std::pair<const JSValue&, std::unique_ptr<StyleLayer>> { layerValue, nullptr }); ids.push_back(layerID); } @@ -230,7 +230,7 @@ void StyleParser::parseLayers(const JSVal& value) { } } -void StyleParser::parseLayer(const std::string& id, const JSVal& value, std::unique_ptr<StyleLayer>& layer) { +void StyleParser::parseLayer(const std::string& id, const JSValue& value, std::unique_ptr<StyleLayer>& layer) { if (layer) { // Skip parsing this again. We already have a valid layer definition. return; @@ -244,7 +244,7 @@ void StyleParser::parseLayer(const std::string& id, const JSVal& value, std::uni if (value.HasMember("ref")) { // This layer is referencing another layer. Recursively parse that layer. - const JSVal& refVal = value["ref"]; + const JSValue& refVal = value["ref"]; if (!refVal.IsString()) { Log::Warning(Event::ParseStyle, "layer ref of '%s' must be a string", id.c_str()); return; @@ -280,7 +280,7 @@ void StyleParser::parseLayer(const std::string& id, const JSVal& value, std::uni return; } - const JSVal& typeVal = value["type"]; + const JSValue& typeVal = value["type"]; if (!typeVal.IsString()) { Log::Warning(Event::ParseStyle, "layer '%s' has an invalid type", id.c_str()); return; @@ -308,7 +308,7 @@ void StyleParser::parseLayer(const std::string& id, const JSVal& value, std::uni layer->id = id; if (value.HasMember("source")) { - const JSVal& value_source = value["source"]; + const JSValue& value_source = value["source"]; if (value_source.IsString()) { layer->source = { value_source.GetString(), value_source.GetStringLength() }; auto source_it = sourcesMap.find(layer->source); @@ -321,7 +321,7 @@ void StyleParser::parseLayer(const std::string& id, const JSVal& value, std::uni } if (value.HasMember("source-layer")) { - const JSVal& value_source_layer = value["source-layer"]; + const JSValue& value_source_layer = value["source-layer"]; if (value_source_layer.IsString()) { layer->sourceLayer = { value_source_layer.GetString(), value_source_layer.GetStringLength() }; } else { @@ -334,7 +334,7 @@ void StyleParser::parseLayer(const std::string& id, const JSVal& value, std::uni } if (value.HasMember("minzoom")) { - const JSVal& min_zoom = value["minzoom"]; + const JSValue& min_zoom = value["minzoom"]; if (min_zoom.IsNumber()) { layer->minZoom = min_zoom.GetDouble(); } else { @@ -343,7 +343,7 @@ void StyleParser::parseLayer(const std::string& id, const JSVal& value, std::uni } if (value.HasMember("maxzoom")) { - const JSVal& max_zoom = value["maxzoom"]; + const JSValue& max_zoom = value["maxzoom"]; if (max_zoom.IsNumber()) { layer->maxZoom = max_zoom.GetDouble(); } else { @@ -360,7 +360,7 @@ void StyleParser::parseLayer(const std::string& id, const JSVal& value, std::uni layer->parsePaints(value); } -void StyleParser::parseVisibility(StyleLayer& layer, const JSVal& value) { +void StyleParser::parseVisibility(StyleLayer& layer, const JSValue& value) { if (!value.HasMember("visibility")) { return; } else if (!value["visibility"].IsString()) { diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 898f39bd01..6242945c46 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -3,8 +3,7 @@ #include <mbgl/style/style_layer.hpp> #include <mbgl/map/source.hpp> - -#include <rapidjson/document.h> +#include <mbgl/util/rapidjson.hpp> #include <vector> #include <memory> @@ -17,13 +16,11 @@ namespace mbgl { class StyleLayer; class Source; -using JSVal = rapidjson::Value; - class StyleParser { public: ~StyleParser(); - void parse(const JSVal&); + void parse(const JSValue&); std::string spriteURL; std::string glyphURL; @@ -32,16 +29,16 @@ public: std::vector<std::unique_ptr<StyleLayer>> layers; private: - void parseSources(const JSVal&); - bool parseVectorSource(Source&, const JSVal&); - bool parseRasterSource(Source&, const JSVal&); - bool parseGeoJSONSource(Source&, const JSVal&); - void parseLayers(const JSVal&); - void parseLayer(const std::string& id, const JSVal&, std::unique_ptr<StyleLayer>&); - void parseVisibility(StyleLayer&, const JSVal& value); + void parseSources(const JSValue&); + bool parseVectorSource(Source&, const JSValue&); + bool parseRasterSource(Source&, const JSValue&); + bool parseGeoJSONSource(Source&, const JSValue&); + void parseLayers(const JSValue&); + void parseLayer(const std::string& id, const JSValue&, std::unique_ptr<StyleLayer>&); + void parseVisibility(StyleLayer&, const JSValue& value); std::unordered_map<std::string, const Source*> sourcesMap; - std::unordered_map<std::string, std::pair<const JSVal&, std::unique_ptr<StyleLayer>>> layersMap; + std::unordered_map<std::string, std::pair<const JSValue&, std::unique_ptr<StyleLayer>>> layersMap; // Store a stack of layer IDs we're parsing right now. This is to prevent reference cycles. std::forward_list<std::string> stack; diff --git a/src/mbgl/style/value.cpp b/src/mbgl/style/value.cpp index 41730470ed..a0fa99edf3 100644 --- a/src/mbgl/style/value.cpp +++ b/src/mbgl/style/value.cpp @@ -10,7 +10,7 @@ std::string mbgl::toString(const mbgl::Value& value) { else return "null"; } -mbgl::Value mbgl::parseValue(const rapidjson::Value& value) { +mbgl::Value mbgl::parseValue(const JSValue& value) { switch (value.GetType()) { case rapidjson::kNullType: case rapidjson::kFalseType: diff --git a/src/mbgl/style/value.hpp b/src/mbgl/style/value.hpp index 0f3127e4f9..fd85ee36c4 100644 --- a/src/mbgl/style/value.hpp +++ b/src/mbgl/style/value.hpp @@ -2,7 +2,7 @@ #define MBGL_STYLE_VALUE #include <mapbox/variant.hpp> -#include <rapidjson/document.h> +#include <mbgl/util/rapidjson.hpp> #include <cstdlib> #include <cerrno> @@ -13,7 +13,7 @@ typedef mapbox::util::variant<bool, int64_t, uint64_t, double, std::string> Valu std::string toString(const Value &value); -Value parseValue(const rapidjson::Value&); +Value parseValue(const JSValue&); namespace util { inline bool parseNumericString(const std::string &str, double &result) { diff --git a/src/mbgl/util/rapidjson.hpp b/src/mbgl/util/rapidjson.hpp new file mode 100644 index 0000000000..c9aad871d9 --- /dev/null +++ b/src/mbgl/util/rapidjson.hpp @@ -0,0 +1,14 @@ +#ifndef MBGL_UTIL_RAPIDJSON +#define MBGL_UTIL_RAPIDJSON + +#include <rapidjson/document.h> +#include <rapidjson/error/en.h> + +namespace mbgl { + +using JSDocument = rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator>; +using JSValue = rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator>; + +} // namespace mbgl + +#endif diff --git a/test/miscellaneous/comparisons.cpp b/test/miscellaneous/comparisons.cpp index afb3990f80..2d5b8c5424 100644 --- a/test/miscellaneous/comparisons.cpp +++ b/test/miscellaneous/comparisons.cpp @@ -37,7 +37,7 @@ private: }; FilterExpression parse(const char * expression) { - rapidjson::Document doc; + rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc; doc.Parse<0>(expression); return parseFilterExpression(doc); } diff --git a/test/miscellaneous/style_parser.cpp b/test/miscellaneous/style_parser.cpp index ed9a0462b5..ab5e984752 100644 --- a/test/miscellaneous/style_parser.cpp +++ b/test/miscellaneous/style_parser.cpp @@ -22,12 +22,12 @@ class StyleParserTest : public ::testing::TestWithParam<std::string> {}; TEST_P(StyleParserTest, ParseStyle) { const std::string base = std::string("test/fixtures/style_parser/") + GetParam(); - rapidjson::Document infoDoc; + rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> infoDoc; infoDoc.Parse<0>(util::read_file(base + ".info.json").c_str()); ASSERT_FALSE(infoDoc.HasParseError()); ASSERT_TRUE(infoDoc.IsObject()); - rapidjson::Document styleDoc; + rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> styleDoc; styleDoc.Parse<0>(util::read_file(base + ".style.json").c_str()); ASSERT_FALSE(styleDoc.HasParseError()); ASSERT_TRUE(styleDoc.IsObject()); @@ -40,14 +40,14 @@ TEST_P(StyleParserTest, ParseStyle) { for (auto it = infoDoc.MemberBegin(), end = infoDoc.MemberEnd(); it != end; it++) { const std::string name { it->name.GetString(), it->name.GetStringLength() }; - const rapidjson::Value &value = it->value; + const JSValue &value = it->value; ASSERT_EQ(true, value.IsObject()); if (value.HasMember("log")) { - const rapidjson::Value &js_log = value["log"]; + const JSValue &js_log = value["log"]; ASSERT_EQ(true, js_log.IsArray()); for (rapidjson::SizeType i = 0; i < js_log.Size(); i++) { - const rapidjson::Value &js_entry = js_log[i]; + const JSValue &js_entry = js_log[i]; ASSERT_EQ(true, js_entry.IsArray()); const uint32_t count = js_entry[rapidjson::SizeType(0)].GetUint(); |