1 | #pragma once |
---|---|
2 | |
3 | #include <mbgl/style/expression/expression.hpp> |
4 | #include <mbgl/style/expression/parsing_context.hpp> |
5 | #include <mbgl/style/conversion.hpp> |
6 | |
7 | #include <memory> |
8 | |
9 | namespace mbgl { |
10 | namespace style { |
11 | namespace expression { |
12 | |
13 | class Literal : public Expression { |
14 | public: |
15 | Literal(Value value_) |
16 | : Expression(Kind::Literal, typeOf(value: value_)) |
17 | , value(value_) |
18 | {} |
19 | |
20 | Literal(type::Array type_, std::vector<Value> value_) |
21 | : Expression(Kind::Literal, type_) |
22 | , value(value_) |
23 | {} |
24 | |
25 | EvaluationResult evaluate(const EvaluationContext&) const override { |
26 | return value; |
27 | } |
28 | |
29 | static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); |
30 | |
31 | void eachChild(const std::function<void(const Expression&)>&) const override {} |
32 | |
33 | bool operator==(const Expression& e) const override { |
34 | if (e.getKind() == Kind::Literal) { |
35 | auto rhs = static_cast<const Literal*>(&e); |
36 | return value == rhs->value; |
37 | } |
38 | return false; |
39 | } |
40 | |
41 | std::vector<optional<Value>> possibleOutputs() const override { |
42 | return {{ value }}; |
43 | } |
44 | |
45 | Value getValue() const { |
46 | return value; |
47 | } |
48 | |
49 | mbgl::Value serialize() const override; |
50 | std::string getOperator() const override { return "literal"; } |
51 | |
52 | private: |
53 | Value value; |
54 | }; |
55 | |
56 | } // namespace expression |
57 | } // namespace style |
58 | } // namespace mbgl |
59 |