diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-11-15 15:47:25 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-11-15 18:32:31 +0200 |
commit | 33818233cf49ffa7238a3d1b2bbf9fc126cbc253 (patch) | |
tree | 86833d95d8bf7abbcb8e6965aaba65d666ffff52 /include/mbgl | |
parent | 73dcfe2d0d3475ad9584969c7908ba681a3f5bfa (diff) | |
download | qtlocation-mapboxgl-33818233cf49ffa7238a3d1b2bbf9fc126cbc253.tar.gz |
[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.
Diffstat (limited to 'include/mbgl')
-rw-r--r-- | include/mbgl/style/layer.hpp | 23 | ||||
-rw-r--r-- | include/mbgl/style/layers/background_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/circle_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/custom_layer.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/style/layers/fill_extrusion_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/fill_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/heatmap_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/hillshade_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/layer.hpp.ejs | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/line_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/raster_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/symbol_layer.hpp | 10 |
12 files changed, 53 insertions, 78 deletions
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 1e1e97dd0d..21ed3adbce 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -19,6 +19,21 @@ class LayerObserver; class Filter; /** + * @brief Holds static data for a certain layer type. + */ +struct LayerTypeInfo { + /** + * @brief contains the layer type as defined in the style specification; + */ + const char* type; + /** + * @brief contains \c SourceRequired if the corresponding layer type requires source; + * contains \c SourceNotRequired otherwise. + */ + const enum { SourceRequired, SourceNotRequired } source; +}; + +/** * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style * Specification. * @@ -83,12 +98,16 @@ public: // identical platform-native peers. util::peer peer; Layer(Immutable<Impl>); + + const LayerTypeInfo* getTypeInfo() const noexcept; + protected: virtual Mutable<Impl> mutableBaseImpl() const = 0; LayerObserver* observer; }; + /** * @brief The LayerFactory abstract class * @@ -97,8 +116,8 @@ protected: class LayerFactory { public: virtual ~LayerFactory() = default; - /// Returns \c true if this factory can produce layers of the given type of the layers; returns \c false otherwise. - virtual bool supportsType(const std::string& type) const noexcept = 0; + /// Returns the layer type data. + virtual const LayerTypeInfo* getTypeInfo() const noexcept = 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; diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 639cb5154c..e188a9ba2c 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -59,15 +59,11 @@ protected: class BackgroundLayerFactory : public LayerFactory { public: BackgroundLayerFactory(); - // LayerFactory overrides. ~BackgroundLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static BackgroundLayerFactory* get() noexcept; -private: - static BackgroundLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index 4c134a58bf..4dacb905df 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -107,15 +107,11 @@ protected: class CircleLayerFactory : public LayerFactory { public: CircleLayerFactory(); - // LayerFactory overrides. ~CircleLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static CircleLayerFactory* get() noexcept; -private: - static CircleLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 0d13001b91..5021df6a60 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -90,13 +90,9 @@ public: CustomLayerFactory(); // LayerFactory overrides. ~CustomLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static CustomLayerFactory* get() noexcept; -private: - static CustomLayerFactory* instance; + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index 621eb45bc4..0092e61f3b 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -83,15 +83,11 @@ protected: class FillExtrusionLayerFactory : public LayerFactory { public: FillExtrusionLayerFactory(); - // LayerFactory overrides. ~FillExtrusionLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static FillExtrusionLayerFactory* get() noexcept; -private: - static FillExtrusionLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index aeb0ba988a..52bbd054ae 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -83,15 +83,11 @@ protected: class FillLayerFactory : public LayerFactory { public: FillLayerFactory(); - // LayerFactory overrides. ~FillLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static FillLayerFactory* get() noexcept; -private: - static FillLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 3630dafba9..d1760100ad 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -72,15 +72,11 @@ protected: class HeatmapLayerFactory : public LayerFactory { public: HeatmapLayerFactory(); - // LayerFactory overrides. ~HeatmapLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static HeatmapLayerFactory* get() noexcept; -private: - static HeatmapLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index a251956d01..978670f8a9 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -77,15 +77,11 @@ protected: class HillshadeLayerFactory : public LayerFactory { public: HillshadeLayerFactory(); - // LayerFactory overrides. ~HillshadeLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static HillshadeLayerFactory* get() noexcept; -private: - static HillshadeLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index d335829efb..11d45b4b0c 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -75,15 +75,11 @@ protected: class <%- camelize(type) %>LayerFactory : public LayerFactory { public: <%- camelize(type) %>LayerFactory(); - // LayerFactory overrides. ~<%- camelize(type) %>LayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static <%- camelize(type) %>LayerFactory* get() noexcept; -private: - static <%- camelize(type) %>LayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 26837f4d06..0f5e2bb347 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -128,15 +128,11 @@ protected: class LineLayerFactory : public LayerFactory { public: LineLayerFactory(); - // LayerFactory overrides. ~LineLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static LineLayerFactory* get() noexcept; -private: - static LineLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index 86f57f3d12..4b63570590 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -89,15 +89,11 @@ protected: class RasterLayerFactory : public LayerFactory { public: RasterLayerFactory(); - // LayerFactory overrides. ~RasterLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static RasterLayerFactory* get() noexcept; -private: - static RasterLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 685e3cb4df..62ea393b33 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -277,15 +277,11 @@ protected: class SymbolLayerFactory : public LayerFactory { public: SymbolLayerFactory(); - // LayerFactory overrides. ~SymbolLayerFactory() override; - bool supportsType(const std::string& type) const noexcept final; - std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; - - static SymbolLayerFactory* get() noexcept; -private: - static SymbolLayerFactory* instance; + // LayerFactory overrides. + const LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const conversion::Convertible& value) final; }; } // namespace style |