summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layout_property.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-04-25 13:59:09 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-02 14:51:39 -0700
commitcadc617c762d453cca2c9bac41f9c1db984c5fac (patch)
tree5a15363a54ef81b0106693dd83c70bfdf7761393 /src/mbgl/style/layout_property.hpp
parentba4a8a97316d65ab595bb7edf759f463bbd10049 (diff)
downloadqtlocation-mapboxgl-cadc617c762d453cca2c9bac41f9c1db984c5fac.tar.gz
[core] Introduce PropertyValue<T>
PropertyValue<T> represents the three possible types of style property value: undefined, constant, or function.
Diffstat (limited to 'src/mbgl/style/layout_property.hpp')
-rw-r--r--src/mbgl/style/layout_property.hpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp
index a856e7589c..b4857aeae5 100644
--- a/src/mbgl/style/layout_property.hpp
+++ b/src/mbgl/style/layout_property.hpp
@@ -1,7 +1,8 @@
#pragma once
+#include <mbgl/style/property_value.hpp>
#include <mbgl/style/property_parsing.hpp>
-#include <mbgl/style/function_evaluator.hpp>
+#include <mbgl/style/property_evaluator.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <utility>
@@ -11,25 +12,38 @@ namespace mbgl {
template <typename T>
class LayoutProperty {
public:
- explicit LayoutProperty(T v) : value(std::move(v)) {}
+ explicit LayoutProperty(T v)
+ : value(std::move(v)),
+ defaultValue(value) {}
+
+ const PropertyValue<T>& get() const {
+ return currentValue;
+ }
+
+ void set(const PropertyValue<T>& value_) {
+ currentValue = value_;
+ }
void parse(const char * name, const JSValue& layout) {
if (layout.HasMember(name)) {
- parsedValue = parseProperty<T>(name, layout[name]);
+ currentValue = parseProperty<T>(name, layout[name]);
}
}
void calculate(const StyleCalculationParameters& parameters) {
- if (parsedValue) {
- NormalFunctionEvaluator<T> evaluator;
- value = evaluator(*parsedValue, parameters);
+ if (currentValue) {
+ PropertyEvaluator<T> evaluator(parameters, defaultValue);
+ value = PropertyValue<T>::visit(currentValue, evaluator);
}
}
+ // TODO: remove / privatize
operator T() const { return value; }
-
- optional<Function<T>> parsedValue;
T value;
+
+private:
+ T defaultValue;
+ PropertyValue<T> currentValue;
};
} // namespace mbgl