summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/layer.cpp.ejs
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-11-15 15:47:25 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-11-15 17:48:36 +0200
commitff09c94d0825f5dbe7dddce52b64e74d61978976 (patch)
tree86833d95d8bf7abbcb8e6965aaba65d666ffff52 /src/mbgl/style/layers/layer.cpp.ejs
parent73dcfe2d0d3475ad9584969c7908ba681a3f5bfa (diff)
downloadqtlocation-mapboxgl-upstream/mikhail_LayerTypeInfo.tar.gz
[core][android] Introduce mbgl::style::LayerTypeInfoupstream/mikhail_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.
Diffstat (limited to 'src/mbgl/style/layers/layer.cpp.ejs')
-rw-r--r--src/mbgl/style/layers/layer.cpp.ejs29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs
index 716f4ab854..4a708041e9 100644
--- a/src/mbgl/style/layers/layer.cpp.ejs
+++ b/src/mbgl/style/layers/layer.cpp.ejs
@@ -19,6 +19,14 @@
namespace mbgl {
namespace style {
+namespace {
+<% if (type === 'background') { -%>
+ const LayerTypeInfo typeInfo<%- camelize(type) %>{ "<%- type %>", LayerTypeInfo::SourceNotRequired };
+<% } else { -%>
+ const LayerTypeInfo typeInfo<%- camelize(type) %>{ "<%- type %>", LayerTypeInfo::SourceRequired };
+<% } -%>
+} // namespace
+
<% if (type === 'background') { -%>
<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID)
: Layer(makeMutable<Impl>(LayerType::<%- camelize(type) %>, layerID, std::string())) {
@@ -59,8 +67,8 @@ void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer<rapidjs
}
<% } -%>
-LayerFactory* <%- camelize(type) %>Layer::Impl::getLayerFactory() const noexcept {
- return <%- camelize(type) %>LayerFactory::get();
+const LayerTypeInfo* <%- camelize(type) %>Layer::Impl::getTypeInfo() const noexcept {
+ return &typeInfo<%- camelize(type) %>;
}
// Layout properties
@@ -264,23 +272,12 @@ Mutable<Layer::Impl> <%- camelize(type) %>Layer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
-<%- camelize(type) %>LayerFactory* <%- camelize(type) %>LayerFactory::instance = nullptr;
-
-<%- camelize(type) %>LayerFactory::<%- camelize(type) %>LayerFactory() {
- assert(!instance);
- instance = this;
-}
+<%- camelize(type) %>LayerFactory::<%- camelize(type) %>LayerFactory() = default;
<%- camelize(type) %>LayerFactory::~<%- camelize(type) %>LayerFactory() = default;
-// static
-<%- camelize(type) %>LayerFactory* <%- camelize(type) %>LayerFactory::get() noexcept {
- assert(instance);
- return instance;
-}
-
-bool <%- camelize(type) %>LayerFactory::supportsType(const std::string& type) const noexcept {
- return type == "<%- type %>";
+const LayerTypeInfo* <%- camelize(type) %>LayerFactory::getTypeInfo() const noexcept {
+ return &typeInfo<%- camelize(type) %>;
}
std::unique_ptr<style::Layer> <%- camelize(type) %>LayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) {