MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
property_value.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mbgl/util/variant.hpp>
6 
7 namespace mbgl {
8 namespace style {
9 
10 template <class T>
12 private:
13  using Value = variant<
14  Undefined,
15  T,
17 
18  Value value;
19 
20  friend bool operator==(const PropertyValue& lhs,
21  const PropertyValue& rhs) {
22  return lhs.value == rhs.value;
23  }
24 
25  friend bool operator!=(const PropertyValue& lhs,
26  const PropertyValue& rhs) {
27  return !(lhs == rhs);
28  }
29 
30 public:
31  PropertyValue() = default;
32 
33  PropertyValue(T constant)
34  : value(std::move(constant)) {}
35 
37  : value(std::move(expression)) {}
38 
39  bool isUndefined() const {
40  return value.template is<Undefined>();
41  }
42 
43  bool isConstant() const {
44  return value.template is<T>();
45  }
46 
47  bool isExpression() const {
48  return value.template is<PropertyExpression<T>>();
49  }
50 
51  bool isDataDriven() const {
52  return value.match(
53  [] (const Undefined&) { return false; },
54  [] (const T&) { return false; },
55  [] (const PropertyExpression<T>& fn) { return !fn.isFeatureConstant(); }
56  );
57  }
58 
59  bool isZoomConstant() const {
60  return value.match(
61  [] (const Undefined&) { return true; },
62  [] (const T&) { return true; },
63  [] (const PropertyExpression<T>& fn) { return fn.isZoomConstant(); }
64  );
65  }
66 
67  const T& asConstant() const {
68  return value.template get<T>();
69  }
70 
72  return value.template get<PropertyExpression<T>>();
73  }
74 
75  template <class... Ts>
76  auto match(Ts&&... ts) const {
77  return value.match(std::forward<Ts>(ts)...);
78  }
79 
80  template <typename Evaluator>
81  auto evaluate(const Evaluator& evaluator, TimePoint = {}) const {
82  return Value::visit(value, evaluator);
83  }
84 
86  return *this != other && (isDataDriven() || other.isDataDriven());
87  }
88 };
89 
90 } // namespace style
91 } // namespace mbgl
const T & asConstant() const
auto match(Ts &&... ts) const
friend bool operator==(const PropertyValue &lhs, const PropertyValue &rhs)
bool hasDataDrivenPropertyDifference(const PropertyValue< T > &other) const
PropertyValue(PropertyExpression< T > expression)
friend bool operator!=(const PropertyValue &lhs, const PropertyValue &rhs)
const PropertyExpression< T > & asExpression() const
auto evaluate(const Evaluator &evaluator, TimePoint={}) const
Definition: actor.hpp:15
Clock::time_point TimePoint
Definition: chrono.hpp:17
mapbox::util::variant< T... > variant
Definition: variant.hpp:17
Definition: tile_id.hpp:256