diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-10-28 22:33:06 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-10-31 18:05:01 +0200 |
commit | cfcb53128b41941a9cdacfec18d618b0866a96bc (patch) | |
tree | 27ee48ad45fca144d21f71673137c470bbb19459 /include/mbgl/style/layer.hpp | |
parent | 278aa3370374154ad6fac7790d2da1546e8493f3 (diff) | |
download | qtlocation-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/layer.hpp')
-rw-r--r-- | include/mbgl/style/layer.hpp | 41 |
1 files changed, 39 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 |