summaryrefslogtreecommitdiff
path: root/include/mbgl/style/property_value.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/style/property_value.hpp')
-rw-r--r--include/mbgl/style/property_value.hpp68
1 files changed, 52 insertions, 16 deletions
diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp
index 1b0f3d2ab0..86812e2301 100644
--- a/include/mbgl/style/property_value.hpp
+++ b/include/mbgl/style/property_value.hpp
@@ -10,44 +10,80 @@ namespace style {
template <class T>
class PropertyValue {
private:
- using Value = variant<Undefined, T, PropertyExpression<T>>;
+ using Value = variant<
+ Undefined,
+ T,
+ PropertyExpression<T>>;
+
Value value;
- friend bool operator==(const PropertyValue& lhs, const PropertyValue& rhs) {
+ friend bool operator==(const PropertyValue& lhs,
+ const PropertyValue& rhs) {
return lhs.value == rhs.value;
}
- friend bool operator!=(const PropertyValue& lhs, const PropertyValue& rhs) {
+ friend bool operator!=(const PropertyValue& lhs,
+ const PropertyValue& rhs) {
return !(lhs == rhs);
}
public:
- PropertyValue()
- : value() {}
+ PropertyValue() = default;
PropertyValue(T constant)
- : value(constant) {}
+ : value(std::move(constant)) {}
PropertyValue(PropertyExpression<T> expression)
- : value(expression) {
- assert(expression.isFeatureConstant());
+ : value(std::move(expression)) {}
+
+ bool isUndefined() const {
+ return value.template is<Undefined>();
+ }
+
+ bool isConstant() const {
+ return value.template is<T>();
+ }
+
+ bool isExpression() const {
+ return value.template is<PropertyExpression<T>>();
+ }
+
+ bool isDataDriven() const {
+ return value.match(
+ [] (const Undefined&) { return false; },
+ [] (const T&) { return false; },
+ [] (const PropertyExpression<T>& fn) { return !fn.isFeatureConstant(); }
+ );
+ }
+
+ bool isZoomConstant() const {
+ return value.match(
+ [] (const Undefined&) { return true; },
+ [] (const T&) { return true; },
+ [] (const PropertyExpression<T>& fn) { return fn.isZoomConstant(); }
+ );
}
- bool isUndefined() const { return value.which() == 0; }
- bool isConstant() const { return value.which() == 1; }
- bool isExpression() const { return value.which() == 2; }
- bool isDataDriven() const { return false; }
+ const T& asConstant() const {
+ return value.template get<T>();
+ }
- const T & asConstant() const { return value.template get< T >(); }
- const PropertyExpression<T>& asExpression() const { return value.template get<PropertyExpression<T>>(); }
+ const PropertyExpression<T>& asExpression() const {
+ return value.template get<PropertyExpression<T>>();
+ }
+
+ template <class... Ts>
+ auto match(Ts&&... ts) const {
+ return value.match(std::forward<Ts>(ts)...);
+ }
template <typename Evaluator>
auto evaluate(const Evaluator& evaluator, TimePoint = {}) const {
return Value::visit(value, evaluator);
}
- bool hasDataDrivenPropertyDifference(const PropertyValue<T>&) const {
- return false;
+ bool hasDataDrivenPropertyDifference(const PropertyValue<T>& other) const {
+ return *this != other && (isDataDriven() || other.isDataDriven());
}
};