diff options
Diffstat (limited to 'include/mbgl/style/data_driven_property_value.hpp')
-rw-r--r-- | include/mbgl/style/data_driven_property_value.hpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/include/mbgl/style/data_driven_property_value.hpp b/include/mbgl/style/data_driven_property_value.hpp new file mode 100644 index 0000000000..4653224f15 --- /dev/null +++ b/include/mbgl/style/data_driven_property_value.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include <mbgl/util/variant.hpp> +#include <mbgl/style/undefined.hpp> +#include <mbgl/style/function/camera_function.hpp> +#include <mbgl/style/function/source_function.hpp> +#include <mbgl/style/function/composite_function.hpp> + +namespace mbgl { +namespace style { + +template <class T> +class DataDrivenPropertyValue { +private: + using Value = variant< + Undefined, + T, + CameraFunction<T>, + SourceFunction<T>, + CompositeFunction<T>>; + + Value value; + + friend bool operator==(const DataDrivenPropertyValue& lhs, + const DataDrivenPropertyValue& rhs) { + return lhs.value == rhs.value; + } + +public: + DataDrivenPropertyValue() = default; + DataDrivenPropertyValue( T v) : value(std::move(v)) {} + DataDrivenPropertyValue( CameraFunction<T> v) : value(std::move(v)) {} + DataDrivenPropertyValue( SourceFunction<T> v) : value(std::move(v)) {} + DataDrivenPropertyValue(CompositeFunction<T> v) : value(std::move(v)) {} + + bool isUndefined() const { + return value.template is<Undefined>(); + } + + bool isDataDriven() const { + return value.template is<SourceFunction<T>>() || value.template is<CompositeFunction<T>>(); + } + + template <typename Evaluator> + auto evaluate(const Evaluator& evaluator) const { + return Value::visit(value, evaluator); + } +}; + +} // namespace style +} // namespace mbgl |