summaryrefslogtreecommitdiff
path: root/src/mbgl/style/conversion/function.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/conversion/function.cpp')
-rw-r--r--src/mbgl/style/conversion/function.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp
index 1cc49e483a..6aadaad3b3 100644
--- a/src/mbgl/style/conversion/function.cpp
+++ b/src/mbgl/style/conversion/function.cpp
@@ -1,4 +1,6 @@
#include <mbgl/style/conversion/function.hpp>
+#include <mbgl/style/conversion/position.hpp>
+#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/style/expression/dsl.hpp>
#include <mbgl/style/expression/step.hpp>
#include <mbgl/style/expression/interpolate.hpp>
@@ -70,6 +72,72 @@ std::unique_ptr<Expression> convertTokenStringToExpression(const std::string& so
}
}
+template <class T>
+optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens) {
+ auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error, convertTokens);
+ if (!expression) {
+ return nullopt;
+ }
+
+ optional<T> defaultValue;
+
+ auto defaultValueValue = objectMember(value, "default");
+ if (defaultValueValue) {
+ defaultValue = convert<T>(*defaultValueValue, error);
+ if (!defaultValue) {
+ error.message = R"(wrong type for "default": )" + error.message;
+ return nullopt;
+ }
+ }
+
+ return PropertyExpression<T>(std::move(*expression), defaultValue);
+}
+
+template optional<PropertyExpression<AlignmentType>>
+ convertFunctionToExpression<AlignmentType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<bool>>
+ convertFunctionToExpression<bool>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<CirclePitchScaleType>>
+ convertFunctionToExpression<CirclePitchScaleType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<float>>
+ convertFunctionToExpression<float>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<HillshadeIlluminationAnchorType>>
+ convertFunctionToExpression<HillshadeIlluminationAnchorType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<IconTextFitType>>
+ convertFunctionToExpression<IconTextFitType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<LightAnchorType>>
+ convertFunctionToExpression<LightAnchorType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<LineCapType>>
+ convertFunctionToExpression<LineCapType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<LineJoinType>>
+ convertFunctionToExpression<LineJoinType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<Color>>
+ convertFunctionToExpression<Color>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<Position>>
+ convertFunctionToExpression<Position>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<RasterResamplingType>>
+ convertFunctionToExpression<RasterResamplingType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<std::array<float, 2>>>
+ convertFunctionToExpression<std::array<float, 2>>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<std::array<float, 4>>>
+ convertFunctionToExpression<std::array<float, 4>>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<std::string>>
+ convertFunctionToExpression<std::string>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<std::vector<float>>>
+ convertFunctionToExpression<std::vector<float>>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<std::vector<std::string>>>
+ convertFunctionToExpression<std::vector<std::string>>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<SymbolAnchorType>>
+ convertFunctionToExpression<SymbolAnchorType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<SymbolPlacementType>>
+ convertFunctionToExpression<SymbolPlacementType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<TextJustifyType>>
+ convertFunctionToExpression<TextJustifyType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<TextTransformType>>
+ convertFunctionToExpression<TextTransformType>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<TranslateAnchorType>>
+ convertFunctionToExpression<TranslateAnchorType>(const Convertible&, Error&, bool);
+
// Ad-hoc Converters for double and int64_t. We should replace float with double wholesale,
// and promote the int64_t Converter to general use (and it should check that the input is
// an integer).