From 33818233cf49ffa7238a3d1b2bbf9fc126cbc253 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Thu, 15 Nov 2018 15:47:25 +0200 Subject: [core][android] Introduce mbgl::style::LayerTypeInfo The `LayerTypeInfo` contains static meta data about certain layer type. Each layer module should have a single immutable `LayerTypeInfo` instance for the represented layer type. Both `LayerImpl` and `LayerFactory` from the module always refer to the same `LayerTypeInfo` instance, so address of this instance can be used as a layer module Id during the process life time. --- src/mbgl/style/layers/background_layer.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/mbgl/style/layers/background_layer.cpp') diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index d84c7b66de..43ada28ab7 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -14,6 +14,10 @@ namespace mbgl { namespace style { +namespace { + const LayerTypeInfo typeInfoBackground{ "background", LayerTypeInfo::SourceNotRequired }; +} // namespace + BackgroundLayer::BackgroundLayer(const std::string& layerID) : Layer(makeMutable(LayerType::Background, layerID, std::string())) { } @@ -42,8 +46,8 @@ std::unique_ptr BackgroundLayer::cloneRef(const std::string& id_) const { void BackgroundLayer::Impl::stringifyLayout(rapidjson::Writer&) const { } -LayerFactory* BackgroundLayer::Impl::getLayerFactory() const noexcept { - return BackgroundLayerFactory::get(); +const LayerTypeInfo* BackgroundLayer::Impl::getTypeInfo() const noexcept { + return &typeInfoBackground; } // Layout properties @@ -274,23 +278,12 @@ Mutable BackgroundLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -BackgroundLayerFactory* BackgroundLayerFactory::instance = nullptr; - -BackgroundLayerFactory::BackgroundLayerFactory() { - assert(!instance); - instance = this; -} +BackgroundLayerFactory::BackgroundLayerFactory() = default; BackgroundLayerFactory::~BackgroundLayerFactory() = default; -// static -BackgroundLayerFactory* BackgroundLayerFactory::get() noexcept { - assert(instance); - return instance; -} - -bool BackgroundLayerFactory::supportsType(const std::string& type) const noexcept { - return type == "background"; +const LayerTypeInfo* BackgroundLayerFactory::getTypeInfo() const noexcept { + return &typeInfoBackground; } std::unique_ptr BackgroundLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { -- cgit v1.2.1