diff options
Diffstat (limited to 'include/mbgl/style/conversion/property_setter.hpp')
-rw-r--r-- | include/mbgl/style/conversion/property_setter.hpp | 79 |
1 files changed, 45 insertions, 34 deletions
diff --git a/include/mbgl/style/conversion/property_setter.hpp b/include/mbgl/style/conversion/property_setter.hpp index 6a15c64026..51ec4778d9 100644 --- a/include/mbgl/style/conversion/property_setter.hpp +++ b/include/mbgl/style/conversion/property_setter.hpp @@ -7,7 +7,6 @@ #include <mbgl/style/conversion/data_driven_property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> -#include <functional> #include <string> namespace mbgl { @@ -15,45 +14,57 @@ namespace style { namespace conversion { template <class V> -using LayoutPropertySetter = std::function<optional<Error> (Layer&, const V&)>; +using LayoutPropertySetter = optional<Error> (*) (Layer&, const V&); template <class V> -using PaintPropertySetter = std::function<optional<Error> (Layer&, const V&, const optional<std::string>&)>; - -template <class V, class L, class PropertyValue, class...Args> -auto makePropertySetter(void (L::*setter)(PropertyValue, const Args&...args)) { - return [setter] (Layer& layer, const V& value, const Args&...args) -> optional<Error> { - L* typedLayer = layer.as<L>(); - if (!typedLayer) { - return Error { "layer doesn't support this property" }; - } - - Result<PropertyValue> typedValue = convert<PropertyValue>(value); - if (!typedValue) { - return typedValue.error(); - } - - (typedLayer->*setter)(*typedValue, args...); - return {}; - }; +using PaintPropertySetter = optional<Error> (*) (Layer&, const V&, const optional<std::string>&); + +template <class V, class L, class PropertyValue, void (L::*setter)(PropertyValue)> +optional<Error> setLayoutProperty(Layer& layer, const V& value) { + L* typedLayer = layer.as<L>(); + if (!typedLayer) { + return Error { "layer doesn't support this property" }; + } + + Result<PropertyValue> typedValue = convert<PropertyValue>(value); + if (!typedValue) { + return typedValue.error(); + } + + (typedLayer->*setter)(*typedValue); + return {}; +} + +template <class V, class L, class PropertyValue, void (L::*setter)(PropertyValue, const optional<std::string>&)> +optional<Error> setPaintProperty(Layer& layer, const V& value, const optional<std::string>& klass) { + L* typedLayer = layer.as<L>(); + if (!typedLayer) { + return Error { "layer doesn't support this property" }; + } + + Result<PropertyValue> typedValue = convert<PropertyValue>(value); + if (!typedValue) { + return typedValue.error(); + } + + (typedLayer->*setter)(*typedValue, klass); + return {}; } -template <class V, class L, class...Args> -auto makeTransitionSetter(void (L::*setter)(const TransitionOptions&, const Args&...args)) { - return [setter] (Layer& layer, const V& value, const Args&...args) -> optional<Error> { - L* typedLayer = layer.as<L>(); - if (!typedLayer) { - return Error { "layer doesn't support this property" }; - } +template <class V, class L, void (L::*setter)(const TransitionOptions&, const optional<std::string>&)> +optional<Error> setTransition(Layer& layer, const V& value, const optional<std::string>& klass) { + L* typedLayer = layer.as<L>(); + if (!typedLayer) { + return Error { "layer doesn't support this property" }; + } - Result<TransitionOptions> transition = convert<TransitionOptions>(value); - if (!transition) { - return transition.error(); - } + Result<TransitionOptions> transition = convert<TransitionOptions>(value); + if (!transition) { + return transition.error(); + } - (typedLayer->*setter)(*transition, args...); - return {}; - }; + (typedLayer->*setter)(*transition, klass); + return {}; } template <class V> |