1 #pragma once
2 
3 #include <mbgl/util/optional.hpp>
4 #include <mbgl/util/string.hpp>
5 #include <mbgl/util/variant.hpp>
6 #include <vector>
7 
8 namespace mbgl {
9 namespace style {
10 namespace expression {
11 namespace type {
12 
13 template <class T>
14 std::string toString(const T& t);
15 
16 struct NullType {
NullTypembgl::style::expression::type::NullType17     constexpr NullType() {};
getNamembgl::style::expression::type::NullType18     std::string getName() const { return "null"; }
operator ==mbgl::style::expression::type::NullType19     bool operator==(const NullType&) const { return true; }
20 };
21 
22 struct NumberType {
NumberTypembgl::style::expression::type::NumberType23     constexpr NumberType() {};
getNamembgl::style::expression::type::NumberType24     std::string getName() const { return "number"; }
operator ==mbgl::style::expression::type::NumberType25     bool operator==(const NumberType&) const { return true; }
26 };
27 
28 struct BooleanType {
BooleanTypembgl::style::expression::type::BooleanType29     constexpr BooleanType() {};
getNamembgl::style::expression::type::BooleanType30     std::string getName() const { return "boolean"; }
operator ==mbgl::style::expression::type::BooleanType31     bool operator==(const BooleanType&) const { return true; }
32 };
33 
34 struct StringType {
StringTypembgl::style::expression::type::StringType35     constexpr StringType() {};
getNamembgl::style::expression::type::StringType36     std::string getName() const { return "string"; }
operator ==mbgl::style::expression::type::StringType37     bool operator==(const StringType&) const { return true; }
38 };
39 
40 struct ColorType {
ColorTypembgl::style::expression::type::ColorType41     constexpr ColorType() {};
getNamembgl::style::expression::type::ColorType42     std::string getName() const { return "color"; }
operator ==mbgl::style::expression::type::ColorType43     bool operator==(const ColorType&) const { return true; }
44 };
45 
46 struct ObjectType {
ObjectTypembgl::style::expression::type::ObjectType47     constexpr ObjectType() {};
getNamembgl::style::expression::type::ObjectType48     std::string getName() const { return "object"; }
operator ==mbgl::style::expression::type::ObjectType49     bool operator==(const ObjectType&) const { return true; }
50 };
51 
52 struct ErrorType {
ErrorTypembgl::style::expression::type::ErrorType53     constexpr ErrorType() {};
getNamembgl::style::expression::type::ErrorType54     std::string getName() const { return "error"; }
operator ==mbgl::style::expression::type::ErrorType55     bool operator==(const ErrorType&) const { return true; }
56 };
57 
58 struct ValueType {
ValueTypembgl::style::expression::type::ValueType59     constexpr ValueType() {};
getNamembgl::style::expression::type::ValueType60     std::string getName() const { return "value"; }
operator ==mbgl::style::expression::type::ValueType61     bool operator==(const ValueType&) const { return true; }
62 };
63 
64 struct CollatorType {
CollatorTypembgl::style::expression::type::CollatorType65     constexpr CollatorType() {}; // NOLINT
getNamembgl::style::expression::type::CollatorType66     std::string getName() const { return "collator"; }
operator ==mbgl::style::expression::type::CollatorType67     bool operator==(const CollatorType&) const { return true; }
68 };
69 
70 constexpr NullType Null;
71 constexpr NumberType Number;
72 constexpr StringType String;
73 constexpr BooleanType Boolean;
74 constexpr ColorType Color;
75 constexpr ValueType Value;
76 constexpr ObjectType Object;
77 constexpr CollatorType Collator;
78 constexpr ErrorType Error;
79 
80 struct Array;
81 
82 using Type = variant<
83     NullType,
84     NumberType,
85     BooleanType,
86     StringType,
87     ColorType,
88     ObjectType,
89     ValueType,
90     mapbox::util::recursive_wrapper<Array>,
91     CollatorType,
92     ErrorType>;
93 
94 struct Array {
Arraymbgl::style::expression::type::Array95     explicit Array(Type itemType_) : itemType(std::move(itemType_)) {}
Arraymbgl::style::expression::type::Array96     Array(Type itemType_, std::size_t N_) : itemType(std::move(itemType_)), N(N_) {}
Arraymbgl::style::expression::type::Array97     Array(Type itemType_, optional<std::size_t> N_) : itemType(std::move(itemType_)), N(std::move(N_)) {}
getNamembgl::style::expression::type::Array98     std::string getName() const {
99         if (N) {
100             return "array<" + toString(itemType) + ", " + util::toString(*N) + ">";
101         } else if (itemType == Value) {
102             return "array";
103         } else {
104             return "array<" + toString(itemType) + ">";
105         }
106     }
107 
operator ==mbgl::style::expression::type::Array108     bool operator==(const Array& rhs) const { return itemType == rhs.itemType && N == rhs.N; }
109 
110     Type itemType;
111     optional<std::size_t> N;
112 };
113 
114 template <class T>
__anon16efe5200102(const auto& t) 115 std::string toString(const T& type) { return type.match([&] (const auto& t) { return t.getName(); }); }
116 
117 } // namespace type
118 } // namespace expression
119 } // namespace style
120 } // namespace mbgl
121