diff options
Diffstat (limited to 'include/mbgl/style/conversion')
4 files changed, 27 insertions, 9 deletions
diff --git a/include/mbgl/style/conversion/color_ramp_property_value.hpp b/include/mbgl/style/conversion/color_ramp_property_value.hpp index 9394daa050..290ee6a56c 100644 --- a/include/mbgl/style/conversion/color_ramp_property_value.hpp +++ b/include/mbgl/style/conversion/color_ramp_property_value.hpp @@ -14,7 +14,7 @@ namespace conversion { template <> struct Converter<ColorRampPropertyValue> { - optional<ColorRampPropertyValue> operator()(const Convertible& value, Error& error) const { + optional<ColorRampPropertyValue> operator()(const Convertible& value, Error& error, bool /* convertTokens */ = false) const { using namespace mbgl::style::expression; if (isUndefined(value)) { return ColorRampPropertyValue(); diff --git a/include/mbgl/style/conversion/data_driven_property_value.hpp b/include/mbgl/style/conversion/data_driven_property_value.hpp index 363134bd3e..f1bd1bdbb7 100644 --- a/include/mbgl/style/conversion/data_driven_property_value.hpp +++ b/include/mbgl/style/conversion/data_driven_property_value.hpp @@ -16,7 +16,7 @@ namespace conversion { template <class T> struct Converter<DataDrivenPropertyValue<T>> { - optional<DataDrivenPropertyValue<T>> operator()(const Convertible& value, Error& error) const { + optional<DataDrivenPropertyValue<T>> operator()(const Convertible& value, Error& error, bool convertTokens) const { using namespace mbgl::style::expression; if (isUndefined(value)) { @@ -34,13 +34,13 @@ struct Converter<DataDrivenPropertyValue<T>> { } expression = PropertyExpression<T>(std::move(*parsed)); } else if (isObject(value)) { - expression = convertFunctionToExpression<T>(value, error); + expression = convertFunctionToExpression<T>(value, error, convertTokens); } else { optional<T> constant = convert<T>(value, error); if (!constant) { return {}; } - return DataDrivenPropertyValue<T>(*constant); + return convertTokens ? maybeConvertTokens(*constant) : DataDrivenPropertyValue<T>(*constant); } if (!expression) { @@ -56,6 +56,17 @@ struct Converter<DataDrivenPropertyValue<T>> { return DataDrivenPropertyValue<T>(*constant); } } + + template <class S> + DataDrivenPropertyValue<T> maybeConvertTokens(const S& t) const { + return DataDrivenPropertyValue<T>(t); + }; + + DataDrivenPropertyValue<T> maybeConvertTokens(const std::string& t) const { + return hasTokens(t) + ? DataDrivenPropertyValue<T>(PropertyExpression<T>(convertTokenStringToExpression(t))) + : DataDrivenPropertyValue<T>(t); + } }; } // namespace conversion diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index 6bc75d7141..8799e9faa4 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -10,11 +10,14 @@ namespace mbgl { namespace style { namespace conversion { -optional<std::unique_ptr<expression::Expression>> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&); +bool hasTokens(const std::string&); +std::unique_ptr<expression::Expression> convertTokenStringToExpression(const std::string&); + +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) { - auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error); +optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens) { + auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error, convertTokens); if (!expression) { return {}; } diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp index 2256cfffb4..db23074c5e 100644 --- a/include/mbgl/style/conversion/property_value.hpp +++ b/include/mbgl/style/conversion/property_value.hpp @@ -16,9 +16,13 @@ namespace conversion { template <class T> struct Converter<PropertyValue<T>> { - optional<PropertyValue<T>> operator()(const Convertible& value, Error& error) const { + optional<PropertyValue<T>> operator()(const Convertible& value, Error& error, bool convertTokens = false) const { using namespace mbgl::style::expression; + // Only icon-image and text-field support tokens, and they are both data-driven. + assert(!convertTokens); + (void)convertTokens; + if (isUndefined(value)) { return PropertyValue<T>(); } @@ -34,7 +38,7 @@ struct Converter<PropertyValue<T>> { } expression = PropertyExpression<T>(std::move(*parsed)); } else if (isObject(value)) { - expression = convertFunctionToExpression<T>(value, error); + expression = convertFunctionToExpression<T>(value, error, false); } else { optional<T> constant = convert<T>(value, error); if (!constant) { |