From 3300fc1eeca8e778c6af01fe0f641e5978ad4c77 Mon Sep 17 00:00:00 2001 From: Wilhelm Berg Date: Thu, 23 Aug 2018 18:13:23 +0200 Subject: down to 289 compile errors --- include/mbgl/style/expression/value.hpp | 127 ++++++++++++++++++++++++++------ 1 file changed, 106 insertions(+), 21 deletions(-) diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index b1126118a9..6170ac46ec 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -18,29 +18,102 @@ namespace expression { struct Value; -using ValueBase = variant< - NullValue, - bool, - double, - std::string, - Color, - Collator, - mapbox::util::recursive_wrapper>, - mapbox::util::recursive_wrapper>>; +using ValueBase = variant>, + mapbox::util::recursive_wrapper>>; struct Value : ValueBase { using ValueBase::ValueBase; - + + template + bool is(T*) const { + return ValueBase::is(); + } + + template <> + bool is(float*) const { + return ValueBase::is(); + } + + template + bool is() const { + return ValueBase::is(); + } + template + T& get(T*) { + return ValueBase::get(); + } + template + T const& get(T*) const { + return ValueBase::get(); + } + template <> + float const& get(float*) const { + return ValueBase::get(); + } + + template + T& get() { + return ValueBase::get(); + } + template + T const& get() const { + return ValueBase::get(); + } + + Value(NullValue&& args) : ValueBase(std::move(args)) { + } + Value(bool&& args) : ValueBase(std::forward(args)) { + } + Value(double&& args) : ValueBase(std::forward(args)) { + } + Value(std::string&& args) : ValueBase(std::move(args)) { + } + Value(Color&& args) : ValueBase(std::forward(args)) { + } + Value(std::vector&& args) + : ValueBase(mapbox::util::recursive_wrapper>(args)) { + } + typedef mapbox::util::recursive_wrapper> rec_map; + Value(std::unordered_map&& args) : ValueBase(rec_map(args)) { + } + + Value(const NullValue& args) : ValueBase(args) { + } + Value(const bool& args) : ValueBase(args) { + } + Value(const double& args) : ValueBase(args) { + } + Value(const std::string& args) : ValueBase(args) { + } + Value(const Color& args) : ValueBase(args) { + } + Value(const std::vector& args) + : ValueBase(mapbox::util::recursive_wrapper>(args)) { + } + Value(const std::unordered_map& args) : ValueBase(rec_map(args)) { + } + + Value(const Value&) = default; + // Javascript's Number.MAX_SAFE_INTEGER - static uint64_t maxSafeInteger() { return 9007199254740991ULL; } - - static bool isSafeInteger(uint64_t x) { return x <= maxSafeInteger(); }; + static uint64_t maxSafeInteger() { + return 9007199254740991ULL; + } + + static bool isSafeInteger(uint64_t x) { + return x <= maxSafeInteger(); + }; static bool isSafeInteger(int64_t x) { return static_cast(x > 0 ? x : -x) <= maxSafeInteger(); } static bool isSafeInteger(double x) { return static_cast(x > 0 ? x : -x) <= maxSafeInteger(); } - }; constexpr NullValue Null = NullValue(); @@ -73,9 +146,15 @@ struct ValueConverter { template <> struct ValueConverter { - static type::Type expressionType() { return type::Value; } - static Value toExpressionValue(const Value& value) { return value; } - static optional fromExpressionValue(const Value& value) { return value; } + static type::Type expressionType() { + return type::Value; + } + static Value toExpressionValue(const Value& value) { + return value; + } + static optional fromExpressionValue(const Value& value) { + return value; + } }; template <> @@ -86,7 +165,9 @@ struct ValueConverter { template <> struct ValueConverter { - static type::Type expressionType() { return type::Number; } + static type::Type expressionType() { + return type::Number; + } static Value toExpressionValue(const float value); static optional fromExpressionValue(const Value& value); }; @@ -111,14 +192,18 @@ struct ValueConverter> { template <> struct ValueConverter { - static type::Type expressionType() { return type::Array(type::Number, 3); } + static type::Type expressionType() { + return type::Array(type::Number, 3); + } static Value toExpressionValue(const mbgl::style::Position& value); static optional fromExpressionValue(const Value& v); }; template -struct ValueConverter::value >> { - static type::Type expressionType() { return type::String; } +struct ValueConverter::value>> { + static type::Type expressionType() { + return type::String; + } static Value toExpressionValue(const T& value); static optional fromExpressionValue(const Value& value); }; -- cgit v1.2.1