From ff09c94d0825f5dbe7dddce52b64e74d61978976 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Thu, 15 Nov 2018 15:47:25 +0200 Subject: [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. --- include/mbgl/style/layer.hpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'include/mbgl/style/layer.hpp') 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 @@ -18,6 +18,21 @@ namespace style { 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); + + const LayerTypeInfo* getTypeInfo() const noexcept; + protected: virtual Mutable 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 createLayer(const std::string& id, const conversion::Convertible& value) = 0; -- cgit v1.2.1