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.
This commit is contained in:
Mikhail Pozdnyakov
2018-10-25 16:15:31 +03:00
parent fdd8b54900
commit 7a9461a8d4
30 changed files with 203 additions and 929 deletions

View File

@@ -24,10 +24,44 @@ std::string Layer::getID() const {
return baseImpl->id;
}
std::string Layer::getSourceID() const {
return baseImpl->source;
}
std::string Layer::getSourceLayer() const {
return baseImpl->sourceLayer;
}
void Layer::setSourceLayer(const std::string& sourceLayer) {
auto impl_ = mutableBaseImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const Filter& Layer::getFilter() const {
return baseImpl->filter;
}
void Layer::setFilter(const Filter& filter) {
auto impl_ = mutableBaseImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
VisibilityType Layer::getVisibility() const {
return baseImpl->visibility;
}
void Layer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableBaseImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
float Layer::getMinZoom() const {
return baseImpl->minZoom;
}
@@ -36,6 +70,20 @@ float Layer::getMaxZoom() const {
return baseImpl->maxZoom;
}
void Layer::setMinZoom(float minZoom) {
auto impl_ = mutableBaseImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void Layer::setMaxZoom(float maxZoom) {
auto impl_ = mutableBaseImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void Layer::setObserver(LayerObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver;
}

View File

@@ -42,34 +42,6 @@ std::unique_ptr<Layer> BackgroundLayer::cloneRef(const std::string& id_) const {
void BackgroundLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
// Visibility
void BackgroundLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void BackgroundLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void BackgroundLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
@@ -294,5 +266,9 @@ optional<Error> BackgroundLayer::setLayoutProperty(const std::string& name, cons
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> BackgroundLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -42,62 +42,6 @@ std::unique_ptr<Layer> CircleLayer::cloneRef(const std::string& id_) const {
void CircleLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
// Source
const std::string& CircleLayer::getSourceID() const {
return impl().source;
}
void CircleLayer::setSourceLayer(const std::string& sourceLayer) {
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& CircleLayer::getSourceLayer() const {
return impl().sourceLayer;
}
// Filter
void CircleLayer::setFilter(const Filter& filter) {
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
const Filter& CircleLayer::getFilter() const {
return impl().filter;
}
// Visibility
void CircleLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void CircleLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void CircleLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
@@ -739,5 +683,9 @@ optional<Error> CircleLayer::setLayoutProperty(const std::string& name, const Co
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> CircleLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -25,31 +25,6 @@ std::unique_ptr<Layer> CustomLayer::cloneRef(const std::string&) const {
return nullptr;
}
// Visibility
void CustomLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void CustomLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void CustomLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}
using namespace conversion;
optional<Error> CustomLayer::setPaintProperty(const std::string&, const Convertible&) {
@@ -60,6 +35,10 @@ optional<Error> CustomLayer::setLayoutProperty(const std::string&, const Convert
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> CustomLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
template <>
bool Layer::is<CustomLayer>() const {
return getType() == LayerType::Custom;

View File

@@ -42,62 +42,6 @@ std::unique_ptr<Layer> FillExtrusionLayer::cloneRef(const std::string& id_) cons
void FillExtrusionLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
// Source
const std::string& FillExtrusionLayer::getSourceID() const {
return impl().source;
}
void FillExtrusionLayer::setSourceLayer(const std::string& sourceLayer) {
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& FillExtrusionLayer::getSourceLayer() const {
return impl().sourceLayer;
}
// Filter
void FillExtrusionLayer::setFilter(const Filter& filter) {
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
const Filter& FillExtrusionLayer::getFilter() const {
return impl().filter;
}
// Visibility
void FillExtrusionLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void FillExtrusionLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void FillExtrusionLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
@@ -541,5 +485,9 @@ optional<Error> FillExtrusionLayer::setLayoutProperty(const std::string& name, c
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> FillExtrusionLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -42,62 +42,6 @@ std::unique_ptr<Layer> FillLayer::cloneRef(const std::string& id_) const {
void FillLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
// Source
const std::string& FillLayer::getSourceID() const {
return impl().source;
}
void FillLayer::setSourceLayer(const std::string& sourceLayer) {
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& FillLayer::getSourceLayer() const {
return impl().sourceLayer;
}
// Filter
void FillLayer::setFilter(const Filter& filter) {
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
const Filter& FillLayer::getFilter() const {
return impl().filter;
}
// Visibility
void FillLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void FillLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void FillLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
@@ -541,5 +485,9 @@ optional<Error> FillLayer::setLayoutProperty(const std::string& name, const Conv
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> FillLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -42,62 +42,6 @@ std::unique_ptr<Layer> HeatmapLayer::cloneRef(const std::string& id_) const {
void HeatmapLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
// Source
const std::string& HeatmapLayer::getSourceID() const {
return impl().source;
}
void HeatmapLayer::setSourceLayer(const std::string& sourceLayer) {
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& HeatmapLayer::getSourceLayer() const {
return impl().sourceLayer;
}
// Filter
void HeatmapLayer::setFilter(const Filter& filter) {
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
const Filter& HeatmapLayer::getFilter() const {
return impl().filter;
}
// Visibility
void HeatmapLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void HeatmapLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void HeatmapLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
@@ -426,5 +370,9 @@ optional<Error> HeatmapLayer::setLayoutProperty(const std::string& name, const C
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> HeatmapLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -42,40 +42,6 @@ std::unique_ptr<Layer> HillshadeLayer::cloneRef(const std::string& id_) const {
void HillshadeLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
// Source
const std::string& HillshadeLayer::getSourceID() const {
return impl().source;
}
// Visibility
void HillshadeLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void HillshadeLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void HillshadeLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
@@ -451,5 +417,9 @@ optional<Error> HillshadeLayer::setLayoutProperty(const std::string& name, const
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> HillshadeLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -59,66 +59,6 @@ void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer<rapidjs
}
<% } -%>
<% if (type !== 'background') { -%>
// Source
const std::string& <%- camelize(type) %>Layer::getSourceID() const {
return impl().source;
}
<% if (type !== 'raster' && type !== 'hillshade') { -%>
void <%- camelize(type) %>Layer::setSourceLayer(const std::string& sourceLayer) {
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& <%- camelize(type) %>Layer::getSourceLayer() const {
return impl().sourceLayer;
}
// Filter
void <%- camelize(type) %>Layer::setFilter(const Filter& filter) {
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
const Filter& <%- camelize(type) %>Layer::getFilter() const {
return impl().filter;
}
<% } -%>
<% } -%>
// Visibility
void <%- camelize(type) %>Layer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void <%- camelize(type) %>Layer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void <%- camelize(type) %>Layer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
<% for (const property of layoutProperties) { -%>
@@ -316,5 +256,9 @@ optional<Error> <%- camelize(type) %>Layer::setLayoutProperty(const std::string&
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> <%- camelize(type) %>Layer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -43,62 +43,6 @@ void LineLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>
layout.stringify(writer);
}
// Source
const std::string& LineLayer::getSourceID() const {
return impl().source;
}
void LineLayer::setSourceLayer(const std::string& sourceLayer) {
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& LineLayer::getSourceLayer() const {
return impl().sourceLayer;
}
// Filter
void LineLayer::setFilter(const Filter& filter) {
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
const Filter& LineLayer::getFilter() const {
return impl().filter;
}
// Visibility
void LineLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void LineLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void LineLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
PropertyValue<LineCapType> LineLayer::getDefaultLineCap() {
@@ -880,5 +824,9 @@ optional<Error> LineLayer::setLayoutProperty(const std::string& name, const Conv
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> LineLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -42,40 +42,6 @@ std::unique_ptr<Layer> RasterLayer::cloneRef(const std::string& id_) const {
void RasterLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
// Source
const std::string& RasterLayer::getSourceID() const {
return impl().source;
}
// Visibility
void RasterLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void RasterLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void RasterLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
@@ -540,5 +506,9 @@ optional<Error> RasterLayer::setLayoutProperty(const std::string& name, const Co
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> RasterLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -43,62 +43,6 @@ void SymbolLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffe
layout.stringify(writer);
}
// Source
const std::string& SymbolLayer::getSourceID() const {
return impl().source;
}
void SymbolLayer::setSourceLayer(const std::string& sourceLayer) {
auto impl_ = mutableImpl();
impl_->sourceLayer = sourceLayer;
baseImpl = std::move(impl_);
}
const std::string& SymbolLayer::getSourceLayer() const {
return impl().sourceLayer;
}
// Filter
void SymbolLayer::setFilter(const Filter& filter) {
auto impl_ = mutableImpl();
impl_->filter = filter;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
const Filter& SymbolLayer::getFilter() const {
return impl().filter;
}
// Visibility
void SymbolLayer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
auto impl_ = mutableImpl();
impl_->visibility = value;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Zoom range
void SymbolLayer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
void SymbolLayer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
observer->onLayerChanged(*this);
}
// Layout properties
PropertyValue<SymbolPlacementType> SymbolLayer::getDefaultSymbolPlacement() {
@@ -2030,5 +1974,9 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co
return Error { "layer doesn't support this property" };
}
Mutable<Layer::Impl> SymbolLayer::mutableBaseImpl() const {
return staticMutableCast<Layer::Impl>(mutableImpl());
}
} // namespace style
} // namespace mbgl

View File

@@ -146,28 +146,13 @@ void Style::Impl::addSource(std::unique_ptr<Source> source) {
sources.add(std::move(source));
}
struct SourceIdUsageEvaluator {
const std::string& sourceId;
bool operator()(BackgroundLayer&) { return false; }
bool operator()(CustomLayer&) { return false; }
template <class LayerType>
bool operator()(LayerType& layer) {
return layer.getSourceID() == sourceId;
}
};
std::unique_ptr<Source> Style::Impl::removeSource(const std::string& id) {
// Check if source is in use
SourceIdUsageEvaluator sourceIdEvaluator {id};
auto layerIt = std::find_if(layers.begin(), layers.end(), [&](const auto& layer) {
return layer->accept(sourceIdEvaluator);
});
if (layerIt != layers.end()) {
Log::Warning(Event::General, "Source '%s' is in use, cannot remove", id.c_str());
return nullptr;
for (const auto& layer: layers) {
if (layer->getSourceID() == id) {
Log::Warning(Event::General, "Source '%s' is in use, cannot remove", id.c_str());
return nullptr;
}
}
std::unique_ptr<Source> source = sources.remove(id);