diff options
Diffstat (limited to 'include/mbgl/style/expression')
-rw-r--r-- | include/mbgl/style/expression/length.hpp | 32 | ||||
-rw-r--r-- | include/mbgl/style/expression/let.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/style/expression/literal.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/style/expression/parsing_context.hpp | 34 |
4 files changed, 64 insertions, 9 deletions
diff --git a/include/mbgl/style/expression/length.hpp b/include/mbgl/style/expression/length.hpp new file mode 100644 index 0000000000..1d754f1932 --- /dev/null +++ b/include/mbgl/style/expression/length.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/expression/parsing_context.hpp> + +#include <memory> +#include <vector> + +namespace mbgl { +namespace style { +namespace expression { + +class Length : public Expression { +public: + Length(std::unique_ptr<Expression> input); + + static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); + + EvaluationResult evaluate(const EvaluationContext& params) const override; + void eachChild(const std::function<void(const Expression&)>& visit) const override; + bool operator==(const Expression& e) const override; + std::vector<optional<Value>> possibleOutputs() const override; + std::string getOperator() const override { return "length"; } + +private: + std::unique_ptr<Expression> input; +}; + +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/expression/let.hpp b/include/mbgl/style/expression/let.hpp index 75d2adda62..d0210d8bba 100644 --- a/include/mbgl/style/expression/let.hpp +++ b/include/mbgl/style/expression/let.hpp @@ -70,6 +70,9 @@ public: mbgl::Value serialize() const override; std::string getOperator() const override { return "var"; } + + const std::shared_ptr<Expression>& getBoundExpression() const { return value; } + private: std::string name; std::shared_ptr<Expression> value; diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp index d854b419f4..a00c468efc 100644 --- a/include/mbgl/style/expression/literal.hpp +++ b/include/mbgl/style/expression/literal.hpp @@ -40,6 +40,10 @@ public: std::vector<optional<Value>> possibleOutputs() const override { return {{ value }}; } + + Value getValue() const { + return value; + } mbgl::Value serialize() const override; std::string getOperator() const override { return "literal"; } diff --git a/include/mbgl/style/expression/parsing_context.hpp b/include/mbgl/style/expression/parsing_context.hpp index f92a4c95ea..c19974a4f7 100644 --- a/include/mbgl/style/expression/parsing_context.hpp +++ b/include/mbgl/style/expression/parsing_context.hpp @@ -55,7 +55,7 @@ class ParsingContext { public: ParsingContext() : errors(std::make_shared<std::vector<ParsingError>>()) {} ParsingContext(std::string key_) : key(std::move(key_)), errors(std::make_shared<std::vector<ParsingError>>()) {} - explicit ParsingContext(optional<type::Type> expected_) + explicit ParsingContext(type::Type expected_) : expected(std::move(expected_)), errors(std::make_shared<std::vector<ParsingError>>()) {} @@ -67,6 +67,7 @@ public: std::string getKey() const { return key; } optional<type::Type> getExpected() const { return expected; } const std::vector<ParsingError>& getErrors() const { return *errors; } + const std::string getCombinedErrors() const; enum TypeAnnotationOption { includeTypeAnnotations, @@ -74,16 +75,21 @@ public: }; /* - Parse the given style-spec JSON value into an Expression object. - Specifically, this function is responsible for determining the expression - type (either Literal, or the one named in value[0]) and dispatching to the - appropriate ParseXxxx::parse(const V&, ParsingContext) method. + Parse the given style-spec JSON value as an expression. */ - ParseResult parse(const mbgl::style::conversion::Convertible& value, - TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations); + ParseResult parseExpression(const mbgl::style::conversion::Convertible& value, + TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations); /* - Parse a child expression. + Parse the given style-spec JSON value as an expression intended to be used + in a layout or paint property. This entails checking additional constraints + that exist in that context but not, e.g., for filters. + */ + ParseResult parseLayerPropertyExpression(const mbgl::style::conversion::Convertible& value, + TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations); + + /* + Parse a child expression. For use by individual Expression::parse() methods. */ ParseResult parse(const mbgl::style::conversion::Convertible&, std::size_t, @@ -91,7 +97,7 @@ public: TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations); /* - Parse a child expression. + Parse a child expression. For use by individual Expression::parse() methods. */ ParseResult parse(const mbgl::style::conversion::Convertible&, std::size_t index, @@ -141,6 +147,16 @@ private: errors(std::move(errors_)) {} + + /* + Parse the given style-spec JSON value into an Expression object. + Specifically, this function is responsible for determining the expression + type (either Literal, or the one named in value[0]) and dispatching to the + appropriate ParseXxxx::parse(const V&, ParsingContext) method. + */ + ParseResult parse(const mbgl::style::conversion::Convertible& value, + TypeAnnotationOption typeAnnotationOption = includeTypeAnnotations); + std::string key; optional<type::Type> expected; std::shared_ptr<detail::Scope> scope; |