summaryrefslogtreecommitdiff
path: root/src/mbgl/style/function/identity_stops.cpp
blob: 0ac6fda8460def90167fdce754de41b3aae16c37 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <mbgl/style/function/identity_stops.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/color.hpp>

#include <array>

namespace mbgl {
namespace style {

template <>
optional<float> IdentityStops<float>::evaluate(const Value& value) const {
    return numericValue<float>(value);
}

template <>
optional<std::string> IdentityStops<std::string>::evaluate(const Value& value) const {
    if (!value.is<std::string>()) {
        return {};
    }
    
    return value.get<std::string>();
}

template <>
optional<Color> IdentityStops<Color>::evaluate(const Value& value) const {
    if (!value.is<std::string>()) {
        return {};
    }

    return Color::parse(value.get<std::string>());
}

template <>
optional<TextTransformType> IdentityStops<TextTransformType>::evaluate(const Value& value) const {
    if (!value.is<std::string>()) {
        return {};
    }

    return Enum<TextTransformType>::toEnum(value.get<std::string>());
}

template <>
optional<TextJustifyType> IdentityStops<TextJustifyType>::evaluate(const Value& value) const {
    if (!value.is<std::string>()) {
        return {};
    }

    return Enum<TextJustifyType>::toEnum(value.get<std::string>());
}

template <>
optional<SymbolAnchorType> IdentityStops<SymbolAnchorType>::evaluate(const Value& value) const {
    if (!value.is<std::string>()) {
        return {};
    }

    return Enum<SymbolAnchorType>::toEnum(value.get<std::string>());
}

template <>
optional<LineJoinType> IdentityStops<LineJoinType>::evaluate(const Value& value) const {
    if (!value.is<std::string>()) {
        return {};
    }

    return Enum<LineJoinType>::toEnum(value.get<std::string>());
}

template <>
optional<std::array<float, 2>> IdentityStops<std::array<float, 2>>::evaluate(const Value& value) const {
    if (!value.is<std::vector<Value>>()) {
        return {};
    }

    const auto& vector = value.get<std::vector<Value>>();
    if (vector.size() != 2 || !numericValue<float>(vector[0]) || !numericValue<float>(vector[1])) {
        return {};
    }

    std::array<float, 2> array {{
        *numericValue<float>(vector[0]),
        *numericValue<float>(vector[1])
    }};
    return array;
}

} // namespace style
} // namespace mbgl