summaryrefslogtreecommitdiff
path: root/src/mbgl/style/function/categorical_stops.cpp
blob: dd179f5376236c4d98ae97950a604e3d7477b3b8 (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
36
37
38
39
40
41
#include <mbgl/style/function/categorical_stops.hpp>
#include <mbgl/style/types.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>
optional<T> CategoricalStops<T>::evaluate(const Value& value) const {
    auto v = categoricalValue(value);
    if (!v) {
        return {};
    }
    auto it = stops.find(*v);
    return it == stops.end() ? optional<T>() : it->second;
}

template class CategoricalStops<float>;
template class CategoricalStops<Color>;
template class CategoricalStops<std::array<float, 2>>;
template class CategoricalStops<std::string>;
template class CategoricalStops<TextTransformType>;
template class CategoricalStops<TextJustifyType>;
template class CategoricalStops<SymbolAnchorType>;
template class CategoricalStops<LineJoinType>;

} // namespace style
} // namespace mbgl