MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
let.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include <memory>
8 #include <map>
9 #include <optional>
10 
11 namespace mbgl {
12 namespace style {
13 namespace expression {
14 
15 class Let : public Expression {
16 public:
17  using Bindings = std::map<std::string, std::shared_ptr<Expression>>;
18 
19  Let(Bindings bindings_, std::unique_ptr<Expression> result_) :
20  Expression(Kind::Let, result_->getType()),
21  bindings(std::move(bindings_)),
22  result(std::move(result_))
23  {}
24 
26 
27  EvaluationResult evaluate(const EvaluationContext& params) const override;
28  void eachChild(const std::function<void(const Expression&)>&) const override;
29 
30  bool operator==(const Expression& e) const override {
31  if (e.getKind() == Kind::Let) {
32  auto rhs = static_cast<const Let*>(&e);
33  return *result == *(rhs->result);
34  }
35  return false;
36  }
37 
38  std::vector<std::optional<Value>> possibleOutputs() const override;
39 
40  Expression* getResult() const {
41  return result.get();
42  }
43 
44  mbgl::Value serialize() const override;
45  std::string getOperator() const override { return "let"; }
46 private:
47  Bindings bindings;
48  std::unique_ptr<Expression> result;
49 };
50 
51 class Var : public Expression {
52 public:
53  Var(std::string name_, std::shared_ptr<Expression> value_)
54  : Expression(Kind::Var, value_->getType()), name(std::move(name_)), value(std::move(value_)) {}
55 
57 
58  EvaluationResult evaluate(const EvaluationContext& params) const override;
59  void eachChild(const std::function<void(const Expression&)>&) const override;
60 
61  bool operator==(const Expression& e) const override {
62  if (e.getKind() == Kind::Var) {
63  auto rhs = static_cast<const Var*>(&e);
64  return *value == *(rhs->value);
65  }
66  return false;
67  }
68 
69  std::vector<std::optional<Value>> possibleOutputs() const override;
70 
71  mbgl::Value serialize() const override;
72  std::string getOperator() const override { return "var"; }
73 
74  const std::shared_ptr<Expression>& getBoundExpression() const { return value; }
75 
76 private:
77  std::string name;
78  std::shared_ptr<Expression> value;
79 };
80 
81 } // namespace expression
82 } // namespace style
83 } // namespace mbgl
mbgl::Value serialize() const override
bool operator==(const Expression &e) const override
Definition: let.hpp:30
static ParseResult parse(const mbgl::style::conversion::Convertible &, ParsingContext &)
std::vector< std::optional< Value > > possibleOutputs() const override
std::map< std::string, std::shared_ptr< Expression > > Bindings
Definition: let.hpp:17
EvaluationResult evaluate(const EvaluationContext &params) const override
void eachChild(const std::function< void(const Expression &)> &) const override
Expression * getResult() const
Definition: let.hpp:40
std::string getOperator() const override
Definition: let.hpp:45
Let(Bindings bindings_, std::unique_ptr< Expression > result_)
Definition: let.hpp:19
const std::shared_ptr< Expression > & getBoundExpression() const
Definition: let.hpp:74
mbgl::Value serialize() const override
Var(std::string name_, std::shared_ptr< Expression > value_)
Definition: let.hpp:53
EvaluationResult evaluate(const EvaluationContext &params) const override
std::vector< std::optional< Value > > possibleOutputs() const override
void eachChild(const std::function< void(const Expression &)> &) const override
static ParseResult parse(const mbgl::style::conversion::Convertible &, ParsingContext &)
std::string getOperator() const override
Definition: let.hpp:72
bool operator==(const Expression &e) const override
Definition: let.hpp:61
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
std::optional< std::unique_ptr< Expression > > ParseResult
Definition: actor.hpp:15
mapbox::base::Value Value
Definition: feature.hpp:11
Definition: tile_id.hpp:256