diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-28 16:39:50 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-02 09:44:42 -0800 |
commit | 141e995806576364d185626176c1b993fc519291 (patch) | |
tree | ecdc41fc7699f2a1a9e9456157348451ebe99597 /include/mbgl/style/data_driven_property_value.hpp | |
parent | 6a6bddb4537004cc1bfc506e76772de74d33f3f7 (diff) | |
download | qtlocation-mapboxgl-141e995806576364d185626176c1b993fc519291.tar.gz |
[core] Add support for data-driven styling
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 |