Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Give Style ownership of new layers
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Oct 19, 2016
1 parent a4c44bc commit e43fbf4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class Map : private util::noncopyable {
// Layers
std::vector<style::Layer*> getLayers();
style::Layer* getLayer(const std::string& layerID);
void setLayers(std::vector<style::Layer*>&);
void setLayers(std::vector<std::unique_ptr<style::Layer>>);
void addLayer(std::unique_ptr<style::Layer>, const optional<std::string>& beforeLayerID = {});
void removeLayer(const std::string& layerID);

Expand Down
6 changes: 3 additions & 3 deletions platform/darwin/src/MGLStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ - (void)removeSource:(MGLSource *)source
}

- (void)setLayers:(NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *)layers {
std::vector<mbgl::style::Layer *> rawLayers;
std::vector<std::unique_ptr<mbgl::style::Layer>> rawLayers;
rawLayers.reserve(layers.count);
for (MGLStyleLayer *layer in layers.reverseObjectEnumerator) {
rawLayers.push_back(layer.layer);
rawLayers.push_back(std::unique_ptr<mbgl::style::Layer>(layer.layer));
}
self.mapView.mbglMap->setLayers(rawLayers);
self.mapView.mbglMap->setLayers(std::move(rawLayers));
}

- (NSUInteger)countOfLayers
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,10 @@ style::Layer* Map::getLayer(const std::string& layerID) {
return nullptr;
}

void Map::setLayers(std::vector<style::Layer*>& layers) {
void Map::setLayers(std::vector<std::unique_ptr<style::Layer>> layers) {
impl->view.activate();

impl->style->setLayers(layers);
impl->style->setLayers(std::move(layers));
impl->updateFlags |= Update::Classes;
impl->asyncUpdate.send();

Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ Layer* Style::getLayer(const std::string& id) const {
return it != layers.end() ? it->get() : nullptr;
}

void Style::setLayers(std::vector<Layer*>& newLayers) {
void Style::setLayers(std::vector<std::unique_ptr<style::Layer>> newLayers) {
layers.empty();
for (auto& layer : newLayers) {
addLayer(std::unique_ptr<Layer>(layer));
addLayer(std::move(layer));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Style : public GlyphAtlasObserver,
std::vector<const Layer*> getLayers() const;
std::vector<Layer*> getLayers();
Layer* getLayer(const std::string& id) const;
void setLayers(std::vector<Layer*>&);
void setLayers(std::vector<std::unique_ptr<style::Layer>>);
Layer* addLayer(std::unique_ptr<Layer>,
optional<std::string> beforeLayerID = {});
void removeLayer(const std::string& layerID);
Expand Down

0 comments on commit e43fbf4

Please sign in to comment.