diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-10-25 16:15:31 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-10-25 22:42:43 +0300 |
commit | 7a9461a8d439458b18656ecfb839923adc5f0e9b (patch) | |
tree | 5617367418dafc5b7b45c4ba7cca4b74f40200f3 /include | |
parent | fdd8b54900d963d01f9b643fa7edd9e988eb7785 (diff) | |
download | qtlocation-mapboxgl-7a9461a8d439458b18656ecfb839923adc5f0e9b.tar.gz |
Consolidate `style::Layer` properties API
The `style::Layer` class now exposes all the properties contained at `style::LayerImpl`.
This allowed to drop `style::Layer::accept()` method usage, avoid the repeated generated code
and thus save some binary size.
This patch is a part of the layers modularization effort.
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/style/layer.hpp | 73 | ||||
-rw-r--r-- | include/mbgl/style/layers/background_layer.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/layers/circle_layer.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/layers/custom_layer.hpp | 12 | ||||
-rw-r--r-- | include/mbgl/style/layers/fill_extrusion_layer.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/layers/fill_layer.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/layers/heatmap_layer.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/layers/hillshade_layer.hpp | 13 | ||||
-rw-r--r-- | include/mbgl/style/layers/layer.hpp.ejs | 22 | ||||
-rw-r--r-- | include/mbgl/style/layers/line_layer.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/layers/raster_layer.hpp | 13 | ||||
-rw-r--r-- | include/mbgl/style/layers/symbol_layer.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/util/immutable.hpp | 6 |
13 files changed, 61 insertions, 196 deletions
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 3b7969ea79..dd8f1a1e0e 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -1,6 +1,5 @@ #pragma once -#include <mbgl/util/noncopyable.hpp> #include <mbgl/util/peer.hpp> #include <mbgl/util/immutable.hpp> #include <mbgl/util/optional.hpp> @@ -27,6 +26,7 @@ class CustomLayer; class FillExtrusionLayer; class HeatmapLayer; class LayerObserver; +class Filter; /** * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style @@ -44,8 +44,11 @@ class LayerObserver; * * auto circleLayer = std::make_unique<CircleLayer>("my-circle-layer"); */ -class Layer : public mbgl::util::noncopyable { +class Layer { public: + Layer(const Layer& ) = delete; + Layer& operator=(const Layer&) = delete; + virtual ~Layer(); // Check whether this layer is of the given subtype. @@ -63,60 +66,26 @@ public: return is<T>() ? reinterpret_cast<const T*>(this) : nullptr; } - // Convenience method for dynamic dispatch on the concrete layer type. Using - // method overloading, this allows consolidation of logic common to vector-based - // layers (Fill, FillExtrusion, Line, Circle, or Symbol). For example: - // - // struct Visitor { - // void operator()(CustomLayer&) { ... } - // void operator()(RasterLayer&) { ... } - // void operator()(BackgroundLayer&) { ... } - // template <class VectorLayer> - // void operator()(VectorLayer&) { ... } - // }; - // - template <class V> - auto accept(V&& visitor) { - switch (getType()) { - case LayerType::Fill: - return std::forward<V>(visitor)(*as<FillLayer>()); - case LayerType::Line: - return std::forward<V>(visitor)(*as<LineLayer>()); - case LayerType::Circle: - return std::forward<V>(visitor)(*as<CircleLayer>()); - case LayerType::Symbol: - return std::forward<V>(visitor)(*as<SymbolLayer>()); - case LayerType::Raster: - return std::forward<V>(visitor)(*as<RasterLayer>()); - case LayerType::Background: - return std::forward<V>(visitor)(*as<BackgroundLayer>()); - case LayerType::Hillshade: - return std::forward<V>(visitor)(*as<HillshadeLayer>()); - case LayerType::Custom: - return std::forward<V>(visitor)(*as<CustomLayer>()); - case LayerType::FillExtrusion: - return std::forward<V>(visitor)(*as<FillExtrusionLayer>()); - case LayerType::Heatmap: - return std::forward<V>(visitor)(*as<HeatmapLayer>()); - } - - // Not reachable, but placate GCC. - assert(false); - throw new std::runtime_error("unknown layer type"); - } - LayerType getType() const; std::string getID() const; + // Source + std::string getSourceID() const; + std::string getSourceLayer() const; + void setSourceLayer(const std::string& sourceLayer); + + // Filter + const Filter& getFilter() const; + void setFilter(const Filter&); // Visibility VisibilityType getVisibility() const; - virtual void setVisibility(VisibilityType) = 0; + void setVisibility(VisibilityType); // Zoom range float getMinZoom() const; float getMaxZoom() const; - virtual void setMinZoom(float) = 0; - virtual void setMaxZoom(float) = 0; + void setMinZoom(float); + void setMaxZoom(float); // Dynamic properties virtual optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) = 0; @@ -124,21 +93,25 @@ public: optional<conversion::Error> setVisibility(const conversion::Convertible& value); // Private implementation + // TODO : We should not have public mutable data members. class Impl; Immutable<Impl> baseImpl; - Layer(Immutable<Impl>); - // Create a layer, copying all properties except id and paint properties from this layer. virtual std::unique_ptr<Layer> cloneRef(const std::string& id) const = 0; - LayerObserver* observer = nullptr; + void setObserver(LayerObserver*); // For use in SDK bindings, which store a reference to a platform-native peer // object here, so that separately-obtained references to this object share // identical platform-native peers. util::peer peer; +protected: + Layer(Immutable<Impl>); + virtual Mutable<Impl> mutableBaseImpl() const = 0; + + LayerObserver* observer = nullptr; }; } // namespace style diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index ef01ea41be..7d7753cbff 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -19,13 +19,6 @@ public: BackgroundLayer(const std::string& layerID); ~BackgroundLayer() final; - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -58,6 +51,9 @@ public: Mutable<Impl> mutableImpl() const; BackgroundLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index 0f8d1c0c13..909412dbab 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -19,21 +19,6 @@ public: CircleLayer(const std::string& layerID, const std::string& sourceID); ~CircleLayer() final; - // Source - const std::string& getSourceID() const; - const std::string& getSourceLayer() const; - void setSourceLayer(const std::string& sourceLayer); - - void setFilter(const Filter&); - const Filter& getFilter() const; - - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -114,6 +99,9 @@ public: Mutable<Impl> mutableImpl() const; CircleLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 4b4c770489..4ae59dfae3 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -68,13 +68,6 @@ public: ~CustomLayer() final; - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -88,10 +81,9 @@ public: std::unique_ptr<Layer> cloneRef(const std::string& id) const final; CustomLayer(const CustomLayer&) = delete; -}; -template <> -bool Layer::is<CustomLayer>() const; + Mutable<Layer::Impl> mutableBaseImpl() const final; +}; } // 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 d30ffa26da..8798738d90 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -19,21 +19,6 @@ public: FillExtrusionLayer(const std::string& layerID, const std::string& sourceID); ~FillExtrusionLayer() final; - // Source - const std::string& getSourceID() const; - const std::string& getSourceLayer() const; - void setSourceLayer(const std::string& sourceLayer); - - void setFilter(const Filter&); - const Filter& getFilter() const; - - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -90,6 +75,9 @@ public: Mutable<Impl> mutableImpl() const; FillExtrusionLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 25c46d312f..033b451abc 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -19,21 +19,6 @@ public: FillLayer(const std::string& layerID, const std::string& sourceID); ~FillLayer() final; - // Source - const std::string& getSourceID() const; - const std::string& getSourceLayer() const; - void setSourceLayer(const std::string& sourceLayer); - - void setFilter(const Filter&); - const Filter& getFilter() const; - - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -90,6 +75,9 @@ public: Mutable<Impl> mutableImpl() const; FillLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 347bb8a4aa..2315eac3f2 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -20,21 +20,6 @@ public: HeatmapLayer(const std::string& layerID, const std::string& sourceID); ~HeatmapLayer() final; - // Source - const std::string& getSourceID() const; - const std::string& getSourceLayer() const; - void setSourceLayer(const std::string& sourceLayer); - - void setFilter(const Filter&); - const Filter& getFilter() const; - - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -79,6 +64,9 @@ public: Mutable<Impl> mutableImpl() const; HeatmapLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index 697d4c71ad..4c18b5ed89 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -19,16 +19,6 @@ public: HillshadeLayer(const std::string& layerID, const std::string& sourceID); ~HillshadeLayer() final; - // Source - const std::string& getSourceID() const; - - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -79,6 +69,9 @@ public: Mutable<Impl> mutableImpl() const; HillshadeLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 9d595d2035..f6dd08000a 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -35,25 +35,6 @@ public: <% } -%> ~<%- camelize(type) %>Layer() final; -<% if (type !== 'background') { -%> - // Source - const std::string& getSourceID() const; -<% if (type !== 'raster' && type !== 'hillshade') { -%> - const std::string& getSourceLayer() const; - void setSourceLayer(const std::string& sourceLayer); - - void setFilter(const Filter&); - const Filter& getFilter() const; -<% } -%> - -<% } -%> - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -86,6 +67,9 @@ public: Mutable<Impl> mutableImpl() const; <%- camelize(type) %>Layer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 1e55561bbd..0e1d026e74 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -22,21 +22,6 @@ public: LineLayer(const std::string& layerID, const std::string& sourceID); ~LineLayer() final; - // Source - const std::string& getSourceID() const; - const std::string& getSourceLayer() const; - void setSourceLayer(const std::string& sourceLayer); - - void setFilter(const Filter&); - const Filter& getFilter() const; - - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -135,6 +120,9 @@ public: Mutable<Impl> mutableImpl() const; LineLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index b1c716c17f..2d10d65914 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -19,16 +19,6 @@ public: RasterLayer(const std::string& layerID, const std::string& sourceID); ~RasterLayer() final; - // Source - const std::string& getSourceID() const; - - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -91,6 +81,9 @@ public: Mutable<Impl> mutableImpl() const; RasterLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 6d82e5df85..b75a943be0 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -21,21 +21,6 @@ public: SymbolLayer(const std::string& layerID, const std::string& sourceID); ~SymbolLayer() final; - // Source - const std::string& getSourceID() const; - const std::string& getSourceLayer() const; - void setSourceLayer(const std::string& sourceLayer); - - void setFilter(const Filter&); - const Filter& getFilter() const; - - // Visibility - void setVisibility(VisibilityType) final; - - // Zoom range - void setMinZoom(float) final; - void setMaxZoom(float) final; - // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; @@ -284,6 +269,9 @@ public: Mutable<Impl> mutableImpl() const; SymbolLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + +protected: + Mutable<Layer::Impl> mutableBaseImpl() const final; }; template <> diff --git a/include/mbgl/util/immutable.hpp b/include/mbgl/util/immutable.hpp index eb26c0d282..b4117166dd 100644 --- a/include/mbgl/util/immutable.hpp +++ b/include/mbgl/util/immutable.hpp @@ -39,6 +39,7 @@ private: template <class S> friend class Immutable; template <class S, class... Args> friend Mutable<S> makeMutable(Args&&...); + template <class S, class U> friend Mutable<S> staticMutableCast(const Mutable<U>&); }; template <class T, class... Args> @@ -46,6 +47,11 @@ Mutable<T> makeMutable(Args&&... args) { return Mutable<T>(std::make_shared<T>(std::forward<Args>(args)...)); } +template <class S, class U> +Mutable<S> staticMutableCast(const Mutable<U>& u) { + return Mutable<S>(std::static_pointer_cast<S>(u.ptr)); +} + /** * `Immutable<T>` is a non-nullable shared reference to a `const T`. Construction requires * a transfer of unique ownership from a `Mutable<T>`; once constructed it has the same behavior |