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