summaryrefslogtreecommitdiff
path: root/include/mbgl/style/expression/value.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/style/expression/value.hpp')
-rw-r--r--include/mbgl/style/expression/value.hpp53
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