summaryrefslogtreecommitdiff
path: root/include/mbgl/style/conversion
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/style/conversion')
-rw-r--r--include/mbgl/style/conversion/color_ramp_property_value.hpp2
-rw-r--r--include/mbgl/style/conversion/data_driven_property_value.hpp64
-rw-r--r--include/mbgl/style/conversion/function.hpp66
-rw-r--r--include/mbgl/style/conversion/property_value.hpp49
4 files changed, 60 insertions, 121 deletions
diff --git a/include/mbgl/style/conversion/color_ramp_property_value.hpp b/include/mbgl/style/conversion/color_ramp_property_value.hpp
index cf5d5e55d9..9394daa050 100644
--- a/include/mbgl/style/conversion/color_ramp_property_value.hpp
+++ b/include/mbgl/style/conversion/color_ramp_property_value.hpp
@@ -3,11 +3,9 @@
#include <mbgl/style/color_ramp_property_value.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/constant.hpp>
-#include <mbgl/style/conversion/function.hpp>
#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/expression/is_constant.hpp>
#include <mbgl/style/expression/is_expression.hpp>
-#include <mbgl/style/expression/find_zoom_curve.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
namespace mbgl {
diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp
index 07ed201c99..363134bd3e 100644
--- a/include/mbgl/style/conversion/data_driven_property_value.hpp
+++ b/include/mbgl/style/conversion/data_driven_property_value.hpp
@@ -6,74 +6,54 @@
#include <mbgl/style/conversion/function.hpp>
#include <mbgl/style/expression/is_expression.hpp>
#include <mbgl/style/expression/is_constant.hpp>
-#include <mbgl/style/expression/find_zoom_curve.hpp>
#include <mbgl/style/expression/literal.hpp>
#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
-#include <unordered_set>
-
-
namespace mbgl {
namespace style {
namespace conversion {
template <class T>
struct Converter<DataDrivenPropertyValue<T>> {
-
optional<DataDrivenPropertyValue<T>> operator()(const Convertible& value, Error& error) const {
using namespace mbgl::style::expression;
-
+
if (isUndefined(value)) {
return DataDrivenPropertyValue<T>();
- } else if (isExpression(value)) {
+ }
+
+ optional<PropertyExpression<T>> expression;
+
+ if (isExpression(value)) {
ParsingContext ctx(valueTypeToExpressionType<T>());
- ParseResult expression = ctx.parseLayerPropertyExpression(value);
- if (!expression) {
+ ParseResult parsed = ctx.parseLayerPropertyExpression(value);
+ if (!parsed) {
error = { ctx.getCombinedErrors() };
return {};
}
-
- bool featureConstant = isFeatureConstant(**expression);
- bool zoomConstant = isZoomConstant(**expression);
-
- if (featureConstant && !zoomConstant) {
- return DataDrivenPropertyValue<T>(CameraFunction<T>(std::move(*expression)));
- } else if (!featureConstant && zoomConstant) {
- return DataDrivenPropertyValue<T>(SourceFunction<T>(std::move(*expression)));
- } else if (!featureConstant && !zoomConstant) {
- return DataDrivenPropertyValue<T>(CompositeFunction<T>(std::move(*expression)));
- } else {
- auto literal = dynamic_cast<Literal*>(expression->get());
- assert(literal);
- optional<T> constant = fromExpressionValue<T>(literal->getValue());
- if (!constant) {
- return {};
- }
- return DataDrivenPropertyValue<T>(*constant);
- }
- } else if (!isObject(value)) {
+ expression = PropertyExpression<T>(std::move(*parsed));
+ } else if (isObject(value)) {
+ expression = convertFunctionToExpression<T>(value, error);
+ } else {
optional<T> constant = convert<T>(value, error);
if (!constant) {
return {};
}
return DataDrivenPropertyValue<T>(*constant);
- } else if (!objectMember(value, "property")) {
- optional<CameraFunction<T>> function = convert<CameraFunction<T>>(value, error);
- if (!function) {
- return {};
- }
- return DataDrivenPropertyValue<T>(*function);
+ }
+
+ if (!expression) {
+ return {};
+ } else if (!(*expression).isFeatureConstant() || !(*expression).isZoomConstant()) {
+ return { std::move(*expression) };
} else {
- optional<CompositeFunction<T>> composite = convert<CompositeFunction<T>>(value, error);
- if (composite) {
- return DataDrivenPropertyValue<T>(*composite);
- }
- optional<SourceFunction<T>> source = convert<SourceFunction<T>>(value, error);
- if (!source) {
+ optional<T> constant = fromExpressionValue<T>(
+ dynamic_cast<const Literal&>((*expression).getExpression()).getValue());
+ if (!constant) {
return {};
}
- return DataDrivenPropertyValue<T>(*source);
+ return DataDrivenPropertyValue<T>(*constant);
}
}
};
diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp
index 5ddede324b..6bc75d7141 100644
--- a/include/mbgl/style/conversion/function.hpp
+++ b/include/mbgl/style/conversion/function.hpp
@@ -1,8 +1,6 @@
#pragma once
-#include <mbgl/style/function/camera_function.hpp>
-#include <mbgl/style/function/source_function.hpp>
-#include <mbgl/style/function/composite_function.hpp>
+#include <mbgl/style/property_expression.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/expression/expression.hpp>
@@ -12,66 +10,28 @@ namespace mbgl {
namespace style {
namespace conversion {
-template <class T>
-optional<optional<T>> convertDefaultValue(const Convertible& value, Error& error) {
- auto defaultValueValue = objectMember(value, "default");
- if (!defaultValueValue) {
- return optional<T>();
- }
+optional<std::unique_ptr<expression::Expression>> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&);
- auto defaultValue = convert<T>(*defaultValueValue, error);
- if (!defaultValue) {
- error = { R"(wrong type for "default": )" + error.message };
+template <class T>
+optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error) {
+ auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error);
+ if (!expression) {
return {};
}
- return { *defaultValue };
-}
-
-optional<std::unique_ptr<expression::Expression>> convertCameraFunctionToExpression(expression::type::Type, const Convertible&, Error&);
-optional<std::unique_ptr<expression::Expression>> convertSourceFunctionToExpression(expression::type::Type, const Convertible&, Error&);
-optional<std::unique_ptr<expression::Expression>> convertCompositeFunctionToExpression(expression::type::Type, const Convertible&, Error&);
+ optional<T> defaultValue;
-template <class T>
-struct Converter<CameraFunction<T>> {
- optional<CameraFunction<T>> operator()(const Convertible& value, Error& error) const {
- auto expression = convertCameraFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error);
- if (!expression) {
- return {};
- }
- return CameraFunction<T>(std::move(*expression), false);
- }
-};
-
-template <class T>
-struct Converter<SourceFunction<T>> {
- optional<SourceFunction<T>> operator()(const Convertible& value, Error& error) const {
- auto expression = convertSourceFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error);
- if (!expression) {
- return {};
- }
- auto defaultValue = convertDefaultValue<T>(value, error);
+ auto defaultValueValue = objectMember(value, "default");
+ if (defaultValueValue) {
+ defaultValue = convert<T>(*defaultValueValue, error);
if (!defaultValue) {
+ error = { R"(wrong type for "default": )" + error.message };
return {};
}
- return SourceFunction<T>(std::move(*expression), *defaultValue);
}
-};
-template <class T>
-struct Converter<CompositeFunction<T>> {
- optional<CompositeFunction<T>> operator()(const Convertible& value, Error& error) const {
- auto expression = convertCompositeFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error);
- if (!expression) {
- return {};
- }
- auto defaultValue = convertDefaultValue<T>(value, error);
- if (!defaultValue) {
- return {};
- }
- return CompositeFunction<T>(std::move(*expression), *defaultValue);
- }
-};
+ return PropertyExpression<T>(std::move(*expression), defaultValue);
+}
} // namespace conversion
} // namespace style
diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp
index e52c63d023..2256cfffb4 100644
--- a/include/mbgl/style/conversion/property_value.hpp
+++ b/include/mbgl/style/conversion/property_value.hpp
@@ -7,7 +7,6 @@
#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/expression/is_constant.hpp>
#include <mbgl/style/expression/is_expression.hpp>
-#include <mbgl/style/expression/find_zoom_curve.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
#include <mbgl/style/expression/literal.hpp>
@@ -22,34 +21,20 @@ struct Converter<PropertyValue<T>> {
if (isUndefined(value)) {
return PropertyValue<T>();
- } else if (isExpression(value)) {
+ }
+
+ optional<PropertyExpression<T>> expression;
+
+ if (isExpression(value)) {
ParsingContext ctx(valueTypeToExpressionType<T>());
- ParseResult expression = ctx.parseLayerPropertyExpression(value);
- if (!expression) {
+ ParseResult parsed = ctx.parseLayerPropertyExpression(value);
+ if (!parsed) {
error = { ctx.getCombinedErrors() };
return {};
}
-
- if (!isFeatureConstant(**expression)) {
- error = { "property expressions not supported" };
- return {};
- } else if (!isZoomConstant(**expression)) {
- return { CameraFunction<T>(std::move(*expression)) };
- } else {
- auto literal = dynamic_cast<Literal*>(expression->get());
- assert(literal);
- optional<T> constant = fromExpressionValue<T>(literal->getValue());
- if (!constant) {
- return {};
- }
- return PropertyValue<T>(*constant);
- }
+ expression = PropertyExpression<T>(std::move(*parsed));
} else if (isObject(value)) {
- optional<CameraFunction<T>> function = convert<CameraFunction<T>>(value, error);
- if (!function) {
- return {};
- }
- return { *function };
+ expression = convertFunctionToExpression<T>(value, error);
} else {
optional<T> constant = convert<T>(value, error);
if (!constant) {
@@ -57,6 +42,22 @@ struct Converter<PropertyValue<T>> {
}
return { *constant };
}
+
+ if (!expression) {
+ return {};
+ } else if (!(*expression).isFeatureConstant()) {
+ error = { "data expressions not supported" };
+ return {};
+ } else if (!(*expression).isZoomConstant()) {
+ return { std::move(*expression) };
+ } else {
+ optional<T> constant = fromExpressionValue<T>(
+ dynamic_cast<const Literal&>((*expression).getExpression()).getValue());
+ if (!constant) {
+ return {};
+ }
+ return PropertyValue<T>(*constant);
+ }
}
};