summaryrefslogtreecommitdiff
path: root/include/mbgl/style/function/source_function.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-10-28 16:39:50 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-02 09:44:42 -0800
commit141e995806576364d185626176c1b993fc519291 (patch)
treeecdc41fc7699f2a1a9e9456157348451ebe99597 /include/mbgl/style/function/source_function.hpp
parent6a6bddb4537004cc1bfc506e76772de74d33f3f7 (diff)
downloadqtlocation-mapboxgl-141e995806576364d185626176c1b993fc519291.tar.gz
[core] Add support for data-driven styling
Diffstat (limited to 'include/mbgl/style/function/source_function.hpp')
-rw-r--r--include/mbgl/style/function/source_function.hpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp
new file mode 100644
index 0000000000..e998be082a
--- /dev/null
+++ b/include/mbgl/style/function/source_function.hpp
@@ -0,0 +1,56 @@
+#pragma once
+
+#include <mbgl/style/function/exponential_stops.hpp>
+#include <mbgl/style/function/interval_stops.hpp>
+#include <mbgl/style/function/categorical_stops.hpp>
+#include <mbgl/style/function/identity_stops.hpp>
+#include <mbgl/tile/geometry_tile_data.hpp>
+#include <mbgl/util/interpolate.hpp>
+#include <mbgl/util/variant.hpp>
+
+#include <string>
+
+namespace mbgl {
+namespace style {
+
+template <class T>
+class SourceFunction {
+public:
+ using Stops = std::conditional_t<
+ util::Interpolatable<T>,
+ variant<
+ ExponentialStops<T>,
+ IntervalStops<T>,
+ CategoricalStops<T>,
+ IdentityStops<T>>,
+ variant<
+ IntervalStops<T>,
+ CategoricalStops<T>,
+ IdentityStops<T>>>;
+
+ SourceFunction(std::string property_, Stops stops_)
+ : property(std::move(property_)),
+ stops(std::move(stops_)) {
+ }
+
+ T evaluate(const GeometryTileFeature& feature) const {
+ optional<Value> v = feature.getValue(property);
+ if (!v) {
+ return T();
+ }
+ return stops.match([&] (const auto& s) {
+ return s.evaluate(*v);
+ });
+ }
+
+ friend bool operator==(const SourceFunction& lhs,
+ const SourceFunction& rhs) {
+ return lhs.property == rhs.property && lhs.stops == rhs.stops;
+ }
+
+ std::string property;
+ Stops stops;
+};
+
+} // namespace style
+} // namespace mbgl