diff options
author | Anand Thakker <github@anandthakker.net> | 2017-07-10 10:48:10 -0400 |
---|---|---|
committer | Anand Thakker <github@anandthakker.net> | 2017-07-10 10:48:10 -0400 |
commit | 70809fd85f890e326b1d963eb6ace7b93be46d61 (patch) | |
tree | 761815f7445bf0b9d72b7dbe06118c0b3e33b78e | |
parent | 2893112609489ae007b087474ac7a2349c0c04d9 (diff) | |
download | qtlocation-mapboxgl-upstream/expressions-temp.tar.gz |
troubleshooting 'duplicate symbol' link errorupstream/expressions-temp
-rw-r--r-- | cmake/core-files.cmake | 5 | ||||
-rw-r--r-- | include/mbgl/style/expression/expression.hpp | 30 | ||||
-rw-r--r-- | include/mbgl/style/expression/type.hpp (renamed from include/mbgl/style/function/type.hpp) | 14 | ||||
-rw-r--r-- | include/mbgl/style/expression/value.hpp | 53 | ||||
-rw-r--r-- | platform/node/src/node_expression.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/style/expression/type.cpp (renamed from src/mbgl/style/function/type.cpp) | 2 |
6 files changed, 73 insertions, 32 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index d3eb02ac13..01fd8dd1dc 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -392,6 +392,9 @@ set(MBGL_CORE_FILES include/mbgl/style/expression/expression.hpp include/mbgl/style/expression/parse.hpp include/mbgl/style/expression/parsing_context.hpp + include/mbgl/style/expression/type.hpp + include/mbgl/style/expression/value.hpp + src/mbgl/style/expression/type.cpp # style/function include/mbgl/style/function/camera_function.hpp @@ -404,11 +407,9 @@ set(MBGL_CORE_FILES include/mbgl/style/function/identity_stops.hpp include/mbgl/style/function/interval_stops.hpp include/mbgl/style/function/source_function.hpp - include/mbgl/style/function/type.hpp src/mbgl/style/function/categorical_stops.cpp src/mbgl/style/function/expression.cpp src/mbgl/style/function/identity_stops.cpp - src/mbgl/style/function/type.cpp # style/layers include/mbgl/style/layers/background_layer.hpp diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index e36db1b3c7..99aaed8a14 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -6,8 +6,8 @@ #include <mbgl/util/optional.hpp> #include <mbgl/util/variant.hpp> #include <mbgl/util/color.hpp> -#include <mbgl/style/function/type.hpp> -#include <mbgl/util/feature.hpp> +#include <mbgl/style/expression/type.hpp> +#include <mbgl/style/expression/value.hpp> #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/conversion.hpp> @@ -20,20 +20,6 @@ class GeometryTileFeature; namespace style { namespace expression { -struct Value; -using ValueBase = variant< - NullValue, - float, - std::string, - mbgl::Color, - mapbox::util::recursive_wrapper<std::vector<Value>>, - mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>>>; -struct Value : ValueBase { - using ValueBase::ValueBase; -}; - -constexpr NullValue Null = NullValue(); - struct EvaluationError { std::string message; }; @@ -102,17 +88,7 @@ public: template <class V> static ParseResult parse(const V& value, const ParsingContext& ctx) { const Value& parsedValue = parseValue(value); - const type::Type& type = parsedValue.match( - [&](float) -> type::Type { return type::Primitive::Number; }, - [&](const std::string&) -> type::Type { return type::Primitive::String; }, - [&](const mbgl::Color&) -> type::Type { return type::Primitive::Color; }, - [&](const NullValue&) -> type::Type { return type::Primitive::Null; }, - [&](const std::unordered_map<std::string, Value>&) -> type::Type { return type::Primitive::Object; }, - [&](const std::vector<Value>& arr) -> type::Type { - // TODO - return type::Array(type::Primitive::Value, arr.size()); - } - ); + const type::Type& type = typeOf(parsedValue); return std::make_unique<LiteralExpression>(ctx.key(), type, parsedValue); } diff --git a/include/mbgl/style/function/type.hpp b/include/mbgl/style/expression/type.hpp index 19897ac77f..72f36e2451 100644 --- a/include/mbgl/style/function/type.hpp +++ b/include/mbgl/style/expression/type.hpp @@ -30,6 +30,9 @@ using Type = variant< Array, NArgs, Lambda>; + +template <class T> +std::string toString(const T& t); class Primitive { public: @@ -62,7 +65,13 @@ public: Array(ValueType itemType_) : itemType(itemType_) {} Array(ValueType itemType_, std::size_t N_) : itemType(itemType_), N(N_) {} std::string getName() const { - return "array"; + if (N) { + return "Array<" + toString(itemType) + ", " + std::to_string(*N) + ">"; + } else if (toString(itemType) == "Value") { + return "Array"; + } else { + return "Array<" + toString(itemType) + ">"; + } } private: @@ -110,6 +119,9 @@ private: std::vector<ValueType> params; }; +template <class T> +std::string toString(const T& t) { return t.match([&] (const auto& t) { return t.getName(); }); } + } // namespace type } // namespace expression diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp new file mode 100644 index 0000000000..0cac50c6ab --- /dev/null +++ b/include/mbgl/style/expression/value.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include <mbgl/util/variant.hpp> +#include <mbgl/util/feature.hpp> +#include <mbgl/style/expression/type.hpp> + +namespace mbgl { +namespace style { +namespace expression { + +struct Value; +using ValueBase = variant< + NullValue, + float, + std::string, + mbgl::Color, + mapbox::util::recursive_wrapper<std::vector<Value>>, + mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>>>; +struct Value : ValueBase { + using ValueBase::ValueBase; +}; + +constexpr NullValue Null = NullValue(); + +type::Type typeOf(const Value& value) { + return value.match( + [&](float) -> type::Type { return type::Primitive::Number; }, + [&](const std::string&) -> type::Type { return type::Primitive::String; }, + [&](const mbgl::Color&) -> type::Type { return type::Primitive::Color; }, + [&](const NullValue&) -> type::Type { return type::Primitive::Null; }, + [&](const std::unordered_map<std::string, Value>&) -> type::Type { return type::Primitive::Object; }, + [&](const std::vector<Value>& arr) -> type::Type { + optional<type::Type> itemType; + for (const auto& item : arr) { + const auto& t = typeOf(item); + if (!itemType) { + itemType = {t}; + } else if (type::toString(*itemType) == type::toString(t)) { + continue; + } else { + itemType = {type::Primitive::Value}; + break; + } + } + + return type::Array(type::Primitive::Value, arr.size()); + } + ); +} + +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/platform/node/src/node_expression.hpp b/platform/node/src/node_expression.hpp index 5cfc3b553e..e977b58288 100644 --- a/platform/node/src/node_expression.hpp +++ b/platform/node/src/node_expression.hpp @@ -11,7 +11,6 @@ #include <nan.h> #pragma GCC diagnostic pop -using namespace mbgl::style; using namespace mbgl::style::expression; namespace node_mbgl { diff --git a/src/mbgl/style/function/type.cpp b/src/mbgl/style/expression/type.cpp index 5e1a95433f..2b7f78a8d8 100644 --- a/src/mbgl/style/function/type.cpp +++ b/src/mbgl/style/expression/type.cpp @@ -1,4 +1,4 @@ -#include <mbgl/style/function/type.hpp> +#include <mbgl/style/expression/type.hpp> namespace mbgl { namespace style { |