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

@@ -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);