diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-01-31 15:44:18 +0200 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-02 09:44:42 -0800 |
commit | 8a5bff8ee630673c6ebc496322eab94a41ae9353 (patch) | |
tree | 8bb6428cd9c3d591c237d77f94d4b0e56efb0ee0 /include/mbgl/style/conversion | |
parent | 141e995806576364d185626176c1b993fc519291 (diff) | |
download | qtlocation-mapboxgl-8a5bff8ee630673c6ebc496322eab94a41ae9353.tar.gz |
[core] default value support in categorical function conversion
Diffstat (limited to 'include/mbgl/style/conversion')
-rw-r--r-- | include/mbgl/style/conversion/function.hpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index 90b4b95063..7d69fa55c5 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -198,6 +198,21 @@ struct Converter<CameraFunction<T>> { } }; +template <class T, class V> +Result<optional<T>> convertDefaultValue(const V& value) { + auto defaultValueValue = objectMember(value, "defaultValue"); + if (!defaultValueValue) { + return {}; + } + + auto defaultValue = convert<T>(*defaultValueValue); + if (!defaultValue) { + return Error { "wrong type for \"default\": " + defaultValue.error().message }; + } + + return *defaultValue; +} + template <class T> struct Converter<SourceFunction<T>> { template <class V> @@ -221,7 +236,12 @@ struct Converter<SourceFunction<T>> { return stops.error(); } - return SourceFunction<T>(*propertyString, *stops); + auto defaultValue = convertDefaultValue<T>(value); + if (!defaultValue) { + return defaultValue.error(); + } + + return SourceFunction<T>(*propertyString, *stops, *defaultValue); } }; @@ -280,6 +300,11 @@ struct Converter<CompositeFunction<T>> { return Error { "function property must be a string" }; } + auto defaultValue = convertDefaultValue<T>(value); + if (!defaultValue) { + return defaultValue.error(); + } + std::string type = "exponential"; auto typeValue = objectMember(value, "type"); if (typeValue && toString(*typeValue)) { @@ -305,7 +330,7 @@ struct Converter<CompositeFunction<T>> { inner.stops.emplace(stop.first.second, stop.second); } - return CompositeFunction<T>(*propertyString, convertedStops); + return CompositeFunction<T>(*propertyString, convertedStops, *defaultValue); } else if (type == "interval") { auto stops = convertStops<CompositeValue<float>, T>(value); if (!stops) { @@ -318,7 +343,7 @@ struct Converter<CompositeFunction<T>> { inner.stops.emplace(stop.first.second, stop.second); } - return CompositeFunction<T>(*propertyString, convertedStops); + return CompositeFunction<T>(*propertyString, convertedStops, *defaultValue); } else if (type == "categorical") { auto stops = convertStops<CompositeValue<CategoricalValue>, T>(value); if (!stops) { @@ -331,7 +356,7 @@ struct Converter<CompositeFunction<T>> { inner.stops.emplace(stop.first.second, stop.second); } - return CompositeFunction<T>(*propertyString, convertedStops); + return CompositeFunction<T>(*propertyString, convertedStops, *defaultValue); } else { return Error { "unsupported function type" }; } |