diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp index d976e995db8..6f5bc5ed691 100644 --- a/include/mbgl/style/conversion.hpp +++ b/include/mbgl/style/conversion.hpp @@ -22,13 +22,13 @@ namespace conversion { A single template function serves as the public interface: template - optional convert(const Value& value, Error& error); + optional convert(const Convertible& input, Error& error); Where `T` is one of the above types. If the conversion fails, the result is empty, and the error parameter includes diagnostic text suitable for presentation to a library user. Otherwise, a filled optional is returned. - `Value` is a type that encapsulates a special form of polymorphism over various underlying types that + `Convertible` is a type that encapsulates a special form of polymorphism over various underlying types that can serve as input to the conversion algorithm. For instance, on macOS, we need to support conversion from both RapidJSON types, and a JSON structure represented with `NSArray`/`NSDictionary`/etc. On Qt, we need to support conversion from RapidJSON types and QVariant. @@ -40,11 +40,11 @@ namespace conversion { * Runtime polymorphism using virtual methods requires extra heap allocation and ubiquitous use of std::unique_ptr, unsuitable for this performance-sensitive code. - Therefore, we're using a custom implementation where we manually create and dispatch through a table - of function pointers (vtable), while keeping the storage for any of the possible underlying types inline - on the stack. + Therefore, we're using a custom implementation of runtime polymorphism where we manually create and + dispatch through a table of function pointers (vtable), while keeping the storage for any of the possible + underlying types inline on the stack, using `std::aligned_storage`. - For a given underlying type T, an explicit specialization of ValueTraits must be provided. This + For a given underlying type T, an explicit specialization of `ConversionTraits` must be provided. This specialization must provide the following static methods: * `isUndefined(v)` -- returns a boolean indication whether `v` is undefined or a JSON null @@ -65,32 +65,32 @@ namespace conversion { * `toNumber(v)` -- returns `optional`, absence indicating `v` is not a JSON number * `toDouble(v)` -- returns `optional`, absence indicating `v` is not a JSON number * `toString(v)` -- returns `optional`, absence indicating `v` is not a JSON string - * `toValue(v)` -- returns `optional`, a variant type, for generic conversion, + * `toValue(v)` -- returns `optional`, a variant type, for generic conversion, absence indicating `v` is not a boolean, number, or string. Numbers should be converted to unsigned integer, signed integer, or floating point, in descending preference. - In addition, the type T must be move-constructable. And finally, `Value::Storage`, a typedef for + In addition, the type T must be move-constructable. And finally, `Convertible::Storage`, a typedef for `std::aligned_storage_t`, must be large enough to satisfy the memory requirements for any of the possible underlying types. (A static assert will fail if this is not the case.) - `Value` itself is movable, but not copyable. A moved-from `Value` is in an invalid state; you must - not do anything with it except let it go out of scope. + `Convertible` itself is movable, but not copyable. A moved-from `Convertible` is in an invalid state; + you must not do anything with it except let it go out of scope. */ struct Error { std::string message; }; template -class ValueTraits; +class ConversionTraits; -class Value { +class Convertible { public: template - Value(const T value) : vtable(vtableForType()) { + Convertible(const T value) : vtable(vtableForType()) { static_assert(sizeof(Storage) >= sizeof(T), "Storage must be large enough to hold value type"); new (static_cast(&storage)) T(value); } - Value(Value&& v) + Convertible(Convertible&& v) : vtable(v.vtable) { if (vtable) { @@ -98,13 +98,13 @@ class Value { } } - ~Value() { + ~Convertible() { if (vtable) { vtable->destroy(storage); } } - Value& operator=(Value&& v) { + Convertible& operator=(Convertible&& v) { if (vtable) { vtable->destroy(storage); } @@ -116,71 +116,71 @@ class Value { return *this; } - Value() = delete; - Value(const Value&) = delete; - Value& operator=(const Value&) = delete; + Convertible() = delete; + Convertible(const Convertible&) = delete; + Convertible& operator=(const Convertible&) = delete; - friend inline bool isUndefined(const Value& v) { + friend inline bool isUndefined(const Convertible& v) { assert(v.vtable); return v.vtable->isUndefined(v.storage); } - friend inline bool isArray(const Value& v) { + friend inline bool isArray(const Convertible& v) { assert(v.vtable); return v.vtable->isArray(v.storage); } - friend inline std::size_t arrayLength(const Value& v) { + friend inline std::size_t arrayLength(const Convertible& v) { assert(v.vtable); return v.vtable->arrayLength(v.storage); } - friend inline Value arrayMember(const Value& v, std::size_t i) { + friend inline Convertible arrayMember(const Convertible& v, std::size_t i) { assert(v.vtable); return v.vtable->arrayMember(v.storage, i); } - friend inline bool isObject(const Value& v) { + friend inline bool isObject(const Convertible& v) { assert(v.vtable); return v.vtable->isObject(v.storage); } - friend inline optional objectMember(const Value& v, const char * name) { + friend inline optional objectMember(const Convertible& v, const char * name) { assert(v.vtable); return v.vtable->objectMember(v.storage, name); } - friend inline optional eachMember(const Value& v, const std::function (const std::string&, const Value&)>& fn) { + friend inline optional eachMember(const Convertible& v, const std::function (const std::string&, const Convertible&)>& fn) { assert(v.vtable); return v.vtable->eachMember(v.storage, fn); } - friend inline optional toBool(const Value& v) { + friend inline optional toBool(const Convertible& v) { assert(v.vtable); return v.vtable->toBool(v.storage); } - friend inline optional toNumber(const Value& v) { + friend inline optional toNumber(const Convertible& v) { assert(v.vtable); return v.vtable->toNumber(v.storage); } - friend inline optional toDouble(const Value& v) { + friend inline optional toDouble(const Convertible& v) { assert(v.vtable); return v.vtable->toDouble(v.storage); } - friend inline optional toString(const Value& v) { + friend inline optional toString(const Convertible& v) { assert(v.vtable); return v.vtable->toString(v.storage); } - friend inline optional toValue(const Value& v) { + friend inline optional toValue(const Convertible& v) { assert(v.vtable); return v.vtable->toValue(v.storage); } - friend inline optional toGeoJSON(const Value& v, Error& error) { + friend inline optional toGeoJSON(const Convertible& v, Error& error) { assert(v.vtable); return v.vtable->toGeoJSON(v.storage, error); } @@ -202,17 +202,17 @@ class Value { bool (*isArray) (const Storage&); std::size_t (*arrayLength) (const Storage&); - Value (*arrayMember) (const Storage&, std::size_t); + Convertible (*arrayMember) (const Storage&, std::size_t); - bool (*isObject) (const Storage&); - optional (*objectMember) (const Storage&, const char *); - optional (*eachMember) (const Storage&, const std::function (const std::string&, const Value&)>&); + bool (*isObject) (const Storage&); + optional (*objectMember) (const Storage&, const char *); + optional (*eachMember) (const Storage&, const std::function (const std::string&, const Convertible&)>&); optional (*toBool) (const Storage&); optional (*toNumber) (const Storage&); optional (*toDouble) (const Storage&); optional (*toString) (const Storage&); - optional (*toValue) (const Storage&); + optional (*toValue) (const Storage&); // https://github.com/mapbox/mapbox-gl-native/issues/5623 optional (*toGeoJSON) (const Storage&, Error&); @@ -220,9 +220,8 @@ class Value { template static VTable* vtableForType() { - using Traits = ValueTraits; - - static Value::VTable vtable = { + using Traits = ConversionTraits; + static VTable vtable = { [] (Storage&& src, Storage& dest) { auto srcValue = reinterpret_cast(src); new (static_cast(&dest)) T(std::move(srcValue)); @@ -241,19 +240,19 @@ class Value { return Traits::arrayLength(reinterpret_cast(s)); }, [] (const Storage& s, std::size_t i) { - return Value(Traits::arrayMember(reinterpret_cast(s), i)); + return Convertible(Traits::arrayMember(reinterpret_cast(s), i)); }, [] (const Storage& s) { return Traits::isObject(reinterpret_cast(s)); }, [] (const Storage& s, const char * key) { optional member = Traits::objectMember(reinterpret_cast(s), key); - if (member) return optional(*member); - return optional(); + if (member) return optional(*member); + return optional(); }, - [] (const Storage& s, const std::function (const std::string&, const Value&)>& fn) { + [] (const Storage& s, const std::function (const std::string&, const Convertible&)>& fn) { return Traits::eachMember(reinterpret_cast(s), [&](const std::string& k, const T& v) { - return fn(k, Value(v)); + return fn(k, Convertible(v)); }); }, [] (const Storage& s) { @@ -286,7 +285,7 @@ template struct Converter; template -optional convert(const Value& value, Error& error, Args&&...args) { +optional convert(const Convertible& value, Error& error, Args&&...args) { return Converter()(value, error, std::forward(args)...); } diff --git a/include/mbgl/style/conversion/constant.hpp b/include/mbgl/style/conversion/constant.hpp index 50d31ab9a82..7b3249da52b 100644 --- a/include/mbgl/style/conversion/constant.hpp +++ b/include/mbgl/style/conversion/constant.hpp @@ -15,22 +15,22 @@ namespace conversion { template <> struct Converter { - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; template <> struct Converter { - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; template <> struct Converter { - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; template struct Converter::value>> { - optional operator()(const Value& value, Error& error) const { + optional operator()(const Convertible& value, Error& error) const { optional string = toString(value); if (!string) { error = { "value must be a string" }; @@ -49,12 +49,12 @@ struct Converter::value>> { template <> struct Converter { - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; template struct Converter> { - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { if (!isArray(value) || arrayLength(value) != N) { error = { "value must be an array of " + util::toString(N) + " numbers" }; return {}; @@ -75,12 +75,12 @@ struct Converter> { template <> struct Converter> { - optional> operator()(const Value& value, Error& error) const; + optional> operator()(const Convertible& value, Error& error) const; }; template <> struct Converter> { - optional> operator()(const Value& value, Error& error) const; + optional> operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/coordinate.hpp b/include/mbgl/style/conversion/coordinate.hpp index 8aa39283a80..e11db5e32f3 100644 --- a/include/mbgl/style/conversion/coordinate.hpp +++ b/include/mbgl/style/conversion/coordinate.hpp @@ -10,7 +10,7 @@ namespace conversion { template<> struct Converter { public: - optional operator() (const Value& value, Error& error) const; + optional operator() (const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp index b7e3bef1725..1e54c15a493 100644 --- a/include/mbgl/style/conversion/data_driven_property_value.hpp +++ b/include/mbgl/style/conversion/data_driven_property_value.hpp @@ -11,7 +11,7 @@ namespace conversion { template struct Converter> { - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { if (isUndefined(value)) { return DataDrivenPropertyValue(); } else if (!isObject(value)) { diff --git a/include/mbgl/style/conversion/filter.hpp b/include/mbgl/style/conversion/filter.hpp index d948ad01652..9daf6ea7a4e 100644 --- a/include/mbgl/style/conversion/filter.hpp +++ b/include/mbgl/style/conversion/filter.hpp @@ -10,7 +10,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index 49dfacfef2e..e2308849442 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -12,7 +12,7 @@ namespace style { namespace conversion { template -optional> convertStops(const Value& value, Error& error) { +optional> convertStops(const Convertible& value, Error& error) { auto stopsValue = objectMember(value, "stops"); if (!stopsValue) { error = { "function value must specify stops" }; @@ -63,7 +63,7 @@ template struct Converter> { static constexpr const char * type = "exponential"; - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { auto stops = convertStops(value, error); if (!stops) { return {}; @@ -88,7 +88,7 @@ template struct Converter> { static constexpr const char * type = "interval"; - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { auto stops = convertStops(value, error); if (!stops) { return {}; @@ -99,7 +99,7 @@ struct Converter> { template <> struct Converter { - optional operator()(const Value& value, Error& error) const { + optional operator()(const Convertible& value, Error& error) const { auto b = toBool(value); if (b) { return { *b }; @@ -124,7 +124,7 @@ template struct Converter> { static constexpr const char * type = "categorical"; - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { auto stops = convertStops(value, error); if (!stops) { return {}; @@ -138,7 +138,7 @@ template struct Converter> { static constexpr const char * type = "identity"; - optional> operator()(const Value&, Error&) const { + optional> operator()(const Convertible&, Error&) const { return IdentityStops(); } }; @@ -149,7 +149,7 @@ struct StopsConverter; template struct StopsConverter> { public: - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { std::string type = util::Interpolatable::value ? "exponential" : "interval"; auto typeValue = objectMember(value, "type"); @@ -187,7 +187,7 @@ struct StopsConverter> { template struct Converter> { - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error = { "function must be an object" }; return {}; @@ -203,7 +203,7 @@ struct Converter> { }; template -optional> convertDefaultValue(const Value& value, Error& error) { +optional> convertDefaultValue(const Convertible& value, Error& error) { auto defaultValueValue = objectMember(value, "default"); if (!defaultValueValue) { return optional(); @@ -220,7 +220,7 @@ optional> convertDefaultValue(const Value& value, Error& error) { template struct Converter> { - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error = { "function must be an object" }; return {}; @@ -259,7 +259,7 @@ struct CompositeValue : std::pair { template struct Converter> { - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error = { "stop must be an object" }; return {}; @@ -295,7 +295,7 @@ template struct Converter> { static constexpr const char * type = "exponential"; - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { auto stops = convertStops, T>(value, error); if (!stops) { return {}; @@ -320,7 +320,7 @@ template struct Converter> { static constexpr const char * type = "interval"; - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { auto stops = convertStops, T>(value, error); if (!stops) { return {}; @@ -339,7 +339,7 @@ template struct Converter> { static constexpr const char * type = "categorical"; - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { auto stops = convertStops, T>(value, error); if (!stops) { return {}; @@ -356,7 +356,7 @@ struct Converter> { template struct Converter> { - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error = { "function must be an object" }; return {}; diff --git a/include/mbgl/style/conversion/geojson.hpp b/include/mbgl/style/conversion/geojson.hpp index ed1e0d5fb0c..403c5f953b2 100644 --- a/include/mbgl/style/conversion/geojson.hpp +++ b/include/mbgl/style/conversion/geojson.hpp @@ -13,7 +13,7 @@ optional parseGeoJSON(const std::string&, Error&); template <> struct Converter { public: - optional operator()(const Value&, Error&) const; + optional operator()(const Convertible&, Error&) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/geojson_options.hpp b/include/mbgl/style/conversion/geojson_options.hpp index e9a147a5cb9..3f625babb6f 100644 --- a/include/mbgl/style/conversion/geojson_options.hpp +++ b/include/mbgl/style/conversion/geojson_options.hpp @@ -9,7 +9,7 @@ namespace conversion { template <> struct Converter { - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/layer.hpp b/include/mbgl/style/conversion/layer.hpp index 32454bdde4e..1c0e2e2f07d 100644 --- a/include/mbgl/style/conversion/layer.hpp +++ b/include/mbgl/style/conversion/layer.hpp @@ -12,12 +12,12 @@ namespace conversion { template <> struct Converter> { public: - optional> operator()(const Value& value, Error& error) const; + optional> operator()(const Convertible& value, Error& error) const; }; -optional setLayoutProperty(Layer& layer, const std::string& name, const Value& value); -optional setPaintProperty(Layer& layer, const std::string& name, const Value& value); -optional setPaintProperties(Layer& layer, const Value& value); +optional setLayoutProperty(Layer& layer, const std::string& name, const Convertible& value); +optional setPaintProperty(Layer& layer, const std::string& name, const Convertible& value); +optional setPaintProperties(Layer& layer, const Convertible& value); } // namespace conversion } // namespace style diff --git a/include/mbgl/style/conversion/light.hpp b/include/mbgl/style/conversion/light.hpp index 38b6991b564..289fca2e312 100644 --- a/include/mbgl/style/conversion/light.hpp +++ b/include/mbgl/style/conversion/light.hpp @@ -10,7 +10,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/position.hpp b/include/mbgl/style/conversion/position.hpp index 167cd313786..044c45862d0 100644 --- a/include/mbgl/style/conversion/position.hpp +++ b/include/mbgl/style/conversion/position.hpp @@ -9,7 +9,7 @@ namespace conversion { template <> struct Converter { - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp index 3780381b232..c7f971ec91f 100644 --- a/include/mbgl/style/conversion/property_value.hpp +++ b/include/mbgl/style/conversion/property_value.hpp @@ -11,7 +11,7 @@ namespace conversion { template struct Converter> { - optional> operator()(const Value& value, Error& error) const { + optional> operator()(const Convertible& value, Error& error) const { if (isUndefined(value)) { return PropertyValue(); } else if (isObject(value)) { diff --git a/include/mbgl/style/conversion/source.hpp b/include/mbgl/style/conversion/source.hpp index 0b9a273eb5b..2cf2e36da4e 100644 --- a/include/mbgl/style/conversion/source.hpp +++ b/include/mbgl/style/conversion/source.hpp @@ -12,7 +12,7 @@ namespace conversion { template <> struct Converter> { public: - optional> operator()(const Value& value, Error& error, const std::string& id) const; + optional> operator()(const Convertible& value, Error& error, const std::string& id) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/tileset.hpp b/include/mbgl/style/conversion/tileset.hpp index 25f4f27d819..1fb4acf70d7 100644 --- a/include/mbgl/style/conversion/tileset.hpp +++ b/include/mbgl/style/conversion/tileset.hpp @@ -10,7 +10,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/transition_options.hpp b/include/mbgl/style/conversion/transition_options.hpp index 173d4a84487..0563f39ac3c 100644 --- a/include/mbgl/style/conversion/transition_options.hpp +++ b/include/mbgl/style/conversion/transition_options.hpp @@ -10,7 +10,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Value& value, Error& error) const; + optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/platform/android/src/style/android_conversion.hpp b/platform/android/src/style/android_conversion.hpp index bc067fbc534..9b0ddbb50a3 100644 --- a/platform/android/src/style/android_conversion.hpp +++ b/platform/android/src/style/android_conversion.hpp @@ -15,7 +15,7 @@ namespace style { namespace conversion { template <> -class ValueTraits { +class ConversionTraits { public: static bool isUndefined(const mbgl::android::Value& value) { return value.isNull(); @@ -85,7 +85,7 @@ class ValueTraits { } } - static optional toValue(const mbgl::android::Value& value) { + static optional toValue(const mbgl::android::Value& value) { if (value.isNull()) { return {}; } else if (value.isBool()) { @@ -111,7 +111,7 @@ class ValueTraits { template optional convert(const mbgl::android::Value& value, Error& error, Args&&...args) { - return convert(Value(value), error, std::forward(args)...); + return convert(Convertible(value), error, std::forward(args)...); } } // namespace conversion diff --git a/platform/android/src/style/conversion/url_or_tileset.hpp b/platform/android/src/style/conversion/url_or_tileset.hpp index dae1209697d..f2ebce7bd1c 100644 --- a/platform/android/src/style/conversion/url_or_tileset.hpp +++ b/platform/android/src/style/conversion/url_or_tileset.hpp @@ -20,16 +20,16 @@ namespace android { inline variant convertURLOrTileset(const mbgl::android::Value& value) { using namespace mbgl::style::conversion; - const mbgl::style::conversion::Value converted(value); - if (isObject(converted)) { + const Convertible convertible(value); + if (isObject(convertible)) { Error error; - optional tileset = convert(converted, error); + optional tileset = convert(convertible, error); if (!tileset) { throw std::logic_error(error.message); } return { *tileset }; } else { - return { *toString(converted) }; + return { *toString(convertible) }; } } diff --git a/platform/darwin/src/MGLConversion.h b/platform/darwin/src/MGLConversion.h index 584438e04c7..1edb387a991 100644 --- a/platform/darwin/src/MGLConversion.h +++ b/platform/darwin/src/MGLConversion.h @@ -14,7 +14,7 @@ class Holder { }; template <> -class ValueTraits { +class ConversionTraits { public: static bool isUndefined(const Holder& holder) { const id value = holder.value; @@ -140,8 +140,8 @@ class ValueTraits { } }; -inline Value makeValue(const id value) { - return {Holder(value)}; +inline Convertible makeConvertible(const id value) { + return Convertible(Holder(value)); } } // namespace conversion diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index a6da6017d42..5914e0a2aaf 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -126,7 +126,7 @@ class MGLStyleValueTransformer { } else if ([value isKindOfClass:[MGLStyleFunction class]]) { mbgl::style::conversion::Error error; auto result = mbgl::style::conversion::convert>( - mbgl::style::conversion::makeValue(toRawStyleSpecValue((MGLStyleFunction *) value)), error); + mbgl::style::conversion::makeConvertible(toRawStyleSpecValue((MGLStyleFunction *) value)), error); NSCAssert(result, @(error.message.c_str())); return *result; } else { diff --git a/platform/node/src/node_conversion.hpp b/platform/node/src/node_conversion.hpp index 7db5b236429..04494eb142d 100644 --- a/platform/node/src/node_conversion.hpp +++ b/platform/node/src/node_conversion.hpp @@ -16,7 +16,7 @@ namespace style { namespace conversion { template <> -class ValueTraits> { +class ConversionTraits> { public: static bool isUndefined(const v8::Local& value) { Nan::HandleScope scope; @@ -105,7 +105,7 @@ class ValueTraits> { return std::string(*Nan::Utf8String(value)); } - static optional toValue(const v8::Local& value) { + static optional toValue(const v8::Local& value) { if (value->IsFalse()) { return { false }; } else if (value->IsTrue()) { @@ -137,7 +137,7 @@ class ValueTraits> { template optional convert(const v8::Local& value, Error& error, Args&&...args) { - return convert(Value(value), error, std::forward(args)...); + return convert(Convertible(value), error, std::forward(args)...); } } // namespace conversion diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index bd5ba7b1526..ade409048e5 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -748,7 +748,7 @@ void NodeMap::SetLayoutProperty(const Nan::FunctionCallbackInfo& info return Nan::ThrowTypeError("Second argument must be a string"); } - mbgl::optional error = setLayoutProperty(*layer, *Nan::Utf8String(info[1]), Value(info[2])); + mbgl::optional error = setLayoutProperty(*layer, *Nan::Utf8String(info[1]), Convertible(info[2])); if (error) { return Nan::ThrowTypeError(error->message.c_str()); } @@ -780,7 +780,7 @@ void NodeMap::SetPaintProperty(const Nan::FunctionCallbackInfo& info) return Nan::ThrowTypeError("Second argument must be a string"); } - mbgl::optional error = setPaintProperty(*layer, *Nan::Utf8String(info[1]), Value(info[2])); + mbgl::optional error = setPaintProperty(*layer, *Nan::Utf8String(info[1]), Convertible(info[2])); if (error) { return Nan::ThrowTypeError(error->message.c_str()); } diff --git a/platform/qt/src/qt_conversion.hpp b/platform/qt/src/qt_conversion.hpp index 3f58147ca24..91d5d48c126 100644 --- a/platform/qt/src/qt_conversion.hpp +++ b/platform/qt/src/qt_conversion.hpp @@ -14,7 +14,7 @@ namespace style { namespace conversion { template <> -class ValueTraits { +class ConversionTraits { public: static bool isUndefined(const QVariant& value) { return value.isNull() || !value.isValid(); @@ -105,7 +105,7 @@ class ValueTraits { } } - static optional toValue(const QVariant& value) { + static optional toValue(const QVariant& value) { if (value.type() == QVariant::Bool) { return { value.toBool() }; } else if (value.type() == QVariant::String) { @@ -140,7 +140,7 @@ class ValueTraits { template optional convert(const QVariant& value, Error& error, Args&&...args) { - return convert(Value(value), error, std::forward(args)...); + return convert(Convertible(value), error, std::forward(args)...); } } // namespace conversion diff --git a/src/mbgl/style/conversion/constant.cpp b/src/mbgl/style/conversion/constant.cpp index 43feb3380b4..e837c4e70bb 100644 --- a/src/mbgl/style/conversion/constant.cpp +++ b/src/mbgl/style/conversion/constant.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { optional converted = toBool(value); if (!converted) { error = { "value must be a boolean" }; @@ -13,7 +13,7 @@ optional Converter::operator()(const Value& value, Error& error) con return *converted; } -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { optional converted = toNumber(value); if (!converted) { error = { "value must be a number" }; @@ -22,7 +22,7 @@ optional Converter::operator()(const Value& value, Error& error) c return *converted; } -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { optional converted = toString(value); if (!converted) { error = { "value must be a string" }; @@ -31,7 +31,7 @@ optional Converter::operator()(const Value& value, Err return *converted; } -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { optional string = toString(value); if (!string) { error = { "value must be a string" }; @@ -47,7 +47,7 @@ optional Converter::operator()(const Value& value, Error& error) c return *color; } -optional> Converter>::operator()(const Value& value, Error& error) const { +optional> Converter>::operator()(const Convertible& value, Error& error) const { if (!isArray(value)) { error = { "value must be an array" }; return {}; @@ -68,7 +68,7 @@ optional> Converter>::operator()(const Val return result; } -optional> Converter>::operator()(const Value& value, Error& error) const { +optional> Converter>::operator()(const Convertible& value, Error& error) const { if (!isArray(value)) { error = { "value must be an array" }; return {}; diff --git a/src/mbgl/style/conversion/coordinate.cpp b/src/mbgl/style/conversion/coordinate.cpp index 4f92a9a963d..9b2be3381ec 100644 --- a/src/mbgl/style/conversion/coordinate.cpp +++ b/src/mbgl/style/conversion/coordinate.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator() (const Value& value, Error& error) const { +optional Converter::operator() (const Convertible& value, Error& error) const { if (!isArray(value) || arrayLength(value) < 2 ) { error = { "coordinate array must contain numeric longitude and latitude values" }; return {}; diff --git a/src/mbgl/style/conversion/filter.cpp b/src/mbgl/style/conversion/filter.cpp index f3633d5ff72..bb7bb6ea980 100644 --- a/src/mbgl/style/conversion/filter.cpp +++ b/src/mbgl/style/conversion/filter.cpp @@ -5,7 +5,7 @@ namespace mbgl { namespace style { namespace conversion { -static optional normalizeValue(const optional& value, Error& error) { +static optional normalizeValue(const optional& value, Error& error) { if (!value) { error = { "filter expression value must be a boolean, number, or string" }; return {}; @@ -14,7 +14,7 @@ static optional normalizeValue(const optional& value, } } -static optional toFeatureType(const Value& value, Error& error) { +static optional toFeatureType(const Convertible& value, Error& error) { optional type = toString(value); if (!type) { error = { "value for $type filter must be a string" }; @@ -31,8 +31,8 @@ static optional toFeatureType(const Value& value, Error& error) { } } -static optional toFeatureIdentifier(const Value& value, Error& error) { - optional identifier = toValue(value); +static optional toFeatureIdentifier(const Convertible& value, Error& error) { + optional identifier = toValue(value); if (!identifier) { error = { "filter expression value must be a boolean, number, or string" }; return {}; @@ -50,7 +50,7 @@ static optional toFeatureIdentifier(const Value& value, Error } template -optional convertUnaryFilter(const Value& value, Error& error) { +optional convertUnaryFilter(const Convertible& value, Error& error) { if (arrayLength(value) < 2) { error = { "filter expression must have 2 elements" }; return {}; @@ -70,7 +70,7 @@ optional convertUnaryFilter(const Value& value, Error& error) { } template -optional convertEqualityFilter(const Value& value, Error& error) { +optional convertEqualityFilter(const Convertible& value, Error& error) { if (arrayLength(value) < 3) { error = { "filter expression must have 3 elements" }; return {}; @@ -99,7 +99,7 @@ optional convertEqualityFilter(const Value& value, Error& error) { return { IdentifierFilterType { *filterValue } }; } else { - optional filterValue = normalizeValue(toValue(arrayMember(value, 2)), error); + optional filterValue = normalizeValue(toValue(arrayMember(value, 2)), error); if (!filterValue) { return {}; } @@ -109,7 +109,7 @@ optional convertEqualityFilter(const Value& value, Error& error) { } template -optional convertBinaryFilter(const Value& value, Error& error) { +optional convertBinaryFilter(const Convertible& value, Error& error) { if (arrayLength(value) < 3) { error = { "filter expression must have 3 elements" }; return {}; @@ -121,7 +121,7 @@ optional convertBinaryFilter(const Value& value, Error& error) { return {}; } - optional filterValue = normalizeValue(toValue(arrayMember(value, 2)), error); + optional filterValue = normalizeValue(toValue(arrayMember(value, 2)), error); if (!filterValue) { return {}; } @@ -130,7 +130,7 @@ optional convertBinaryFilter(const Value& value, Error& error) { } template -optional convertSetFilter(const Value& value, Error& error) { +optional convertSetFilter(const Convertible& value, Error& error) { if (arrayLength(value) < 2) { error = { "filter expression must at least 2 elements" }; return {}; @@ -167,9 +167,9 @@ optional convertSetFilter(const Value& value, Error& error) { return { IdentifierFilterType { std::move(values) } }; } else { - std::vector values; + std::vector values; for (std::size_t i = 2; i < arrayLength(value); ++i) { - optional filterValue = normalizeValue(toValue(arrayMember(value, i)), error); + optional filterValue = normalizeValue(toValue(arrayMember(value, i)), error); if (!filterValue) { return {}; } @@ -181,7 +181,7 @@ optional convertSetFilter(const Value& value, Error& error) { } template -optional convertCompoundFilter(const Value& value, Error& error) { +optional convertCompoundFilter(const Convertible& value, Error& error) { std::vector filters; for (std::size_t i = 1; i < arrayLength(value); ++i) { optional element = convert(arrayMember(value, i), error); @@ -194,7 +194,7 @@ optional convertCompoundFilter(const Value& value, Error& error) { return { FilterType { std::move(filters) } }; } -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { if (!isArray(value)) { error = { "filter expression must be an array" }; return {}; diff --git a/src/mbgl/style/conversion/geojson.cpp b/src/mbgl/style/conversion/geojson.cpp index 3e7188502f0..e39a1a80ebc 100644 --- a/src/mbgl/style/conversion/geojson.cpp +++ b/src/mbgl/style/conversion/geojson.cpp @@ -5,7 +5,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { return toGeoJSON(value, error); } diff --git a/src/mbgl/style/conversion/geojson_options.cpp b/src/mbgl/style/conversion/geojson_options.cpp index e3d42900912..a2c5ed88160 100644 --- a/src/mbgl/style/conversion/geojson_options.cpp +++ b/src/mbgl/style/conversion/geojson_options.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { GeoJSONOptions options; const auto minzoomValue = objectMember(value, "minzoom"); diff --git a/src/mbgl/style/conversion/layer.cpp b/src/mbgl/style/conversion/layer.cpp index 129c39c4ea4..0ca582f8dce 100644 --- a/src/mbgl/style/conversion/layer.cpp +++ b/src/mbgl/style/conversion/layer.cpp @@ -14,7 +14,7 @@ namespace mbgl { namespace style { namespace conversion { -optional setLayoutProperty(Layer& layer, const std::string& name, const Value& value) { +optional setLayoutProperty(Layer& layer, const std::string& name, const Convertible& value) { static const auto setters = makeLayoutPropertySetters(); auto it = setters.find(name); if (it == setters.end()) { @@ -23,7 +23,7 @@ optional setLayoutProperty(Layer& layer, const std::string& name, const V return it->second(layer, value); } -optional setPaintProperty(Layer& layer, const std::string& name, const Value& value) { +optional setPaintProperty(Layer& layer, const std::string& name, const Convertible& value) { static const auto setters = makePaintPropertySetters(); auto it = setters.find(name); if (it == setters.end()) { @@ -32,18 +32,18 @@ optional setPaintProperty(Layer& layer, const std::string& name, const Va return it->second(layer, value); } -optional setPaintProperties(Layer& layer, const Value& value) { +optional setPaintProperties(Layer& layer, const Convertible& value) { auto paintValue = objectMember(value, "paint"); if (!paintValue) { return {}; } - return eachMember(*paintValue, [&] (const std::string& k, const Value& v) { + return eachMember(*paintValue, [&] (const std::string& k, const Convertible& v) { return setPaintProperty(layer, k, v); }); } template -optional> convertVectorLayer(const std::string& id, const Value& value, Error& error) { +optional> convertVectorLayer(const std::string& id, const Convertible& value, Error& error) { auto sourceValue = objectMember(value, "source"); if (!sourceValue) { error = { "layer must have a source" }; @@ -80,7 +80,7 @@ optional> convertVectorLayer(const std::string& id, const return { std::move(layer) }; } -static optional> convertRasterLayer(const std::string& id, const Value& value, Error& error) { +static optional> convertRasterLayer(const std::string& id, const Convertible& value, Error& error) { auto sourceValue = objectMember(value, "source"); if (!sourceValue) { error = { "layer must have a source" }; @@ -96,11 +96,11 @@ static optional> convertRasterLayer(const std::string& id return { std::make_unique(id, *source) }; } -static optional> convertBackgroundLayer(const std::string& id, const Value&, Error&) { +static optional> convertBackgroundLayer(const std::string& id, const Convertible&, Error&) { return { std::make_unique(id) }; } -optional> Converter>::operator()(const Value& value, Error& error) const { +optional> Converter>::operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error = { "layer must be an object" }; return {}; @@ -183,7 +183,7 @@ optional> Converter>::operator()(c error = { "layout must be an object" }; return {}; } - optional error_ = eachMember(*layoutValue, [&] (const std::string& k, const Value& v) { + optional error_ = eachMember(*layoutValue, [&] (const std::string& k, const Convertible& v) { return setLayoutProperty(*layer, k, v); }); if (error_) { diff --git a/src/mbgl/style/conversion/light.cpp b/src/mbgl/style/conversion/light.cpp index f468bddcc12..f521f743868 100644 --- a/src/mbgl/style/conversion/light.cpp +++ b/src/mbgl/style/conversion/light.cpp @@ -7,7 +7,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error = { "light must be an object" }; return {}; diff --git a/src/mbgl/style/conversion/position.cpp b/src/mbgl/style/conversion/position.cpp index fa6619fee3b..702d250dbf1 100644 --- a/src/mbgl/style/conversion/position.cpp +++ b/src/mbgl/style/conversion/position.cpp @@ -7,7 +7,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { optional> spherical = convert>(value, error); if (!spherical) { diff --git a/src/mbgl/style/conversion/property_setter.hpp b/src/mbgl/style/conversion/property_setter.hpp index ef8377fc127..9e382b9c38d 100644 --- a/src/mbgl/style/conversion/property_setter.hpp +++ b/src/mbgl/style/conversion/property_setter.hpp @@ -13,10 +13,10 @@ namespace mbgl { namespace style { namespace conversion { -using PropertySetter = optional (*) (Layer&, const Value&); +using PropertySetter = optional (*) (Layer&, const Convertible&); template -optional setProperty(Layer& layer, const Value& value) { +optional setProperty(Layer& layer, const Convertible& value) { auto* typedLayer = layer.as(); if (!typedLayer) { return Error { "layer doesn't support this property" }; @@ -33,7 +33,7 @@ optional setProperty(Layer& layer, const Value& value) { } template -optional setTransition(Layer& layer, const Value& value) { +optional setTransition(Layer& layer, const Convertible& value) { auto* typedLayer = layer.as(); if (!typedLayer) { return Error { "layer doesn't support this property" }; @@ -49,7 +49,7 @@ optional setTransition(Layer& layer, const Value& value) { return {}; } -inline optional setVisibility(Layer& layer, const Value& value) { +inline optional setVisibility(Layer& layer, const Convertible& value) { if (isUndefined(value)) { layer.setVisibility(VisibilityType::Visible); return {}; diff --git a/src/mbgl/style/conversion/source.cpp b/src/mbgl/style/conversion/source.cpp index f88d33fa4bc..c10d0babcf8 100644 --- a/src/mbgl/style/conversion/source.cpp +++ b/src/mbgl/style/conversion/source.cpp @@ -14,7 +14,7 @@ namespace style { namespace conversion { // A tile source can either specify a URL to TileJSON, or inline TileJSON. -static optional> convertURLOrTileset(const Value& value, Error& error) { +static optional> convertURLOrTileset(const Convertible& value, Error& error) { auto urlVal = objectMember(value, "url"); if (!urlVal) { optional tileset = convert(value, error); @@ -34,7 +34,7 @@ static optional> convertURLOrTileset(const Value& } static optional> convertRasterSource(const std::string& id, - const Value& value, + const Convertible& value, Error& error) { optional> urlOrTileset = convertURLOrTileset(value, error); if (!urlOrTileset) { @@ -56,7 +56,7 @@ static optional> convertRasterSource(const std::string& } static optional> convertVectorSource(const std::string& id, - const Value& value, + const Convertible& value, Error& error) { optional> urlOrTileset = convertURLOrTileset(value, error); if (!urlOrTileset) { @@ -67,7 +67,7 @@ static optional> convertVectorSource(const std::string& } static optional> convertGeoJSONSource(const std::string& id, - const Value& value, + const Convertible& value, Error& error) { auto dataValue = objectMember(value, "data"); if (!dataValue) { @@ -99,7 +99,7 @@ static optional> convertGeoJSONSource(const std::string& } static optional> convertImageSource(const std::string& id, - const Value& value, + const Convertible& value, Error& error) { auto urlValue = objectMember(value, "url"); if (!urlValue) { @@ -138,7 +138,7 @@ static optional> convertImageSource(const std::string& i return { std::move(result) }; } -optional> Converter>::operator()(const Value& value, Error& error, const std::string& id) const { +optional> Converter>::operator()(const Convertible& value, Error& error, const std::string& id) const { if (!isObject(value)) { error = { "source must be an object" }; return {}; diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp index 42b694c8527..6ae6fede42d 100644 --- a/src/mbgl/style/conversion/stringify.hpp +++ b/src/mbgl/style/conversion/stringify.hpp @@ -98,8 +98,8 @@ void stringify(Writer& writer, const std::unordered_map& m) { } template -void stringify(Writer& writer, const mbgl::Value& v) { - mbgl::Value::visit(v, [&] (const auto& v_) { stringify(writer, v_); }); +void stringify(Writer& writer, const Value& v) { + Value::visit(v, [&] (const auto& v_) { stringify(writer, v_); }); } template diff --git a/src/mbgl/style/conversion/tileset.cpp b/src/mbgl/style/conversion/tileset.cpp index 54a486cb969..b9383c41b81 100644 --- a/src/mbgl/style/conversion/tileset.cpp +++ b/src/mbgl/style/conversion/tileset.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { Tileset result; auto tiles = objectMember(value, "tiles"); diff --git a/src/mbgl/style/conversion/transition_options.cpp b/src/mbgl/style/conversion/transition_options.cpp index caabe7ec887..8a60c5bfd8e 100644 --- a/src/mbgl/style/conversion/transition_options.cpp +++ b/src/mbgl/style/conversion/transition_options.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Value& value, Error& error) const { +optional Converter::operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error = { "transition must be an object" }; return {}; diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index 23901f5dc93..10fce339860 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -258,7 +258,7 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique } layer = reference->cloneRef(id); - conversion::setPaintProperties(*layer, conversion::Value(&value)); + conversion::setPaintProperties(*layer, conversion::Convertible(&value)); } else { conversion::Error error; optional> converted = conversion::convert>(value, error); diff --git a/src/mbgl/style/rapidjson_conversion.hpp b/src/mbgl/style/rapidjson_conversion.hpp index ae3ead24b06..967f1d829cb 100644 --- a/src/mbgl/style/rapidjson_conversion.hpp +++ b/src/mbgl/style/rapidjson_conversion.hpp @@ -11,7 +11,7 @@ namespace style { namespace conversion { template <> -class ValueTraits { +class ConversionTraits { public: static bool isUndefined(const JSValue* value) { return value->IsNull(); @@ -81,7 +81,7 @@ class ValueTraits { return {{ value->GetString(), value->GetStringLength() }}; } - static optional toValue(const JSValue* value) { + static optional toValue(const JSValue* value) { switch (value->GetType()) { case rapidjson::kNullType: case rapidjson::kFalseType: @@ -115,7 +115,7 @@ class ValueTraits { template optional convert(const JSValue& value, Error& error, Args&&...args) { - return convert(Value(&value), error, std::forward(args)...); + return convert(Convertible(&value), error, std::forward(args)...); } } // namespace conversion