diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/style/expression/type.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/function/convert.hpp | 29 |
2 files changed, 35 insertions, 4 deletions
diff --git a/include/mbgl/style/expression/type.hpp b/include/mbgl/style/expression/type.hpp index 3ad2faa3c8..21b01234c6 100644 --- a/include/mbgl/style/expression/type.hpp +++ b/include/mbgl/style/expression/type.hpp @@ -50,6 +50,12 @@ struct ObjectType { bool operator==(const ObjectType&) const { return true; } }; +struct ErrorType { + constexpr ErrorType() {} + std::string getName() const { return "Error"; } + bool operator==(const ErrorType&) const { return true; } +}; + struct ValueType { constexpr ValueType() {} std::string getName() const { return "Value"; } @@ -63,6 +69,7 @@ constexpr BooleanType Boolean; constexpr ColorType Color; constexpr ValueType Value; constexpr ObjectType Object; +constexpr ErrorType Error; struct Array; @@ -74,7 +81,8 @@ using Type = variant< ColorType, ObjectType, ValueType, - mapbox::util::recursive_wrapper<Array>>; + mapbox::util::recursive_wrapper<Array>, + ErrorType>; struct Array { Array(Type itemType_) : itemType(itemType_) {} diff --git a/include/mbgl/style/function/convert.hpp b/include/mbgl/style/function/convert.hpp index ad42f3f9d2..edbd0c6fa0 100644 --- a/include/mbgl/style/function/convert.hpp +++ b/include/mbgl/style/function/convert.hpp @@ -23,6 +23,24 @@ namespace mbgl { namespace style { namespace expression { +namespace detail { + +class ErrorExpression : public Expression { +public: + ErrorExpression(std::string message_) : Expression(type::Error), message(std::move(message_)) {} + bool isFeatureConstant() const override { return true; } + bool isZoomConstant() const override { return true; } + + EvaluationResult evaluate(const EvaluationParameters&) const override { + return EvaluationError{message}; + } + +private: + std::string message; +}; + +} + // Create expressions representing 'classic' (i.e. stop-based) style functions struct Convert { @@ -53,6 +71,11 @@ struct Convert { std::vector<std::unique_ptr<Expression>>(), ctx))); } + + static std::unique_ptr<Expression> makeError(std::string message) { + return std::make_unique<detail::ErrorExpression>(message); + } + template <typename T> static ParseResult makeCoalesceToDefault(std::unique_ptr<Expression> main, optional<T> defaultValue) { @@ -150,7 +173,7 @@ struct Convert { return ParseResult(std::make_unique<Match<Key>>(valueTypeToExpressionType<T>(), std::move(input), std::move(cases), - makeLiteral(Null))); + makeError("No matching label"))); } template <typename T> @@ -159,10 +182,10 @@ struct Convert { // case expression std::vector<typename Case::Branch> cases; auto true_case = stops.stops.find(true) == stops.stops.end() ? - makeLiteral(Null) : + makeError("No matching label") : makeLiteral(stops.stops.at(true)); auto false_case = stops.stops.find(false) == stops.stops.end() ? - makeLiteral(Null) : + makeError("No matching label") : makeLiteral(stops.stops.at(false)); cases.push_back(std::make_pair(std::move(input), std::move(true_case))); return ParseResult(std::make_unique<Case>(valueTypeToExpressionType<T>(), std::move(cases), std::move(false_case))); |