MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
type.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mbgl/util/string.hpp>
4 #include <mbgl/util/variant.hpp>
5 #include <vector>
6 
7 #include <optional>
8 
9 namespace mbgl {
10 namespace style {
11 namespace expression {
12 namespace type {
13 
14 template <class T>
15 std::string toString(const T& t);
16 
17 struct NullType {
18  constexpr NullType() = default;
19  std::string getName() const { return "null"; }
20  bool operator==(const NullType&) const { return true; }
21 };
22 
23 struct NumberType {
24  constexpr NumberType() = default;
25  std::string getName() const { return "number"; }
26  bool operator==(const NumberType&) const { return true; }
27 };
28 
29 struct BooleanType {
30  constexpr BooleanType() = default;
31  std::string getName() const { return "boolean"; }
32  bool operator==(const BooleanType&) const { return true; }
33 };
34 
35 struct StringType {
36  constexpr StringType() = default;
37  std::string getName() const { return "string"; }
38  bool operator==(const StringType&) const { return true; }
39 };
40 
41 struct ColorType {
42  constexpr ColorType() = default;
43  std::string getName() const { return "color"; }
44  bool operator==(const ColorType&) const { return true; }
45 };
46 
47 struct ObjectType {
48  constexpr ObjectType() = default;
49  std::string getName() const { return "object"; }
50  bool operator==(const ObjectType&) const { return true; }
51 };
52 
53 struct ErrorType {
54  constexpr ErrorType() = default;
55  std::string getName() const { return "error"; }
56  bool operator==(const ErrorType&) const { return true; }
57 };
58 
59 struct ValueType {
60  constexpr ValueType() = default;
61  std::string getName() const { return "value"; }
62  bool operator==(const ValueType&) const { return true; }
63 };
64 
65 struct CollatorType {
66  constexpr CollatorType() = default;
67  std::string getName() const { return "collator"; }
68  bool operator==(const CollatorType&) const { return true; }
69 };
70 
71 struct FormattedType {
72  constexpr FormattedType() = default;
73  std::string getName() const { return "formatted"; }
74  bool operator==(const FormattedType&) const { return true; }
75 };
76 
77 struct ImageType {
78  constexpr ImageType() = default;
79  std::string getName() const { return "resolvedImage"; }
80  bool operator==(const ImageType&) const { return true; }
81 };
82 
83 constexpr NullType Null;
84 constexpr NumberType Number;
85 constexpr StringType String;
86 constexpr BooleanType Boolean;
87 constexpr ColorType Color;
88 constexpr ValueType Value;
89 constexpr ObjectType Object;
92 constexpr ErrorType Error;
93 constexpr ImageType Image;
94 
95 struct Array;
96 
98  NumberType,
100  StringType,
101  ColorType,
102  ObjectType,
103  ValueType,
104  mapbox::util::recursive_wrapper<Array>,
105  CollatorType,
107  ErrorType,
108  ImageType>;
109 
110 struct Array {
111  explicit Array(Type itemType_) : itemType(std::move(itemType_)) {}
112  Array(Type itemType_, std::size_t N_) : itemType(std::move(itemType_)), N(N_) {}
113  Array(Type itemType_, std::optional<std::size_t> N_) : itemType(std::move(itemType_)), N(std::move(N_)) {}
115  if (N) {
116  return "array<" + toString(itemType) + ", " + util::toString(*N) + ">";
117  } else if (itemType == Value) {
118  return "array";
119  } else {
120  return "array<" + toString(itemType) + ">";
121  }
122  }
123 
124  bool operator==(const Array& rhs) const { return itemType == rhs.itemType && N == rhs.N; }
125 
127  std::optional<std::size_t> N;
128 };
129 
130 template <class T>
131 std::string toString(const T& type) { return type.match([&] (const auto& t) { return t.getName(); }); }
132 
133 } // namespace type
134 } // namespace expression
135 } // namespace style
136 } // namespace mbgl
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
constexpr NullType Null
Definition: type.hpp:83
constexpr ValueType Value
Definition: type.hpp:88
constexpr ObjectType Object
Definition: type.hpp:89
constexpr BooleanType Boolean
Definition: type.hpp:86
constexpr NumberType Number
Definition: type.hpp:84
constexpr ColorType Color
Definition: type.hpp:87
std::string toString(const T &t)
Definition: type.hpp:131
constexpr CollatorType Collator
Definition: type.hpp:90
constexpr StringType String
Definition: type.hpp:85
constexpr FormattedType Formatted
Definition: type.hpp:91
constexpr ErrorType Error
Definition: type.hpp:92
variant< NullType, NumberType, BooleanType, StringType, ColorType, ObjectType, ValueType, mapbox::util::recursive_wrapper< Array >, CollatorType, FormattedType, ErrorType, ImageType > Type
Definition: type.hpp:108
constexpr ImageType Image
Definition: type.hpp:93
std::string toString(const CanonicalTileID &)
Definition: actor.hpp:15
mapbox::util::variant< T... > variant
Definition: variant.hpp:17
Definition: tile_id.hpp:256
Array(Type itemType_, std::size_t N_)
Definition: type.hpp:112
bool operator==(const Array &rhs) const
Definition: type.hpp:124
std::optional< std::size_t > N
Definition: type.hpp:127
Array(Type itemType_, std::optional< std::size_t > N_)
Definition: type.hpp:113
std::string getName() const
Definition: type.hpp:114
bool operator==(const BooleanType &) const
Definition: type.hpp:32
bool operator==(const CollatorType &) const
Definition: type.hpp:68
bool operator==(const ColorType &) const
Definition: type.hpp:44
bool operator==(const ErrorType &) const
Definition: type.hpp:56
bool operator==(const FormattedType &) const
Definition: type.hpp:74
bool operator==(const ImageType &) const
Definition: type.hpp:80
bool operator==(const NullType &) const
Definition: type.hpp:20
bool operator==(const NumberType &) const
Definition: type.hpp:26
bool operator==(const ObjectType &) const
Definition: type.hpp:50
bool operator==(const StringType &) const
Definition: type.hpp:38
bool operator==(const ValueType &) const
Definition: type.hpp:62