1 | #pragma once |
2 | |
3 | #include <mbgl/style/property_expression.hpp> |
4 | #include <mbgl/style/conversion.hpp> |
5 | #include <mbgl/style/conversion/constant.hpp> |
6 | #include <mbgl/style/expression/expression.hpp> |
7 | #include <mbgl/style/expression/value.hpp> |
8 | |
9 | namespace mbgl { |
10 | namespace style { |
11 | namespace conversion { |
12 | |
13 | bool hasTokens(const std::string&); |
14 | std::unique_ptr<expression::Expression> convertTokenStringToExpression(const std::string&); |
15 | |
16 | optional<std::unique_ptr<expression::Expression>> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&, bool convertTokens); |
17 | |
18 | template <class T> |
19 | optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens) { |
20 | auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error, convertTokens); |
21 | if (!expression) { |
22 | return {}; |
23 | } |
24 | |
25 | optional<T> defaultValue; |
26 | |
27 | auto defaultValueValue = objectMember(v: value, name: "default" ); |
28 | if (defaultValueValue) { |
29 | defaultValue = convert<T>(*defaultValueValue, error); |
30 | if (!defaultValue) { |
31 | error = { .message: R"(wrong type for "default": )" + error.message }; |
32 | return {}; |
33 | } |
34 | } |
35 | |
36 | return PropertyExpression<T>(std::move(*expression), defaultValue); |
37 | } |
38 | |
39 | } // namespace conversion |
40 | } // namespace style |
41 | } // namespace mbgl |
42 | |