#ifndef MBGL_STYLE_STYLE_PARSER #define MBGL_STYLE_STYLE_PARSER #include #include #include #include #include #include #include #include #include namespace mbgl { enum class ClassID : uint32_t; class StyleLayer; class StyleParser { public: using JSVal = const rapidjson::Value&; StyleParser(); void parse(JSVal document); std::vector> getLayers() { return layers; } std::string getSprite() const { return sprite; } std::string getGlyphURL() const { return glyph_url; } private: void parseConstants(JSVal value); JSVal replaceConstant(JSVal value); void parseSources(JSVal value); void parseLayers(JSVal value); void parseLayer(std::pair> &pair); void parsePaints(JSVal value, std::map &paints); void parsePaint(JSVal, ClassProperties &properties); void parseReference(JSVal value, util::ptr &layer); void parseBucket(JSVal value, util::ptr &layer); void parseLayout(JSVal value, util::ptr &bucket); void parseSprite(JSVal value); void parseGlyphURL(JSVal value); // Parses optional properties into a render bucket. template bool parseRenderProperty(JSVal value, T &target, const char *name); template bool parseRenderProperty(JSVal value, T &target, const char *name); // Parses optional properties into style class properties. template void parseVisibility(StyleBucket &bucket, JSVal value); template bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value); template bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value, const char *transition_name); template bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass); template bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass, JSVal transition); template std::tuple parseProperty(JSVal value, const char *property_name); template std::tuple parseProperty(JSVal value, const char *property_name, JSVal transition); template std::tuple> parseFunction(JSVal value, const char *); template std::tuple> parsePiecewiseConstantFunction(JSVal value, std::chrono::steady_clock::duration duration); template std::tuple>> parseStops(JSVal value, const char *property_name); std::tuple> parseFloatArray(JSVal value); FilterExpression parseFilter(JSVal); private: std::unordered_map constants; std::unordered_map> sources; // This stores the root layer. std::vector> layers; // This maps ids to Layer objects, with all items being at the root level. std::unordered_map>> layersMap; // Store a stack of layers we're parsing right now. This is to prevent reference cycles. std::forward_list stack; // Base URL of the sprite image. std::string sprite; // URL template for glyph PBFs. std::string glyph_url; }; } #endif