diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-06-20 12:17:07 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-06-21 17:18:08 -0700 |
commit | 7b90af5d3580bd57cd4280173c1d2b0ee542b89d (patch) | |
tree | 157ce600a1f6397c09ffcd39918e7347e0c70b39 /src/mbgl/annotation | |
parent | 2cc330463d11a9767cbee4a028804e026c76d63b (diff) | |
download | qtlocation-mapboxgl-7b90af5d3580bd57cd4280173c1d2b0ee542b89d.tar.gz |
[core] always return owning pointers for GeometryTileData::getLayer()
Diffstat (limited to 'src/mbgl/annotation')
-rw-r--r-- | src/mbgl/annotation/annotation_manager.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_tile.cpp | 37 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_tile.hpp | 28 | ||||
-rw-r--r-- | src/mbgl/annotation/shape_annotation_impl.cpp | 4 |
4 files changed, 46 insertions, 27 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index bc23a94adf..58bda6052e 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -133,13 +133,13 @@ std::unique_ptr<AnnotationTileData> AnnotationManager::getTileData(const Canonic auto tileData = std::make_unique<AnnotationTileData>(); - AnnotationTileLayer& pointLayer = tileData->addLayer(PointLayerID); + auto pointLayer = tileData->addLayer(PointLayerID); LatLngBounds tileBounds(tileID); symbolTree.query(boost::geometry::index::intersects(tileBounds), boost::make_function_output_iterator([&](const auto& val){ - val->updateLayer(tileID, pointLayer); + val->updateLayer(tileID, *pointLayer); })); for (const auto& shape : shapeAnnotations) { diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp index e8c62effd8..0596d60f4f 100644 --- a/src/mbgl/annotation/annotation_tile.cpp +++ b/src/mbgl/annotation/annotation_tile.cpp @@ -66,7 +66,28 @@ GeometryCollection AnnotationTileFeature::getGeometries() const { return data->geometries; } -AnnotationTileLayer::AnnotationTileLayer(std::string name_) : name(std::move(name_)) { +class AnnotationTileLayerData { +public: + AnnotationTileLayerData(const std::string& name_) : name(name_) { + } + + const std::string name; + std::vector<std::shared_ptr<const AnnotationTileFeatureData>> features; +}; + +AnnotationTileLayer::AnnotationTileLayer(std::shared_ptr<AnnotationTileLayerData> layer_) : layer(std::move(layer_)) { +} + +std::size_t AnnotationTileLayer::featureCount() const { + return layer->features.size(); +} + +std::unique_ptr<GeometryTileFeature> AnnotationTileLayer::getFeature(std::size_t i) const { + return std::make_unique<AnnotationTileFeature>(layer->features.at(i)); +} + +std::string AnnotationTileLayer::getName() const { + return layer->name; } void AnnotationTileLayer::addFeature(const AnnotationID id, @@ -74,7 +95,7 @@ void AnnotationTileLayer::addFeature(const AnnotationID id, GeometryCollection geometries, std::unordered_map<std::string, std::string> properties) { - features.emplace_back(std::make_shared<AnnotationTileFeatureData>( + layer->features.emplace_back(std::make_shared<AnnotationTileFeatureData>( id, type, std::move(geometries), std::move(properties))); } @@ -82,17 +103,21 @@ std::unique_ptr<GeometryTileData> AnnotationTileData::clone() const { return std::make_unique<AnnotationTileData>(*this); } -const GeometryTileLayer* AnnotationTileData::getLayer(const std::string& name) const { +std::unique_ptr<GeometryTileLayer> AnnotationTileData::getLayer(const std::string& name) const { auto it = layers.find(name); if (it != layers.end()) { - return &it->second; + return std::make_unique<AnnotationTileLayer>(it->second); } return nullptr; } -AnnotationTileLayer& AnnotationTileData::addLayer(const std::string& name) { +std::unique_ptr<AnnotationTileLayer> AnnotationTileData::addLayer(const std::string& name) { // Only constructs a new layer if it doesn't yet exist, otherwise, we'll use the existing one. - return layers.emplace(name, name).first->second; + auto it = layers.find(name); + if (it == layers.end()) { + it = layers.emplace(name, std::make_shared<AnnotationTileLayerData>(name)).first; + } + return std::make_unique<AnnotationTileLayer>(it->second); } } // namespace mbgl diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp index 68a4d342ac..88505c50e3 100644 --- a/src/mbgl/annotation/annotation_tile.hpp +++ b/src/mbgl/annotation/annotation_tile.hpp @@ -36,21 +36,15 @@ private: std::shared_ptr<const AnnotationTileFeatureData> data; }; +class AnnotationTileLayerData; + class AnnotationTileLayer : public GeometryTileLayer { public: - AnnotationTileLayer(std::string); - - std::size_t featureCount() const override { - return features.size(); - } + AnnotationTileLayer(std::shared_ptr<AnnotationTileLayerData>); - std::unique_ptr<GeometryTileFeature> getFeature(std::size_t i) const override { - return std::make_unique<AnnotationTileFeature>(features.at(i)); - } - - std::string getName() const override { - return name; - } + std::size_t featureCount() const override; + std::unique_ptr<GeometryTileFeature> getFeature(std::size_t i) const override; + std::string getName() const override; void addFeature(const AnnotationID, FeatureType, @@ -58,18 +52,18 @@ public: std::unordered_map<std::string, std::string> properties = { {} }); private: - std::vector<std::shared_ptr<const AnnotationTileFeatureData>> features; - std::string name; + std::shared_ptr<AnnotationTileLayerData> layer; }; class AnnotationTileData : public GeometryTileData { public: std::unique_ptr<GeometryTileData> clone() const override; - const GeometryTileLayer* getLayer(const std::string&) const override; - AnnotationTileLayer& addLayer(const std::string&); + std::unique_ptr<GeometryTileLayer> getLayer(const std::string&) const override; + + std::unique_ptr<AnnotationTileLayer> addLayer(const std::string&); private: - std::unordered_map<std::string, AnnotationTileLayer> layers; + std::unordered_map<std::string, std::shared_ptr<AnnotationTileLayerData>> layers; }; } // namespace mbgl diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp index 05ffce382d..0c1a631ad8 100644 --- a/src/mbgl/annotation/shape_annotation_impl.cpp +++ b/src/mbgl/annotation/shape_annotation_impl.cpp @@ -38,7 +38,7 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati if (shapeTile.features.empty()) return; - AnnotationTileLayer& layer = data.addLayer(layerID); + auto layer = data.addLayer(layerID); ToGeometryCollection toGeometryCollection; ToFeatureType toFeatureType; @@ -53,7 +53,7 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati renderGeometry = fixupPolygons(renderGeometry); } - layer.addFeature(id, featureType, renderGeometry); + layer->addFeature(id, featureType, renderGeometry); } } |