summaryrefslogtreecommitdiff
path: root/src/mbgl/style/parser.hpp
blob: f992519083cd05eab0ee47fab14b59eae7cd9585 (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
#pragma once

#include <mbgl/style/layer.hpp>
#include <mbgl/style/source.hpp>
#include <mbgl/style/light.hpp>

#include <mbgl/util/constants.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/geo.hpp>

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

namespace mbgl {
namespace style {

using StyleParseResult = std::exception_ptr;

class Parser {
public:
    ~Parser();

    StyleParseResult parse(const std::string&);

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

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

    TransitionOptions transition { { util::DEFAULT_TRANSITION_DURATION } };
    Light light;

    std::string name;
    LatLng latLng;
    double zoom = 0;
    double bearing = 0;
    double pitch = 0;

    // Statically evaluate layer properties to determine what font stacks are used.
    std::set<FontStack> fontStacks() const;

private:
    void parseTransition(const JSValue&);
    void parseLight(const JSValue&);
    void parseSources(const JSValue&);
    void parseLayers(const JSValue&);
    void parseLayer(const std::string& id, const JSValue&, std::unique_ptr<Layer>&);

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

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

} // namespace style
} // namespace mbgl