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/annotation_tile.cpp | |
parent | 2cc330463d11a9767cbee4a028804e026c76d63b (diff) | |
download | qtlocation-mapboxgl-7b90af5d3580bd57cd4280173c1d2b0ee542b89d.tar.gz |
[core] always return owning pointers for GeometryTileData::getLayer()
Diffstat (limited to 'src/mbgl/annotation/annotation_tile.cpp')
-rw-r--r-- | src/mbgl/annotation/annotation_tile.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
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 |