1 #pragma once 2 3 #include <mbgl/style/layer.hpp> 4 #include <mbgl/style/source.hpp> 5 #include <mbgl/style/light.hpp> 6 7 #include <mbgl/util/rapidjson.hpp> 8 #include <mbgl/util/font_stack.hpp> 9 #include <mbgl/util/geo.hpp> 10 11 #include <vector> 12 #include <memory> 13 #include <stdexcept> 14 #include <string> 15 #include <unordered_map> 16 #include <forward_list> 17 18 namespace mbgl { 19 namespace style { 20 21 using StyleParseResult = std::exception_ptr; 22 23 class Parser { 24 public: 25 ~Parser(); 26 27 StyleParseResult parse(const std::string&); 28 29 std::string spriteURL; 30 std::string glyphURL; 31 32 std::vector<std::unique_ptr<Source>> sources; 33 std::vector<std::unique_ptr<Layer>> layers; 34 35 TransitionOptions transition; 36 Light light; 37 38 std::string name; 39 LatLng latLng; 40 double zoom = 0; 41 double bearing = 0; 42 double pitch = 0; 43 44 // Statically evaluate layer properties to determine what font stacks are used. 45 std::vector<FontStack> fontStacks() const; 46 47 private: 48 void parseTransition(const JSValue&); 49 void parseLight(const JSValue&); 50 void parseSources(const JSValue&); 51 void parseLayers(const JSValue&); 52 void parseLayer(const std::string& id, const JSValue&, std::unique_ptr<Layer>&); 53 54 std::unordered_map<std::string, const Source*> sourcesMap; 55 std::unordered_map<std::string, std::pair<const JSValue&, std::unique_ptr<Layer>>> layersMap; 56 57 // Store a stack of layer IDs we're parsing right now. This is to prevent reference cycles. 58 std::forward_list<std::string> stack; 59 }; 60 61 } // namespace style 62 } // namespace mbgl 63