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: Literal(Value value_)15 Literal(Value value_) 16 : Expression(Kind::Literal, typeOf(value_)) 17 , value(value_) 18 {} 19 Literal(type::Array type_,std::vector<Value> value_)20 Literal(type::Array type_, std::vector<Value> value_) 21 : Expression(Kind::Literal, type_) 22 , value(value_) 23 {} 24 evaluate(const EvaluationContext &) const25 EvaluationResult evaluate(const EvaluationContext&) const override { 26 return value; 27 } 28 29 static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); 30 eachChild(const std::function<void (const Expression &)> &) const31 void eachChild(const std::function<void(const Expression&)>&) const override {} 32 operator ==(const Expression & e) const33 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 possibleOutputs() const41 std::vector<optional<Value>> possibleOutputs() const override { 42 return {{ value }}; 43 } 44 getValue() const45 Value getValue() const { 46 return value; 47 } 48 49 mbgl::Value serialize() const override; getOperator() const50 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