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 /include/mbgl/style/expression/value.hpp | |
parent | 2893112609489ae007b087474ac7a2349c0c04d9 (diff) | |
download | qtlocation-mapboxgl-upstream/expressions-temp.tar.gz |
troubleshooting 'duplicate symbol' link errorupstream/expressions-temp
Diffstat (limited to 'include/mbgl/style/expression/value.hpp')
-rw-r--r-- | include/mbgl/style/expression/value.hpp | 53 |
1 files changed, 53 insertions, 0 deletions
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 |