diff options
Diffstat (limited to 'src/mbgl/style/function/categorical_stops.cpp')
-rw-r--r-- | src/mbgl/style/function/categorical_stops.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mbgl/style/function/categorical_stops.cpp b/src/mbgl/style/function/categorical_stops.cpp new file mode 100644 index 0000000000..bcdf170f17 --- /dev/null +++ b/src/mbgl/style/function/categorical_stops.cpp @@ -0,0 +1,35 @@ +#include <mbgl/style/function/categorical_stops.hpp> +#include <mbgl/util/color.hpp> + +#include <array> + +namespace mbgl { +namespace style { + +optional<CategoricalValue> categoricalValue(const Value& value) { + return value.match( + [] (bool t) { return optional<CategoricalValue>(t); }, + [] (uint64_t t) { return optional<CategoricalValue>(int64_t(t)); }, + [] (int64_t t) { return optional<CategoricalValue>(t); }, + [] (double t) { return optional<CategoricalValue>(int64_t(t)); }, + [] (const std::string& t) { return optional<CategoricalValue>(t); }, + [] (const auto&) { return optional<CategoricalValue>(); } + ); +} + +template <class T> +T CategoricalStops<T>::evaluate(const Value& value) const { + auto v = categoricalValue(value); + if (!v) { + return defaultValue; + } + auto it = stops.find(*v); + return it == stops.end() ? defaultValue : it->second; +} + +template class CategoricalStops<float>; +template class CategoricalStops<Color>; +template class CategoricalStops<std::array<float, 2>>; + +} // namespace style +} // namespace mbgl |