MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
match.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 template <typename T>
14 class Match : public Expression {
15 public:
16  using Branches = std::unordered_map<T, std::shared_ptr<Expression>>;
17 
18  Match(const type::Type& type_,
19  std::unique_ptr<Expression> input_,
20  Branches branches_,
21  std::unique_ptr<Expression> otherwise_)
22  : Expression(Kind::Match, type_),
23  input(std::move(input_)),
24  branches(std::move(branches_)),
25  otherwise(std::move(otherwise_)) {}
26 
27  EvaluationResult evaluate(const EvaluationContext& params) const override;
28 
29  void eachChild(const std::function<void(const Expression&)>& visit) const override;
30 
31  bool operator==(const Expression& e) const override;
32 
33  std::vector<std::optional<Value>> possibleOutputs() const override;
34 
35  mbgl::Value serialize() const override;
36  std::string getOperator() const override { return "match"; }
37 private:
38  std::unique_ptr<Expression> input;
39  Branches branches;
40  std::unique_ptr<Expression> otherwise;
41 };
42 
44 
45 } // namespace expression
46 } // namespace style
47 } // namespace mbgl
EvaluationResult evaluate(const EvaluationContext &params) const override
void eachChild(const std::function< void(const Expression &)> &visit) const override
mbgl::Value serialize() const override
std::vector< std::optional< Value > > possibleOutputs() const override
std::string getOperator() const override
Definition: match.hpp:36
Match(const type::Type &type_, std::unique_ptr< Expression > input_, Branches branches_, std::unique_ptr< Expression > otherwise_)
Definition: match.hpp:18
bool operator==(const Expression &e) const override
std::unordered_map< T, std::shared_ptr< Expression > > Branches
Definition: match.hpp:16
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
variant< NullType, NumberType, BooleanType, StringType, ColorType, ObjectType, ValueType, mapbox::util::recursive_wrapper< Array >, CollatorType, FormattedType, ErrorType, ImageType > Type
Definition: type.hpp:108
std::optional< std::unique_ptr< Expression > > ParseResult
ParseResult parseMatch(const mbgl::style::conversion::Convertible &value, ParsingContext &ctx)
Definition: actor.hpp:15
mapbox::base::Value Value
Definition: feature.hpp:11
Definition: tile_id.hpp:256