From f648cfeef6544755fdb10c3cf8847e878d70e0ff Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Wed, 8 Nov 2017 12:34:02 -0500 Subject: Implement Expressions (#9439) Ports https://github.com/mapbox/mapbox-gl-js/pull/4777 (and its several follow-ups) --- include/mbgl/style/expression/let.hpp | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 include/mbgl/style/expression/let.hpp (limited to 'include/mbgl/style/expression/let.hpp') diff --git a/include/mbgl/style/expression/let.hpp b/include/mbgl/style/expression/let.hpp new file mode 100644 index 0000000000..aaa16ca0c2 --- /dev/null +++ b/include/mbgl/style/expression/let.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include + +#include +#include + +namespace mbgl { +namespace style { +namespace expression { + +class Let : public Expression { +public: + using Bindings = std::map>; + + Let(Bindings bindings_, std::unique_ptr result_) : + Expression(result_->getType()), + bindings(std::move(bindings_)), + result(std::move(result_)) + {} + + static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); + + EvaluationResult evaluate(const EvaluationContext& params) const override; + void eachChild(const std::function&) const override; + + bool operator==(const Expression& e) const override { + if (auto rhs = dynamic_cast(&e)) { + return *result == *(rhs->result); + } + return false; + } + + Expression* getResult() const { + return result.get(); + } + +private: + Bindings bindings; + std::unique_ptr result; +}; + +class Var : public Expression { +public: + Var(std::string name_, std::shared_ptr value_) : + Expression(value_->getType()), + name(std::move(name_)), + value(value_) + {} + + static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); + + EvaluationResult evaluate(const EvaluationContext& params) const override; + void eachChild(const std::function&) const override; + + bool operator==(const Expression& e) const override { + if (auto rhs = dynamic_cast(&e)) { + return *value == *(rhs->value); + } + return false; + } + +private: + std::string name; + std::shared_ptr value; +}; + +} // namespace expression +} // namespace style +} // namespace mbgl -- cgit v1.2.1