summaryrefslogtreecommitdiff
path: root/include/mbgl/style
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 /include/mbgl/style
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 'include/mbgl/style')
-rw-r--r--include/mbgl/style/layer.hpp41
-rw-r--r--include/mbgl/style/layers/background_layer.hpp8
-rw-r--r--include/mbgl/style/layers/circle_layer.hpp8
-rw-r--r--include/mbgl/style/layers/fill_extrusion_layer.hpp8
-rw-r--r--include/mbgl/style/layers/fill_layer.hpp8
-rw-r--r--include/mbgl/style/layers/heatmap_layer.hpp8
-rw-r--r--include/mbgl/style/layers/hillshade_layer.hpp8
-rw-r--r--include/mbgl/style/layers/layer.hpp.ejs8
-rw-r--r--include/mbgl/style/layers/line_layer.hpp8
-rw-r--r--include/mbgl/style/layers/raster_layer.hpp8
-rw-r--r--include/mbgl/style/layers/symbol_layer.hpp8
11 files changed, 119 insertions, 2 deletions
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp
index 5f12115f87..fd0824c03f 100644
--- a/include/mbgl/style/layer.hpp
+++ b/include/mbgl/style/layer.hpp
@@ -30,9 +30,9 @@ class Filter;
* * Cloning and copying
*
* All other functionality lives in the derived classes. To instantiate a layer, create an instance of the desired
- * type, passing the ID:
+ * type, calling `LayerManager`:
*
- * auto circleLayer = std::make_unique<CircleLayer>("my-circle-layer");
+ * auto circleLayer = LayerManager::get()->createLayer("circle", ...);
*/
class Layer {
public:
@@ -89,5 +89,42 @@ protected:
LayerObserver* observer = nullptr;
};
+/**
+ * @brief The LayerFactory abstract class
+ *
+ * This class is responsible for creation of the layer objects that belong to a concrete layer type.
+ */
+class LayerFactory {
+public:
+ virtual ~LayerFactory() = default;
+ /// Returns the type of the layers, created by this factory.
+ virtual const char* type() const = 0;
+ /// Returns a new Layer instance on success call; returns `nulltptr` otherwise.
+ virtual std::unique_ptr<Layer> createLayer(const std::string& id, const conversion::Convertible& value) = 0;
+protected:
+ optional<std::string> getSource(const conversion::Convertible& value) const;
+ bool initSourceLayerAndFilter(Layer*, const conversion::Convertible& value) const;
+};
+
+/**
+ * @brief A singleton class forwarding calls to the corresponding \c LayerFactory instance.
+ */
+class LayerManager {
+public:
+ /**
+ * @brief A singleton getter.
+ *
+ * @return LayerManager*
+ */
+ static LayerManager* get();
+
+ virtual ~LayerManager() = default;
+ /// Returns a new Layer instance on success call; returns `nulltptr` otherwise.
+ virtual std::unique_ptr<Layer> createLayer(const std::string& type, const std::string& id, const conversion::Convertible& value, conversion::Error& error) = 0;
+
+protected:
+ LayerManager() = default;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp
index 6739973e53..989ef54b21 100644
--- a/include/mbgl/style/layers/background_layer.hpp
+++ b/include/mbgl/style/layers/background_layer.hpp
@@ -56,5 +56,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class BackgroundLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~BackgroundLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp
index e0a121e2dc..dd22275b85 100644
--- a/include/mbgl/style/layers/circle_layer.hpp
+++ b/include/mbgl/style/layers/circle_layer.hpp
@@ -104,5 +104,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class CircleLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~CircleLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp
index ed1cbb924b..fcc66e782b 100644
--- a/include/mbgl/style/layers/fill_extrusion_layer.hpp
+++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp
@@ -80,5 +80,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class FillExtrusionLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~FillExtrusionLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp
index b265bf5d06..0c36435ffc 100644
--- a/include/mbgl/style/layers/fill_layer.hpp
+++ b/include/mbgl/style/layers/fill_layer.hpp
@@ -80,5 +80,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class FillLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~FillLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp
index 5069eef165..3f53877523 100644
--- a/include/mbgl/style/layers/heatmap_layer.hpp
+++ b/include/mbgl/style/layers/heatmap_layer.hpp
@@ -69,5 +69,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class HeatmapLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~HeatmapLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp
index 5c2b4276c3..3227505f5d 100644
--- a/include/mbgl/style/layers/hillshade_layer.hpp
+++ b/include/mbgl/style/layers/hillshade_layer.hpp
@@ -74,5 +74,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class HillshadeLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~HillshadeLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs
index a5d4be14e6..b19b501713 100644
--- a/include/mbgl/style/layers/layer.hpp.ejs
+++ b/include/mbgl/style/layers/layer.hpp.ejs
@@ -72,5 +72,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class <%- camelize(type) %>LayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~<%- camelize(type) %>LayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp
index 487fef5837..62cca8215d 100644
--- a/include/mbgl/style/layers/line_layer.hpp
+++ b/include/mbgl/style/layers/line_layer.hpp
@@ -125,5 +125,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class LineLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~LineLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp
index a31a362f49..27057c6af7 100644
--- a/include/mbgl/style/layers/raster_layer.hpp
+++ b/include/mbgl/style/layers/raster_layer.hpp
@@ -86,5 +86,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class RasterLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~RasterLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp
index 39852aa715..6c0ec6ca6e 100644
--- a/include/mbgl/style/layers/symbol_layer.hpp
+++ b/include/mbgl/style/layers/symbol_layer.hpp
@@ -274,5 +274,13 @@ protected:
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
+class SymbolLayerFactory : public LayerFactory {
+protected:
+ // LayerFactory overrides.
+ ~SymbolLayerFactory() override;
+ const char* type() const final;
+ std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) override;
+};
+
} // namespace style
} // namespace mbgl