summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/layer.cpp.ejs
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-10-28 22:33:06 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-10-31 18:05:01 +0200
commitcfcb53128b41941a9cdacfec18d618b0866a96bc (patch)
tree27ee48ad45fca144d21f71673137c470bbb19459 /src/mbgl/style/layers/layer.cpp.ejs
parent278aa3370374154ad6fac7790d2da1546e8493f3 (diff)
downloadqtlocation-mapboxgl-cfcb53128b41941a9cdacfec18d618b0866a96bc.tar.gz
Introduce the style::Layer factory classes
This patch introduces the initial implementation of - A `LayerFactory` abstract class that creates `style::Layer` instances of a certain layer type (line, hillshade, round, ..) - A singleton `LayerManager` class, which is responsible for initializing the `LayerFactory` instances and forwarding the `create()` calls to the corresponding factory.
Diffstat (limited to 'src/mbgl/style/layers/layer.cpp.ejs')
-rw-r--r--src/mbgl/style/layers/layer.cpp.ejs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs
index d4404ed949..6d08370342 100644
--- a/src/mbgl/style/layers/layer.cpp.ejs
+++ b/src/mbgl/style/layers/layer.cpp.ejs
@@ -260,5 +260,31 @@ Mutable<Layer::Impl> <%- camelize(type) %>Layer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
+<%- camelize(type) %>LayerFactory::~<%- camelize(type) %>LayerFactory() = default;
+
+const char* <%- camelize(type) %>LayerFactory::type() const {
+ return "<%- type %>";
+}
+
+std::unique_ptr<style::Layer> <%- camelize(type) %>LayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) {
+<% if (type === 'background') { -%>
+ (void)value;
+ return std::unique_ptr<style::Layer>(new <%- camelize(type) %>Layer(id));
+<% } else { -%>
+ optional<std::string> source = getSource(value);
+ if (!source) {
+ return nullptr;
+ }
+
+ std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new <%- camelize(type) %>Layer(id, *source));
+<% if (type !== 'raster' && type !== 'hillshade') { -%>
+ if (!initSourceLayerAndFilter(layer.get(), value)) {
+ return nullptr;
+ }
+<% } -%>
+ return layer;
+<% } -%>
+}
+
} // namespace style
} // namespace mbgl