summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-09-10 06:55:38 +0300
committerJulian Rex <julian.rex@mapbox.com>2019-09-09 23:55:38 -0400
commit5207a360746d7d0541e21ca4e8d22b432f41d8f5 (patch)
tree6bb894331c13de8c1f253872639f17ae3c3c6aea /include
parent45140af7cb7f485008905a645e043480615109bc (diff)
downloadqtlocation-mapboxgl-5207a360746d7d0541e21ca4e8d22b432f41d8f5.tar.gz
[core, ios, macos] SDK objects should hold weak pointers to the core style objects (#15539)
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/style/layer.hpp7
-rw-r--r--include/mbgl/style/source.hpp4
-rw-r--r--include/mbgl/style/sources/custom_geometry_source.hpp6
-rw-r--r--include/mbgl/style/sources/geojson_source.hpp7
-rw-r--r--include/mbgl/style/sources/image_source.hpp7
-rw-r--r--include/mbgl/style/sources/raster_source.hpp5
-rw-r--r--include/mbgl/style/sources/vector_source.hpp7
7 files changed, 39 insertions, 4 deletions
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp
index a66ff37b22..cfaca60e60 100644
--- a/include/mbgl/style/layer.hpp
+++ b/include/mbgl/style/layer.hpp
@@ -6,6 +6,8 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/conversion.hpp>
+#include <mapbox/weak.hpp>
+
#include <cassert>
#include <memory>
#include <string>
@@ -124,10 +126,15 @@ public:
const LayerTypeInfo* getTypeInfo() const noexcept;
+ mapbox::base::WeakPtr<Layer> makeWeakPtr() {
+ return weakFactory.makeWeakPtr();
+ }
+
protected:
virtual Mutable<Impl> mutableBaseImpl() const = 0;
LayerObserver* observer;
+ mapbox::base::WeakPtrFactory<Layer> weakFactory {this};
};
} // namespace style
diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp
index dc3a8d73fb..1d5223fa0d 100644
--- a/include/mbgl/style/source.hpp
+++ b/include/mbgl/style/source.hpp
@@ -6,6 +6,8 @@
#include <mbgl/util/immutable.hpp>
#include <mbgl/style/types.hpp>
+#include <mapbox/weak.hpp>
+
#include <memory>
#include <string>
@@ -78,6 +80,8 @@ public:
// object here, so that separately-obtained references to this object share
// identical platform-native peers.
util::peer peer;
+
+ virtual mapbox::base::WeakPtr<Source> makeWeakPtr() = 0;
};
} // namespace style
diff --git a/include/mbgl/style/sources/custom_geometry_source.hpp b/include/mbgl/style/sources/custom_geometry_source.hpp
index 3f29d0c0fb..a5e545f445 100644
--- a/include/mbgl/style/sources/custom_geometry_source.hpp
+++ b/include/mbgl/style/sources/custom_geometry_source.hpp
@@ -20,7 +20,7 @@ using TileFunction = std::function<void(const CanonicalTileID&)>;
class CustomTileLoader;
-class CustomGeometrySource : public Source {
+class CustomGeometrySource final : public Source {
public:
struct TileOptions {
double tolerance = 0.375;
@@ -46,9 +46,13 @@ public:
// Private implementation
class Impl;
const Impl& impl() const;
+ mapbox::base::WeakPtr<Source> makeWeakPtr() override {
+ return weakFactory.makeWeakPtr();
+ }
private:
std::shared_ptr<ThreadPool> threadPool;
std::unique_ptr<Actor<CustomTileLoader>> loader;
+ mapbox::base::WeakPtrFactory<Source> weakFactory {this};
};
template <>
diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp
index 4aec1584a6..c99687fad6 100644
--- a/include/mbgl/style/sources/geojson_source.hpp
+++ b/include/mbgl/style/sources/geojson_source.hpp
@@ -35,7 +35,7 @@ struct GeoJSONOptions {
ClusterProperties clusterProperties;
};
-class GeoJSONSource : public Source {
+class GeoJSONSource final : public Source {
public:
GeoJSONSource(const std::string& id, optional<GeoJSONOptions> = nullopt);
~GeoJSONSource() final;
@@ -50,9 +50,14 @@ public:
void loadDescription(FileSource&) final;
+ mapbox::base::WeakPtr<Source> makeWeakPtr() override {
+ return weakFactory.makeWeakPtr();
+ }
+
private:
optional<std::string> url;
std::unique_ptr<AsyncRequest> req;
+ mapbox::base::WeakPtrFactory<Source> weakFactory {this};
};
template <>
diff --git a/include/mbgl/style/sources/image_source.hpp b/include/mbgl/style/sources/image_source.hpp
index 009764291f..84faab33c9 100644
--- a/include/mbgl/style/sources/image_source.hpp
+++ b/include/mbgl/style/sources/image_source.hpp
@@ -10,7 +10,7 @@ class AsyncRequest;
namespace style {
-class ImageSource : public Source {
+class ImageSource final : public Source {
public:
ImageSource(std::string id, const std::array<LatLng, 4>);
~ImageSource() override;
@@ -27,9 +27,14 @@ public:
const Impl& impl() const;
void loadDescription(FileSource&) final;
+
+ mapbox::base::WeakPtr<Source> makeWeakPtr() override {
+ return weakFactory.makeWeakPtr();
+ }
private:
optional<std::string> url;
std::unique_ptr<AsyncRequest> req;
+ mapbox::base::WeakPtrFactory<Source> weakFactory {this};
};
template <>
diff --git a/include/mbgl/style/sources/raster_source.hpp b/include/mbgl/style/sources/raster_source.hpp
index 5aa81aa979..1bdced8da7 100644
--- a/include/mbgl/style/sources/raster_source.hpp
+++ b/include/mbgl/style/sources/raster_source.hpp
@@ -25,9 +25,14 @@ public:
void loadDescription(FileSource&) final;
+ mapbox::base::WeakPtr<Source> makeWeakPtr() final {
+ return weakFactory.makeWeakPtr();
+ }
+
private:
const variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;
+ mapbox::base::WeakPtrFactory<Source> weakFactory {this};
};
template <>
diff --git a/include/mbgl/style/sources/vector_source.hpp b/include/mbgl/style/sources/vector_source.hpp
index 6f16974b40..ece7f5615a 100644
--- a/include/mbgl/style/sources/vector_source.hpp
+++ b/include/mbgl/style/sources/vector_source.hpp
@@ -10,7 +10,7 @@ class AsyncRequest;
namespace style {
-class VectorSource : public Source {
+class VectorSource final : public Source {
public:
VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset);
~VectorSource() final;
@@ -23,9 +23,14 @@ public:
void loadDescription(FileSource&) final;
+ mapbox::base::WeakPtr<Source> makeWeakPtr() override {
+ return weakFactory.makeWeakPtr();
+ }
+
private:
const variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;
+ mapbox::base::WeakPtrFactory<Source> weakFactory {this};
};
template <>