From 280b80677797ceda07ddf75f567dd3613f285319 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Wed, 18 Mar 2020 16:46:24 +0200 Subject: [PATCH] [core] Move generic setProperty() parts to the base Layer class --- include/mbgl/gl/custom_layer.hpp | 16 ++++++---------- include/mbgl/style/layer.hpp | 9 ++++++--- include/mbgl/style/layers/background_layer.hpp | 12 ++++++------ include/mbgl/style/layers/circle_layer.hpp | 12 ++++++------ .../mbgl/style/layers/fill_extrusion_layer.hpp | 12 ++++++------ include/mbgl/style/layers/fill_layer.hpp | 12 ++++++------ include/mbgl/style/layers/heatmap_layer.hpp | 12 ++++++------ include/mbgl/style/layers/hillshade_layer.hpp | 12 ++++++------ include/mbgl/style/layers/layer.hpp.ejs | 12 ++++++------ include/mbgl/style/layers/line_layer.hpp | 12 ++++++------ include/mbgl/style/layers/raster_layer.hpp | 12 ++++++------ include/mbgl/style/layers/symbol_layer.hpp | 12 ++++++------ src/mbgl/gl/custom_layer.cpp | 2 +- src/mbgl/style/layer.cpp | 7 +++++++ src/mbgl/style/layers/background_layer.cpp | 7 ++----- src/mbgl/style/layers/circle_layer.cpp | 7 ++----- src/mbgl/style/layers/fill_extrusion_layer.cpp | 7 ++----- src/mbgl/style/layers/fill_layer.cpp | 7 ++----- src/mbgl/style/layers/heatmap_layer.cpp | 7 ++----- src/mbgl/style/layers/hillshade_layer.cpp | 7 ++----- src/mbgl/style/layers/layer.cpp.ejs | 7 ++----- src/mbgl/style/layers/line_layer.cpp | 7 ++----- src/mbgl/style/layers/raster_layer.cpp | 7 ++----- src/mbgl/style/layers/symbol_layer.cpp | 7 ++----- 24 files changed, 100 insertions(+), 124 deletions(-) diff --git a/include/mbgl/gl/custom_layer.hpp b/include/mbgl/gl/custom_layer.hpp index 5dce48498..8b60af5d7 100644 --- a/include/mbgl/gl/custom_layer.hpp +++ b/include/mbgl/gl/custom_layer.hpp @@ -66,21 +66,17 @@ public: CustomLayer(const std::string& id, std::unique_ptr host); + CustomLayer(const CustomLayer&) = delete; ~CustomLayer() final; - - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - StyleProperty getProperty(const std::string&) const final; - // Private implementation - class Impl; const Impl& impl() const; - Mutable mutableImpl() const; + +private: + optional setPropertyInternal(const std::string& name, + const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string&) const final; std::unique_ptr cloneRef(const std::string& id) const final; - - CustomLayer(const CustomLayer&) = delete; - Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 204cb9c69..10baf1960 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -110,8 +110,7 @@ public: void setMaxZoom(float); // Dynamic properties - virtual optional setProperty(const std::string& name, const conversion::Convertible& value) = 0; - optional setVisibility(const conversion::Convertible& value); + optional setProperty(const std::string& name, const conversion::Convertible& value); virtual StyleProperty getProperty(const std::string&) const = 0; virtual Value serialize() const; @@ -142,9 +141,13 @@ public: protected: virtual Mutable mutableBaseImpl() const = 0; void serializeProperty(Value&, const StyleProperty&, const char* propertyName, bool isPaint) const; - + virtual optional setPropertyInternal(const std::string& name, + const conversion::Convertible& value) = 0; LayerObserver* observer; mapbox::base::WeakPtrFactory weakFactory {this}; + +private: + optional setVisibility(const conversion::Convertible& value); }; } // namespace style diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 7f4861834..9fdfd3ac9 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -20,12 +20,6 @@ public: BackgroundLayer(const std::string& layerID); ~BackgroundLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Paint properties static PropertyValue getDefaultBackgroundColor(); @@ -56,6 +50,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index 1ad16cd03..dd5b67400 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -20,12 +20,6 @@ public: CircleLayer(const std::string& layerID, const std::string& sourceID); ~CircleLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Paint properties static PropertyValue getDefaultCircleBlur(); @@ -104,6 +98,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index ef692e570..ca33c6c3f 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -20,12 +20,6 @@ public: FillExtrusionLayer(const std::string& layerID, const std::string& sourceID); ~FillExtrusionLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Paint properties static PropertyValue getDefaultFillExtrusionBase(); @@ -86,6 +80,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 174758a78..4a1f09cca 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -20,12 +20,6 @@ public: FillLayer(const std::string& layerID, const std::string& sourceID); ~FillLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Layout properties static PropertyValue getDefaultFillSortKey(); @@ -86,6 +80,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 0b740c470..588aaa81d 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -21,12 +21,6 @@ public: HeatmapLayer(const std::string& layerID, const std::string& sourceID); ~HeatmapLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Paint properties static ColorRampPropertyValue getDefaultHeatmapColor(); @@ -69,6 +63,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index 184e7c390..c501e80b8 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -20,12 +20,6 @@ public: HillshadeLayer(const std::string& layerID, const std::string& sourceID); ~HillshadeLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Paint properties static PropertyValue getDefaultHillshadeAccentColor(); @@ -74,6 +68,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index aecbe2560..9cdd74737 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -36,12 +36,6 @@ public: <% } -%> ~<%- camelize(type) %>Layer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - <% if (layoutProperties.length) { -%> // Layout properties @@ -72,6 +66,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index cef18d9fa..2186f1666 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -23,12 +23,6 @@ public: LineLayer(const std::string& layerID, const std::string& sourceID); ~LineLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Layout properties static PropertyValue getDefaultLineCap(); @@ -129,6 +123,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index b1aa3a65b..df82c9366 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -20,12 +20,6 @@ public: RasterLayer(const std::string& layerID, const std::string& sourceID); ~RasterLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Paint properties static PropertyValue getDefaultRasterBrightnessMax(); @@ -86,6 +80,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index 2cffd2294..40d16dedf 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -22,12 +22,6 @@ public: SymbolLayer(const std::string& layerID, const std::string& sourceID); ~SymbolLayer() final; - // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value) final; - - StyleProperty getProperty(const std::string& name) const final; - Value serialize() const final; - // Layout properties static PropertyValue getDefaultIconAllowOverlap(); @@ -290,6 +284,12 @@ public: std::unique_ptr cloneRef(const std::string& id) const final; protected: + // Dynamic properties + optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + + StyleProperty getProperty(const std::string& name) const final; + Value serialize() const final; + Mutable mutableBaseImpl() const final; }; diff --git a/src/mbgl/gl/custom_layer.cpp b/src/mbgl/gl/custom_layer.cpp index 456467e90..bb87868d7 100644 --- a/src/mbgl/gl/custom_layer.cpp +++ b/src/mbgl/gl/custom_layer.cpp @@ -38,7 +38,7 @@ std::unique_ptr CustomLayer::cloneRef(const std::string&) const { using namespace conversion; -optional CustomLayer::setProperty(const std::string&, const Convertible&) { +optional CustomLayer::setPropertyInternal(const std::string&, const Convertible&) { return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp index 3183d84ab..efbc91434 100644 --- a/src/mbgl/style/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -143,6 +143,13 @@ void Layer::setObserver(LayerObserver* observer_) { observer = observer_ ? observer_ : &nullObserver; } +optional Layer::setProperty(const std::string& name, const conversion::Convertible& value) { + optional error = setPropertyInternal(name, value); + if (!error) return error; // Successfully set by the derived class implementation. + if (name == "visibility") return setVisibility(value); + return error; // Must be Error{"layer doesn't support this property"}. +} + optional Layer::setVisibility(const conversion::Convertible& value) { using namespace conversion; diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 0b7f0afe4..d3dd02f8a 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -211,12 +211,9 @@ Value BackgroundLayer::serialize() const { return result; } -optional BackgroundLayer::setProperty(const std::string& name, const Convertible& value) { +optional BackgroundLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index ca2f93306..959f9447b 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -491,12 +491,9 @@ Value CircleLayer::serialize() const { return result; } -optional CircleLayer::setProperty(const std::string& name, const Convertible& value) { +optional CircleLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index c9819f66f..b9f4e4fa6 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -386,12 +386,9 @@ Value FillExtrusionLayer::serialize() const { return result; } -optional FillExtrusionLayer::setProperty(const std::string& name, const Convertible& value) { +optional FillExtrusionLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 914a23d96..b6cc1eb50 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -371,12 +371,9 @@ Value FillLayer::serialize() const { return result; } -optional FillLayer::setProperty(const std::string& name, const Convertible& value) { +optional FillLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp index bfac173d6..54add7203 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -283,12 +283,9 @@ Value HeatmapLayer::serialize() const { return result; } -optional HeatmapLayer::setProperty(const std::string& name, const Convertible& value) { +optional HeatmapLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index bfbd3d1d1..04c793575 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -316,12 +316,9 @@ Value HillshadeLayer::serialize() const { return result; } -optional HillshadeLayer::setProperty(const std::string& name, const Convertible& value) { +optional HillshadeLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index a17b9e803..bfdcd6e05 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -271,12 +271,9 @@ Value <%- camelize(type) %>Layer::serialize() const { return result; } -optional <%- camelize(type) %>Layer::setProperty(const std::string& name, const Convertible& value) { +optional <%- camelize(type) %>Layer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index 69c0af095..94ec58293 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -588,12 +588,9 @@ Value LineLayer::serialize() const { return result; } -optional LineLayer::setProperty(const std::string& name, const Convertible& value) { +optional LineLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index 3222eebd7..66ad87388 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -386,12 +386,9 @@ Value RasterLayer::serialize() const { return result; } -optional RasterLayer::setProperty(const std::string& name, const Convertible& value) { +optional RasterLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second); diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 7154bffff..70f731f30 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -1376,12 +1376,9 @@ Value SymbolLayer::serialize() const { return result; } -optional SymbolLayer::setProperty(const std::string& name, const Convertible& value) { +optional SymbolLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - if (name == "visibility") return setVisibility(value); - return Error{"layer doesn't support this property"}; - } + if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; auto property = static_cast(it->second);