#include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { class LayerManagerDefault final : public LayerManager { public: LayerManagerDefault(); private: void addLayerType(std::unique_ptr); // LayerManager overrides. LayerFactory* getFactory(const std::string& type) noexcept final; LayerFactory* getFactory(const style::LayerTypeInfo*) noexcept final; std::vector> factories; std::map typeToFactory; }; LayerManagerDefault::LayerManagerDefault() { #if !defined(MBGL_LAYER_FILL_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_LINE_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_CIRCLE_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_SYMBOL_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_RASTER_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_BACKGROUND_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_HILLSHADE_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_FILL_EXTRUSION_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_HEATMAP_DISABLE_ALL) addLayerType(std::make_unique()); #endif #if !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) addLayerType(std::make_unique()); #endif } void LayerManagerDefault::addLayerType(std::unique_ptr factory) { std::string type{factory->getTypeInfo()->type}; if (!type.empty()) { typeToFactory.emplace(std::make_pair(std::move(type), factory.get())); } factories.emplace_back(std::move(factory)); } LayerFactory* LayerManagerDefault::getFactory(const mbgl::style::LayerTypeInfo* typeInfo) noexcept { assert(typeInfo); for (const auto& factory: factories) { if (factory->getTypeInfo() == typeInfo) { return factory.get(); } } assert(false); return nullptr; } LayerFactory* LayerManagerDefault::getFactory(const std::string& type) noexcept { auto search = typeToFactory.find(type); return (search != typeToFactory.end()) ? search->second : nullptr; } // static LayerManager* LayerManager::get() noexcept { static LayerManagerDefault instance; return &instance; } #if defined(MBGL_LAYER_LINE_DISABLE_ALL) || defined(MBGL_LAYER_SYMBOL_DISABLE_ALL) || defined(MBGL_LAYER_FILL_DISABLE_ALL) const bool LayerManager::annotationsEnabled = false; #else const bool LayerManager::annotationsEnabled = true; #endif } // namespace mbgl