summaryrefslogtreecommitdiff
path: root/src/mbgl/style/function/convert.cpp
blob: a3b19f287b054274e79abb98f345e0c2fb29e5a6 (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
#include <mbgl/style/function/convert.hpp>

namespace mbgl {
namespace style {
namespace expression {

std::unique_ptr<Expression> Convert::fromIdentityFunction(const std::string& property, type::Type type) {
    return type.match(
        [&] (const type::StringType&) {
            return makeGet(type::String, property);
        },
        [&] (const type::NumberType&) {
            return makeGet(type::Number, property);
        },
        [&] (const type::BooleanType&) {
            return makeGet(type::Boolean, property);
        },
        [&] (const type::ColorType&) {
            std::vector<std::unique_ptr<Expression>> args;
            args.push_back(makeGet(type::String, property));
            return std::make_unique<Coercion>(type::Color, std::move(args));
        },
        [&] (const type::Array& arr) {
            std::vector<std::unique_ptr<Expression>> getArgs;
            getArgs.push_back(makeLiteral(property));
            ParsingContext ctx;
            ParseResult get = createCompoundExpression("get", std::move(getArgs), ctx);
            assert(get);
            assert(ctx.getErrors().size() == 0);
            return std::make_unique<ArrayAssertion>(arr, std::move(*get));
        },
        [&] (const auto&) -> std::unique_ptr<Expression> {
            return makeLiteral(Null);
        }
    );
}

} // namespace expression
} // namespace style
} // namespace mbgl