blob: bcdf170f177f69770640003ee71a11e02b1289e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
|