summaryrefslogtreecommitdiff
path: root/src/mbgl/style/style_parser.hpp
blob: 5ee2415abde1475faf9bc23494c5219d9bdcf05b (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
#ifndef MBGL_STYLE_STYLE_PARSER
#define MBGL_STYLE_STYLE_PARSER

#include <mbgl/style/style_layer.hpp>
#include <mbgl/map/source.hpp>

#include <rapidjson/document.h>

#include <vector>
#include <memory>
#include <string>
#include <unordered_map>
#include <forward_list>

namespace mbgl {

class StyleLayer;
class Source;

using JSVal = rapidjson::Value;

class StyleParser {
public:
    ~StyleParser();

    void parse(const JSVal&);

    std::string spriteURL;
    std::string glyphURL;

    std::vector<std::unique_ptr<Source>> sources;
    std::vector<std::unique_ptr<StyleLayer>> layers;

private:
    void parseSources(const JSVal&);
    void parseLayers(const JSVal&);
    void parseLayer(const std::string& id, const JSVal&, std::unique_ptr<StyleLayer>&);
    void parseVisibility(StyleLayer&, const JSVal& value);

    std::unordered_map<std::string, const Source*> sourcesMap;
    std::unordered_map<std::string, std::pair<const JSVal&, std::unique_ptr<StyleLayer>>> layersMap;

    // Store a stack of layer IDs we're parsing right now. This is to prevent reference cycles.
    std::forward_list<std::string> stack;
};

}

#endif