MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
literal.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include <memory>
8 
9 namespace mbgl {
10 namespace style {
11 namespace expression {
12 
13 class Literal : public Expression {
14 public:
15  Literal(const Value& value_) : Expression(Kind::Literal, typeOf(value_)), value(value_) {}
16 
17  Literal(const type::Array& type_, std::vector<Value> value_)
18  : Expression(Kind::Literal, type_), value(std::move(value_)) {}
19 
20  EvaluationResult evaluate(const EvaluationContext&) const override {
21  return value;
22  }
23 
25 
26  void eachChild(const std::function<void(const Expression&)>&) const override {}
27 
28  bool operator==(const Expression& e) const override {
29  if (e.getKind() == Kind::Literal) {
30  auto rhs = static_cast<const Literal*>(&e);
31  return value == rhs->value;
32  }
33  return false;
34  }
35 
36  std::vector<std::optional<Value>> possibleOutputs() const override {
37  return {{ value }};
38  }
39 
40  Value getValue() const {
41  return value;
42  }
43 
44  mbgl::Value serialize() const override;
45  std::string getOperator() const override { return "literal"; }
46 
47 private:
48  Value value;
49 };
50 
51 } // namespace expression
52 } // namespace style
53 } // namespace mbgl
void eachChild(const std::function< void(const Expression &)> &) const override
Definition: literal.hpp:26
std::vector< std::optional< Value > > possibleOutputs() const override
Definition: literal.hpp:36
std::string getOperator() const override
Definition: literal.hpp:45
mbgl::Value serialize() const override
Literal(const Value &value_)
Definition: literal.hpp:15
Literal(const type::Array &type_, std::vector< Value > value_)
Definition: literal.hpp:17
bool operator==(const Expression &e) const override
Definition: literal.hpp:28
static ParseResult parse(const mbgl::style::conversion::Convertible &, ParsingContext &)
EvaluationResult evaluate(const EvaluationContext &) const override
Definition: literal.hpp:20
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
std::optional< std::unique_ptr< Expression > > ParseResult
type::Type typeOf(const Value &value)
Definition: actor.hpp:15
mapbox::base::Value Value
Definition: feature.hpp:11
Definition: tile_id.hpp:256