summaryrefslogtreecommitdiff
path: root/include/mbgl/style/function/type.hpp
blob: 94f710c0051e3d4aa1dbad40d1458054f19af8d2 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#pragma once

#include <vector>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/variant.hpp>

namespace mbgl {
namespace style {
namespace expression {
namespace type {

class Primitive;
class Variant;
class Array;
class NArgs;
class Typename;
class Lambda;

using ValueType = variant<
    Primitive,
    Typename,
    mapbox::util::recursive_wrapper<Variant>,
    mapbox::util::recursive_wrapper<Array>,
    mapbox::util::recursive_wrapper<NArgs>>;
    
using Type = variant<
    Primitive,
    Typename,
    Variant,
    Array,
    NArgs,
    Lambda>;

class Primitive {
public:
    std::string getName() const { return name; }
    
    static Primitive Null;
    static Primitive Number;
    static Primitive String;
    static Primitive Color;
    static Primitive Object;
    
    // It's weird for this to be on Primitive.  Where should it go?
    static Type Value;
    
private:
    std::string name;
    Primitive(std::string name_) : name(name_) {}
};

class Typename {
public:
    Typename(std::string name_) : name(name_) {}
    std::string getName() const { return name; }
private:
    std::string name;
};

class Array {
public:
    Array(ValueType itemType_) : itemType(itemType_) {}
    Array(ValueType itemType_, int N_) : itemType(itemType_), N(N_) {}
    std::string getName() const {
        return "array";
    }

private:
    ValueType itemType;
    optional<int> N;
};

class Variant {
public:
    Variant(std::vector<ValueType> members_) : members(members_) {}
    std::string getName() const {
        return "variant";
    }
    
    std::vector<ValueType> getMembers() {
        return members;
    }

private:
    std::vector<ValueType> members;
};

class NArgs {
public:
    NArgs(std::vector<ValueType> types_) : types(types_) {}
    std::string getName() const {
        return "nargs";
    }
private:
    std::vector<ValueType> types;
};

class Lambda {
public:
    Lambda(ValueType result_, std::vector<ValueType> params_) :
        result(result_),
        params(params_)
    {}
    std::string getName() const {
        return "lambda";
    }
    ValueType getResult() const { return result; }
private:
    ValueType result;
    std::vector<ValueType> params;
};


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