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/constant.hpp35
-rw-r--r--include/mbgl/style/conversion/coordinate.hpp1
-rw-r--r--include/mbgl/style/conversion/custom_geometry_source_options.hpp1
-rw-r--r--include/mbgl/style/conversion/filter.hpp1
-rw-r--r--include/mbgl/style/conversion/function.hpp22
-rw-r--r--include/mbgl/style/conversion/geojson.hpp3
-rw-r--r--include/mbgl/style/conversion/geojson_options.hpp3
-rw-r--r--include/mbgl/style/conversion/layer.hpp1
-rw-r--r--include/mbgl/style/conversion/light.hpp1
-rw-r--r--include/mbgl/style/conversion/position.hpp3
-rw-r--r--include/mbgl/style/conversion/property_value.hpp50
-rw-r--r--include/mbgl/style/conversion/source.hpp3
-rw-r--r--include/mbgl/style/conversion/tileset.hpp1
-rw-r--r--include/mbgl/style/conversion/transition_options.hpp1
14 files changed, 22 insertions, 104 deletions
diff --git a/include/mbgl/style/conversion/constant.hpp b/include/mbgl/style/conversion/constant.hpp
index 7d74ec42ce..40657528c4 100644
--- a/include/mbgl/style/conversion/constant.hpp
+++ b/include/mbgl/style/conversion/constant.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/types.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/string.hpp>
@@ -30,21 +31,7 @@ struct Converter<std::string> {
template <class T>
struct Converter<T, typename std::enable_if_t<std::is_enum<T>::value>> {
- optional<T> operator()(const Convertible& value, Error& error) const {
- optional<std::string> string = toString(value);
- if (!string) {
- error.message = "value must be a string";
- return nullopt;
- }
-
- const auto result = Enum<T>::toEnum(*string);
- if (!result) {
- error.message = "value must be a valid enumeration value";
- return nullopt;
- }
-
- return *result;
- }
+ optional<T> operator()(const Convertible& value, Error& error) const;
};
template <>
@@ -54,23 +41,7 @@ struct Converter<Color> {
template <size_t N>
struct Converter<std::array<float, N>> {
- optional<std::array<float, N>> operator()(const Convertible& value, Error& error) const {
- if (!isArray(value) || arrayLength(value) != N) {
- error.message = "value must be an array of " + util::toString(N) + " numbers";
- return nullopt;
- }
-
- std::array<float, N> result;
- for (size_t i = 0; i < N; i++) {
- optional<float> n = toNumber(arrayMember(value, i));
- if (!n) {
- error.message = "value must be an array of " + util::toString(N) + " numbers";
- return nullopt;
- }
- result[i] = *n;
- }
- return result;
- }
+ optional<std::array<float, N>> operator()(const Convertible& value, Error& error) const;
};
template <>
diff --git a/include/mbgl/style/conversion/coordinate.hpp b/include/mbgl/style/conversion/coordinate.hpp
index e11db5e32f..1346ed738a 100644
--- a/include/mbgl/style/conversion/coordinate.hpp
+++ b/include/mbgl/style/conversion/coordinate.hpp
@@ -2,6 +2,7 @@
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/geo.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
diff --git a/include/mbgl/style/conversion/custom_geometry_source_options.hpp b/include/mbgl/style/conversion/custom_geometry_source_options.hpp
index f0f505e54f..090e5b6239 100644
--- a/include/mbgl/style/conversion/custom_geometry_source_options.hpp
+++ b/include/mbgl/style/conversion/custom_geometry_source_options.hpp
@@ -2,6 +2,7 @@
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/sources/custom_geometry_source.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
diff --git a/include/mbgl/style/conversion/filter.hpp b/include/mbgl/style/conversion/filter.hpp
index 9daf6ea7a4..2d7ad0afc7 100644
--- a/include/mbgl/style/conversion/filter.hpp
+++ b/include/mbgl/style/conversion/filter.hpp
@@ -2,6 +2,7 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp
index 49825a3410..ba9acd7a3b 100644
--- a/include/mbgl/style/conversion/function.hpp
+++ b/include/mbgl/style/conversion/function.hpp
@@ -1,8 +1,8 @@
#pragma once
#include <mbgl/style/property_expression.hpp>
-#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/constant.hpp>
+#include <mbgl/style/conversion.hpp>
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/expression/value.hpp>
@@ -16,25 +16,7 @@ std::unique_ptr<expression::Expression> convertTokenStringToExpression(const std
optional<std::unique_ptr<expression::Expression>> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&, bool convertTokens);
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);
-}
+optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens);
} // namespace conversion
} // namespace style
diff --git a/include/mbgl/style/conversion/geojson.hpp b/include/mbgl/style/conversion/geojson.hpp
index 403c5f953b..90c1d64197 100644
--- a/include/mbgl/style/conversion/geojson.hpp
+++ b/include/mbgl/style/conversion/geojson.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include <mbgl/style/conversion.hpp>
#include <mbgl/util/geojson.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
diff --git a/include/mbgl/style/conversion/geojson_options.hpp b/include/mbgl/style/conversion/geojson_options.hpp
index 3f625babb6..89511848dd 100644
--- a/include/mbgl/style/conversion/geojson_options.hpp
+++ b/include/mbgl/style/conversion/geojson_options.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include <mbgl/style/conversion.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
diff --git a/include/mbgl/style/conversion/layer.hpp b/include/mbgl/style/conversion/layer.hpp
index 2df6c9e381..9cf019378b 100644
--- a/include/mbgl/style/conversion/layer.hpp
+++ b/include/mbgl/style/conversion/layer.hpp
@@ -2,6 +2,7 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
#include <memory>
diff --git a/include/mbgl/style/conversion/light.hpp b/include/mbgl/style/conversion/light.hpp
index 289fca2e31..2f6f8628b8 100644
--- a/include/mbgl/style/conversion/light.hpp
+++ b/include/mbgl/style/conversion/light.hpp
@@ -2,6 +2,7 @@
#include <mbgl/style/light.hpp>
#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
diff --git a/include/mbgl/style/conversion/position.hpp b/include/mbgl/style/conversion/position.hpp
index 044c45862d..10db5c6ec1 100644
--- a/include/mbgl/style/conversion/position.hpp
+++ b/include/mbgl/style/conversion/position.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include <mbgl/style/conversion.hpp>
#include <mbgl/style/position.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp
index fa6752867b..f6f36db983 100644
--- a/include/mbgl/style/conversion/property_value.hpp
+++ b/include/mbgl/style/conversion/property_value.hpp
@@ -1,9 +1,9 @@
#pragma once
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion/function.hpp>
+#include <mbgl/style/conversion.hpp>
#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/expression/is_constant.hpp>
#include <mbgl/style/expression/is_expression.hpp>
@@ -16,53 +16,7 @@ namespace conversion {
template <class T>
struct Converter<PropertyValue<T>> {
- optional<PropertyValue<T>> operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const {
- using namespace mbgl::style::expression;
-
- if (isUndefined(value)) {
- return PropertyValue<T>();
- }
-
- optional<PropertyExpression<T>> expression;
-
- if (isExpression(value)) {
- ParsingContext ctx(valueTypeToExpressionType<T>());
- ParseResult parsed = ctx.parseLayerPropertyExpression(value);
- if (!parsed) {
- error.message = ctx.getCombinedErrors();
- return nullopt;
- }
- expression = PropertyExpression<T>(std::move(*parsed));
- } else if (isObject(value)) {
- expression = convertFunctionToExpression<T>(value, error, convertTokens);
- } else {
- optional<T> constant = convert<T>(value, error);
- if (!constant) {
- return nullopt;
- }
- return convertTokens ? maybeConvertTokens(*constant) : PropertyValue<T>(*constant);
- }
-
- if (!expression) {
- return nullopt;
- } else if (!allowDataExpressions && !(*expression).isFeatureConstant()) {
- error.message = "data expressions not supported";
- return nullopt;
- } else if (!(*expression).isFeatureConstant() || !(*expression).isZoomConstant()) {
- return { std::move(*expression) };
- } else if ((*expression).getExpression().getKind() == Kind::Literal) {
- optional<T> constant = fromExpressionValue<T>(
- static_cast<const Literal&>((*expression).getExpression()).getValue());
- if (!constant) {
- return nullopt;
- }
- return PropertyValue<T>(*constant);
- } else {
- assert(false);
- error.message = "expected a literal expression";
- return nullopt;
- }
- }
+ optional<PropertyValue<T>> operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const;
template <class S>
PropertyValue<T> maybeConvertTokens(const S& t) const {
diff --git a/include/mbgl/style/conversion/source.hpp b/include/mbgl/style/conversion/source.hpp
index 2cf2e36da4..19bc1ce6b6 100644
--- a/include/mbgl/style/conversion/source.hpp
+++ b/include/mbgl/style/conversion/source.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include <mbgl/style/conversion.hpp>
#include <mbgl/style/source.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
#include <memory>
diff --git a/include/mbgl/style/conversion/tileset.hpp b/include/mbgl/style/conversion/tileset.hpp
index 1fb4acf70d..88661c358c 100644
--- a/include/mbgl/style/conversion/tileset.hpp
+++ b/include/mbgl/style/conversion/tileset.hpp
@@ -2,6 +2,7 @@
#include <mbgl/util/tileset.hpp>
#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
diff --git a/include/mbgl/style/conversion/transition_options.hpp b/include/mbgl/style/conversion/transition_options.hpp
index 0563f39ac3..a72d757d3c 100644
--- a/include/mbgl/style/conversion/transition_options.hpp
+++ b/include/mbgl/style/conversion/transition_options.hpp
@@ -2,6 +2,7 @@
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {