From c2a5894f2dbe9982830066ab9347b059e6e7d845 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 25 Apr 2017 18:20:26 -0700 Subject: [core] Immutable Impls --- src/mbgl/style/layers/line_layer.cpp | 252 +++++++++++++++++++++++------------ 1 file changed, 165 insertions(+), 87 deletions(-) (limited to 'src/mbgl/style/layers/line_layer.cpp') diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index 7f1575aad5..8b9085b48c 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -3,33 +3,34 @@ #include #include #include +#include namespace mbgl { namespace style { LineLayer::LineLayer(const std::string& layerID, const std::string& sourceID) - : Layer(LayerType::Line, std::make_unique()) - , impl(static_cast(baseImpl.get())) { - impl->id = layerID; - impl->source = sourceID; + : Layer(makeMutable(LayerType::Line, layerID, sourceID)) { } -LineLayer::LineLayer(const Impl& other) - : Layer(LayerType::Line, std::make_unique(other)) - , impl(static_cast(baseImpl.get())) { +LineLayer::LineLayer(Immutable impl_) + : Layer(std::move(impl_)) { } LineLayer::~LineLayer() = default; -std::unique_ptr LineLayer::Impl::clone() const { - return std::make_unique(*this); +const LineLayer::Impl& LineLayer::impl() const { + return static_cast(*baseImpl); } -std::unique_ptr LineLayer::Impl::cloneRef(const std::string& id_) const { - auto result = std::make_unique(*this); - result->impl->id = id_; - result->impl->cascading = LinePaintProperties::Cascading(); - return std::move(result); +Mutable LineLayer::mutableImpl() const { + return makeMutable(impl()); +} + +std::unique_ptr LineLayer::cloneRef(const std::string& id_) const { + auto impl_ = mutableImpl(); + impl_->id = id_; + impl_->cascading = LinePaintProperties::Cascading(); + return std::make_unique(std::move(impl_)); } void LineLayer::Impl::stringifyLayout(rapidjson::Writer& writer) const { @@ -39,26 +40,55 @@ void LineLayer::Impl::stringifyLayout(rapidjson::Writer // Source const std::string& LineLayer::getSourceID() const { - return impl->source; + return impl().source; } void LineLayer::setSourceLayer(const std::string& sourceLayer) { - impl->sourceLayer = sourceLayer; + auto impl_ = mutableImpl(); + impl_->sourceLayer = sourceLayer; + baseImpl = std::move(impl_); } const std::string& LineLayer::getSourceLayer() const { - return impl->sourceLayer; + return impl().sourceLayer; } // Filter void LineLayer::setFilter(const Filter& filter) { - impl->filter = filter; - impl->observer->onLayerFilterChanged(*this); + auto impl_ = mutableImpl(); + impl_->filter = filter; + baseImpl = std::move(impl_); + observer->onLayerFilterChanged(*this); } const Filter& LineLayer::getFilter() const { - return impl->filter; + return impl().filter; +} + +// Visibility + +void LineLayer::setVisibility(VisibilityType value) { + if (value == getVisibility()) + return; + auto impl_ = mutableImpl(); + impl_->visibility = value; + baseImpl = std::move(impl_); + observer->onLayerVisibilityChanged(*this); +} + +// Zoom range + +void LineLayer::setMinZoom(float minZoom) { + auto impl_ = mutableImpl(); + impl_->minZoom = minZoom; + baseImpl = std::move(impl_); +} + +void LineLayer::setMaxZoom(float maxZoom) { + auto impl_ = mutableImpl(); + impl_->maxZoom = maxZoom; + baseImpl = std::move(impl_); } // Layout properties @@ -68,56 +98,64 @@ PropertyValue LineLayer::getDefaultLineCap() { } PropertyValue LineLayer::getLineCap() const { - return impl->layout.unevaluated.get(); + return impl().layout.unevaluated.get(); } void LineLayer::setLineCap(PropertyValue value) { if (value == getLineCap()) return; - impl->layout.unevaluated.get() = value; - impl->observer->onLayerLayoutPropertyChanged(*this, "line-cap"); + auto impl_ = mutableImpl(); + impl_->layout.unevaluated.get() = value; + baseImpl = std::move(impl_); + observer->onLayerLayoutPropertyChanged(*this, "line-cap"); } PropertyValue LineLayer::getDefaultLineJoin() { return LineJoin::defaultValue(); } PropertyValue LineLayer::getLineJoin() const { - return impl->layout.unevaluated.get(); + return impl().layout.unevaluated.get(); } void LineLayer::setLineJoin(PropertyValue value) { if (value == getLineJoin()) return; - impl->layout.unevaluated.get() = value; - impl->observer->onLayerLayoutPropertyChanged(*this, "line-join"); + auto impl_ = mutableImpl(); + impl_->layout.unevaluated.get() = value; + baseImpl = std::move(impl_); + observer->onLayerLayoutPropertyChanged(*this, "line-join"); } PropertyValue LineLayer::getDefaultLineMiterLimit() { return LineMiterLimit::defaultValue(); } PropertyValue LineLayer::getLineMiterLimit() const { - return impl->layout.unevaluated.get(); + return impl().layout.unevaluated.get(); } void LineLayer::setLineMiterLimit(PropertyValue value) { if (value == getLineMiterLimit()) return; - impl->layout.unevaluated.get() = value; - impl->observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit"); + auto impl_ = mutableImpl(); + impl_->layout.unevaluated.get() = value; + baseImpl = std::move(impl_); + observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit"); } PropertyValue LineLayer::getDefaultLineRoundLimit() { return LineRoundLimit::defaultValue(); } PropertyValue LineLayer::getLineRoundLimit() const { - return impl->layout.unevaluated.get(); + return impl().layout.unevaluated.get(); } void LineLayer::setLineRoundLimit(PropertyValue value) { if (value == getLineRoundLimit()) return; - impl->layout.unevaluated.get() = value; - impl->observer->onLayerLayoutPropertyChanged(*this, "line-round-limit"); + auto impl_ = mutableImpl(); + impl_->layout.unevaluated.get() = value; + baseImpl = std::move(impl_); + observer->onLayerLayoutPropertyChanged(*this, "line-round-limit"); } // Paint properties @@ -127,26 +165,30 @@ DataDrivenPropertyValue LineLayer::getDefaultLineOpacity() { } DataDrivenPropertyValue LineLayer::getLineOpacity(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineOpacity(DataDrivenPropertyValue value, const optional& klass) { if (value == getLineOpacity(klass)) return; - impl->cascading.template get().set(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); if (value.isDataDriven()) { - impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); + observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { - impl->observer->onLayerPaintPropertyChanged(*this); + observer->onLayerPaintPropertyChanged(*this); } } void LineLayer::setLineOpacityTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineOpacityTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } DataDrivenPropertyValue LineLayer::getDefaultLineColor() { @@ -154,26 +196,30 @@ DataDrivenPropertyValue LineLayer::getDefaultLineColor() { } DataDrivenPropertyValue LineLayer::getLineColor(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineColor(DataDrivenPropertyValue value, const optional& klass) { if (value == getLineColor(klass)) return; - impl->cascading.template get().set(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); if (value.isDataDriven()) { - impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); + observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { - impl->observer->onLayerPaintPropertyChanged(*this); + observer->onLayerPaintPropertyChanged(*this); } } void LineLayer::setLineColorTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineColorTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } PropertyValue> LineLayer::getDefaultLineTranslate() { @@ -181,22 +227,26 @@ PropertyValue> LineLayer::getDefaultLineTranslate() { } PropertyValue> LineLayer::getLineTranslate(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineTranslate(PropertyValue> value, const optional& klass) { if (value == getLineTranslate(klass)) return; - impl->cascading.template get().set(value, klass); - impl->observer->onLayerPaintPropertyChanged(*this); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); + observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLineTranslateTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineTranslateTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } PropertyValue LineLayer::getDefaultLineTranslateAnchor() { @@ -204,22 +254,26 @@ PropertyValue LineLayer::getDefaultLineTranslateAnchor() { } PropertyValue LineLayer::getLineTranslateAnchor(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineTranslateAnchor(PropertyValue value, const optional& klass) { if (value == getLineTranslateAnchor(klass)) return; - impl->cascading.template get().set(value, klass); - impl->observer->onLayerPaintPropertyChanged(*this); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); + observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLineTranslateAnchorTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineTranslateAnchorTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } PropertyValue LineLayer::getDefaultLineWidth() { @@ -227,22 +281,26 @@ PropertyValue LineLayer::getDefaultLineWidth() { } PropertyValue LineLayer::getLineWidth(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineWidth(PropertyValue value, const optional& klass) { if (value == getLineWidth(klass)) return; - impl->cascading.template get().set(value, klass); - impl->observer->onLayerPaintPropertyChanged(*this); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); + observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLineWidthTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineWidthTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } DataDrivenPropertyValue LineLayer::getDefaultLineGapWidth() { @@ -250,26 +308,30 @@ DataDrivenPropertyValue LineLayer::getDefaultLineGapWidth() { } DataDrivenPropertyValue LineLayer::getLineGapWidth(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineGapWidth(DataDrivenPropertyValue value, const optional& klass) { if (value == getLineGapWidth(klass)) return; - impl->cascading.template get().set(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); if (value.isDataDriven()) { - impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); + observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { - impl->observer->onLayerPaintPropertyChanged(*this); + observer->onLayerPaintPropertyChanged(*this); } } void LineLayer::setLineGapWidthTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineGapWidthTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } DataDrivenPropertyValue LineLayer::getDefaultLineOffset() { @@ -277,26 +339,30 @@ DataDrivenPropertyValue LineLayer::getDefaultLineOffset() { } DataDrivenPropertyValue LineLayer::getLineOffset(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineOffset(DataDrivenPropertyValue value, const optional& klass) { if (value == getLineOffset(klass)) return; - impl->cascading.template get().set(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); if (value.isDataDriven()) { - impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); + observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { - impl->observer->onLayerPaintPropertyChanged(*this); + observer->onLayerPaintPropertyChanged(*this); } } void LineLayer::setLineOffsetTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineOffsetTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } DataDrivenPropertyValue LineLayer::getDefaultLineBlur() { @@ -304,26 +370,30 @@ DataDrivenPropertyValue LineLayer::getDefaultLineBlur() { } DataDrivenPropertyValue LineLayer::getLineBlur(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineBlur(DataDrivenPropertyValue value, const optional& klass) { if (value == getLineBlur(klass)) return; - impl->cascading.template get().set(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); if (value.isDataDriven()) { - impl->observer->onLayerDataDrivenPaintPropertyChanged(*this); + observer->onLayerDataDrivenPaintPropertyChanged(*this); } else { - impl->observer->onLayerPaintPropertyChanged(*this); + observer->onLayerPaintPropertyChanged(*this); } } void LineLayer::setLineBlurTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineBlurTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } PropertyValue> LineLayer::getDefaultLineDasharray() { @@ -331,22 +401,26 @@ PropertyValue> LineLayer::getDefaultLineDasharray() { } PropertyValue> LineLayer::getLineDasharray(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLineDasharray(PropertyValue> value, const optional& klass) { if (value == getLineDasharray(klass)) return; - impl->cascading.template get().set(value, klass); - impl->observer->onLayerPaintPropertyChanged(*this); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); + observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLineDasharrayTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLineDasharrayTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } PropertyValue LineLayer::getDefaultLinePattern() { @@ -354,22 +428,26 @@ PropertyValue LineLayer::getDefaultLinePattern() { } PropertyValue LineLayer::getLinePattern(const optional& klass) const { - return impl->cascading.template get().get(klass); + return impl().cascading.template get().get(klass); } void LineLayer::setLinePattern(PropertyValue value, const optional& klass) { if (value == getLinePattern(klass)) return; - impl->cascading.template get().set(value, klass); - impl->observer->onLayerPaintPropertyChanged(*this); + auto impl_ = mutableImpl(); + impl_->cascading.template get().set(value, klass); + baseImpl = std::move(impl_); + observer->onLayerPaintPropertyChanged(*this); } void LineLayer::setLinePatternTransition(const TransitionOptions& value, const optional& klass) { - impl->cascading.template get().setTransition(value, klass); + auto impl_ = mutableImpl(); + impl_->cascading.template get().setTransition(value, klass); + baseImpl = std::move(impl_); } TransitionOptions LineLayer::getLinePatternTransition(const optional& klass) const { - return impl->cascading.template get().getTransition(klass); + return impl().cascading.template get().getTransition(klass); } } // namespace style -- cgit v1.2.1