blob: 0cac50c6ab5214f4801b3895cfd1e55399b022ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
|