diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-09-16 16:38:32 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-09-24 16:14:09 +0200 |
commit | f26bb724dc164b69b5358f30c6248fdf5cbd076b (patch) | |
tree | 4c719a97ff02c86a22bcdcec6fc0f781c3bcd3e9 /include | |
parent | 6c526e56370a0f4dee9a4b6ed45489fcb14e3ff1 (diff) | |
download | qtlocation-mapboxgl-f26bb724dc164b69b5358f30c6248fdf5cbd076b.tar.gz |
use util::ptr as a wrapper around std::shared_ptr that asserts nonemptiness
Diffstat (limited to 'include')
32 files changed, 151 insertions, 126 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 3b2c97122e..786c7196ae 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -7,11 +7,11 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/time.hpp> #include <mbgl/util/uv.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <atomic> #include <iosfwd> -#include <memory> #include <set> #include <vector> @@ -48,7 +48,7 @@ public: // Triggers a lazy rerender: only performs a render when the map is not clean. void rerender(); - void renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); + void renderLayer(util::ptr<StyleLayer> layer_desc, RenderPass pass, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); // Forces a map update: always triggers a rerender. void update(); @@ -65,7 +65,7 @@ public: void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height); // Styling - const std::set<std::shared_ptr<StyleSource>> getActiveSources() const; + const std::set<util::ptr<StyleSource>> getActiveSources() const; void setAppliedClasses(const std::vector<std::string> &classes); void toggleClass(const std::string &name); const std::vector<std::string> &getAppliedClasses() const; @@ -118,14 +118,14 @@ public: public: inline const TransformState &getState() const { return state; } - inline std::shared_ptr<FileSource> getFileSource() const { return fileSource; } - inline std::shared_ptr<Style> getStyle() const { return style; } - inline std::shared_ptr<GlyphAtlas> getGlyphAtlas() { return glyphAtlas; } - inline std::shared_ptr<GlyphStore> getGlyphStore() { return glyphStore; } - inline std::shared_ptr<SpriteAtlas> getSpriteAtlas() { return spriteAtlas; } - std::shared_ptr<Sprite> getSprite(); - inline std::shared_ptr<Texturepool> getTexturepool() { return texturepool; } - inline std::shared_ptr<uv::loop> getLoop() { return loop; } + inline util::ptr<FileSource> getFileSource() const { return fileSource; } + inline util::ptr<Style> getStyle() const { return style; } + inline util::ptr<GlyphAtlas> getGlyphAtlas() { return glyphAtlas; } + inline util::ptr<GlyphStore> getGlyphStore() { return glyphStore; } + inline util::ptr<SpriteAtlas> getSpriteAtlas() { return spriteAtlas; } + util::ptr<Sprite> getSprite(); + inline util::ptr<Texturepool> getTexturepool() { return texturepool; } + inline util::ptr<uv::loop> getLoop() { return loop; } inline timestamp getAnimationTime() const { return animationTime; } inline timestamp getTime() const { return animationTime; } void updateTiles(); @@ -141,7 +141,7 @@ private: void setup(); void updateSources(); - void updateSources(const std::shared_ptr<StyleLayerGroup> &group); + void updateSources(const util::ptr<StyleLayerGroup> &group); void updateRenderState(); @@ -154,11 +154,11 @@ private: // Unconditionally performs a render with the current map state. void render(); - void renderLayers(std::shared_ptr<StyleLayerGroup> group); + void renderLayers(util::ptr<StyleLayerGroup> group); private: bool async = false; - std::shared_ptr<uv::loop> loop; + util::ptr<uv::loop> loop; std::unique_ptr<uv::thread> thread; std::unique_ptr<uv_async_t> async_terminate; std::unique_ptr<uv_async_t> async_render; @@ -189,14 +189,14 @@ private: Transform transform; TransformState state; - std::shared_ptr<FileSource> fileSource; + util::ptr<FileSource> fileSource; - std::shared_ptr<Style> style; - std::shared_ptr<GlyphAtlas> glyphAtlas; - std::shared_ptr<GlyphStore> glyphStore; - std::shared_ptr<SpriteAtlas> spriteAtlas; - std::shared_ptr<Sprite> sprite; - std::shared_ptr<Texturepool> texturepool; + util::ptr<Style> style; + util::ptr<GlyphAtlas> glyphAtlas; + util::ptr<GlyphStore> glyphStore; + util::ptr<SpriteAtlas> spriteAtlas; + util::ptr<Sprite> sprite; + util::ptr<Texturepool> texturepool; Painter painter; @@ -209,7 +209,7 @@ private: int indent = 0; - std::set<std::shared_ptr<StyleSource>> activeSources; + std::set<util::ptr<StyleSource>> activeSources; }; diff --git a/include/mbgl/map/raster_tile_data.hpp b/include/mbgl/map/raster_tile_data.hpp index 98aa3baaf5..329bbf4634 100644 --- a/include/mbgl/map/raster_tile_data.hpp +++ b/include/mbgl/map/raster_tile_data.hpp @@ -5,8 +5,6 @@ #include <mbgl/map/tile_data.hpp> #include <mbgl/renderer/raster_bucket.hpp> -#include <memory> - namespace mbgl { class Map; @@ -22,8 +20,8 @@ public: ~RasterTileData(); virtual void parse(); - virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const mat4 &matrix); - virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const; + virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); + virtual bool hasData(util::ptr<StyleLayer> layer_desc) const; protected: StyleBucketRaster properties; diff --git a/include/mbgl/map/source.hpp b/include/mbgl/map/source.hpp index cb069db272..471165f37c 100644 --- a/include/mbgl/map/source.hpp +++ b/include/mbgl/map/source.hpp @@ -8,12 +8,12 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/time.hpp> #include <mbgl/util/mat4.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <forward_list> #include <iosfwd> #include <map> -#include <memory> namespace mbgl { @@ -33,8 +33,8 @@ public: void updateMatrices(const mat4 &projMatrix, const TransformState &transform); void drawClippingMasks(Painter &painter); size_t getTileCount() const; - void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc); - void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); + void render(Painter &painter, util::ptr<StyleLayer> layer_desc); + void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); void finishRender(Painter &painter); std::forward_list<Tile::ID> getIDs() const; diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp index 6461a5e33d..454ebd8886 100644 --- a/include/mbgl/map/sprite.hpp +++ b/include/mbgl/map/sprite.hpp @@ -3,11 +3,11 @@ #include <mbgl/util/image.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <atomic> #include <iosfwd> -#include <memory> #include <string> #include <unordered_map> #include <future> @@ -34,11 +34,11 @@ public: class Sprite : public std::enable_shared_from_this<Sprite>, private util::noncopyable { private: struct Key {}; - void load(const std::shared_ptr<FileSource> &fileSource); + void load(const util::ptr<FileSource> &fileSource); public: Sprite(const Key &, const std::string& base_url, float pixelRatio); - static std::shared_ptr<Sprite> Create(const std::string& base_url, float pixelRatio, const std::shared_ptr<FileSource> &fileSource); + static util::ptr<Sprite> Create(const std::string& base_url, float pixelRatio, const util::ptr<FileSource> &fileSource); const SpritePosition &getSpritePosition(const std::string& name) const; diff --git a/include/mbgl/map/tile.hpp b/include/mbgl/map/tile.hpp index 75ced7e384..b9f0556add 100644 --- a/include/mbgl/map/tile.hpp +++ b/include/mbgl/map/tile.hpp @@ -3,6 +3,7 @@ #include <mbgl/util/mat4.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <bitset> @@ -10,7 +11,6 @@ #include <cstdint> #include <forward_list> #include <iosfwd> -#include <memory> #include <string> namespace mbgl { @@ -78,7 +78,7 @@ public: const Tile::ID id; ClipID clip; mat4 matrix; - std::shared_ptr<TileData> data; + util::ptr<TileData> data; }; } diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index 900224be2d..803f0447b3 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -6,11 +6,11 @@ #include <mbgl/geometry/debug_font_buffer.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/ptr.hpp> #include <atomic> #include <exception> #include <iosfwd> -#include <memory> #include <string> namespace mbgl { @@ -28,7 +28,7 @@ public: struct geometry_too_long_exception : exception {}; public: - typedef std::shared_ptr<TileData> Ptr; + typedef util::ptr<TileData> Ptr; enum class State { invalid, @@ -56,8 +56,8 @@ public: virtual void beforeParse(); virtual void parse() = 0; virtual void afterParse(); - virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const mat4 &matrix) = 0; - virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const = 0; + virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix) = 0; + virtual bool hasData(util::ptr<StyleLayer> layer_desc) const = 0; public: diff --git a/include/mbgl/map/tile_parser.hpp b/include/mbgl/map/tile_parser.hpp index fa64dad6d5..ddb4b98820 100644 --- a/include/mbgl/map/tile_parser.hpp +++ b/include/mbgl/map/tile_parser.hpp @@ -4,10 +4,10 @@ #include <mbgl/map/vector_tile.hpp> #include <mbgl/style/filter_expression.hpp> #include <mbgl/text/glyph.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <iosfwd> -#include <memory> #include <string> namespace mbgl { @@ -32,11 +32,11 @@ class Collision; class TileParser { public: TileParser(const std::string &data, VectorTileData &tile, - const std::shared_ptr<const Style> &style, - const std::shared_ptr<GlyphAtlas> &glyphAtlas, - const std::shared_ptr<GlyphStore> &glyphStore, - const std::shared_ptr<SpriteAtlas> &spriteAtlas, - const std::shared_ptr<Sprite> &sprite); + const util::ptr<const Style> &style, + const util::ptr<GlyphAtlas> &glyphAtlas, + const util::ptr<GlyphStore> &glyphStore, + const util::ptr<SpriteAtlas> &spriteAtlas, + const util::ptr<Sprite> &sprite); ~TileParser(); public: @@ -44,11 +44,11 @@ public: private: bool obsolete() const; - void parseStyleLayers(std::shared_ptr<StyleLayerGroup> group); - std::unique_ptr<Bucket> createBucket(std::shared_ptr<StyleBucket> bucket_desc); + void parseStyleLayers(util::ptr<StyleLayerGroup> group); + std::unique_ptr<Bucket> createBucket(util::ptr<StyleBucket> bucket_desc); std::unique_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketFill &fill); - std::unique_ptr<Bucket> createRasterBucket(const std::shared_ptr<Texturepool> &texturepool, const StyleBucketRaster &raster); + std::unique_ptr<Bucket> createRasterBucket(const util::ptr<Texturepool> &texturepool, const StyleBucketRaster &raster); std::unique_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketLine &line); std::unique_ptr<Bucket> createSymbolBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketSymbol &symbol); @@ -59,12 +59,12 @@ private: VectorTileData& tile; // Cross-thread shared data. - std::shared_ptr<const Style> style; - std::shared_ptr<GlyphAtlas> glyphAtlas; - std::shared_ptr<GlyphStore> glyphStore; - std::shared_ptr<SpriteAtlas> spriteAtlas; - std::shared_ptr<Sprite> sprite; - std::shared_ptr<Texturepool> texturePool; + util::ptr<const Style> style; + util::ptr<GlyphAtlas> glyphAtlas; + util::ptr<GlyphStore> glyphStore; + util::ptr<SpriteAtlas> spriteAtlas; + util::ptr<Sprite> sprite; + util::ptr<Texturepool> texturePool; std::unique_ptr<Collision> collision; }; diff --git a/include/mbgl/map/transform.hpp b/include/mbgl/map/transform.hpp index d0f56b7fba..5404f333c1 100644 --- a/include/mbgl/map/transform.hpp +++ b/include/mbgl/map/transform.hpp @@ -98,10 +98,10 @@ private: // cache values for spherical mercator math double Bc, Cc; - std::forward_list<std::shared_ptr<util::transition>> transitions; - std::shared_ptr<util::transition> scale_timeout; - std::shared_ptr<util::transition> rotate_timeout; - std::shared_ptr<util::transition> pan_timeout; + std::forward_list<util::ptr<util::transition>> transitions; + util::ptr<util::transition> scale_timeout; + util::ptr<util::transition> rotate_timeout; + util::ptr<util::transition> pan_timeout; }; } diff --git a/include/mbgl/map/vector_tile_data.hpp b/include/mbgl/map/vector_tile_data.hpp index deb628e485..3f80c0080c 100644 --- a/include/mbgl/map/vector_tile_data.hpp +++ b/include/mbgl/map/vector_tile_data.hpp @@ -32,8 +32,8 @@ public: virtual void beforeParse(); virtual void parse(); virtual void afterParse(); - virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const mat4 &matrix); - virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const; + virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); + virtual bool hasData(util::ptr<StyleLayer> layer_desc) const; protected: // Holds the actual geometries in this tile. diff --git a/include/mbgl/renderer/bucket.hpp b/include/mbgl/renderer/bucket.hpp index 1391f6e3e3..696bfb1110 100644 --- a/include/mbgl/renderer/bucket.hpp +++ b/include/mbgl/renderer/bucket.hpp @@ -1,11 +1,11 @@ #ifndef MBGL_RENDERER_BUCKET #define MBGL_RENDERER_BUCKET -#include <string> -#include <memory> #include <mbgl/map/tile.hpp> #include <mbgl/util/noncopyable.hpp> +#include <string> + namespace mbgl { class Painter; @@ -13,7 +13,7 @@ class StyleLayer; class Bucket : private util::noncopyable { public: - virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix) = 0; + virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix) = 0; virtual bool hasData() const = 0; virtual ~Bucket() {} diff --git a/include/mbgl/renderer/debug_bucket.hpp b/include/mbgl/renderer/debug_bucket.hpp index 660b7fcba8..fb6cfb4cae 100644 --- a/include/mbgl/renderer/debug_bucket.hpp +++ b/include/mbgl/renderer/debug_bucket.hpp @@ -6,7 +6,6 @@ #include <mbgl/geometry/vao.hpp> #include <vector> -#include <memory> #ifndef BUFFER_OFFSET #define BUFFER_OFFSET(i) ((char *)nullptr + (i)) @@ -20,7 +19,7 @@ class DebugBucket : public Bucket { public: DebugBucket(DebugFontBuffer& fontBuffer); - virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); virtual bool hasData() const; void drawLines(PlainShader& shader); diff --git a/include/mbgl/renderer/fill_bucket.hpp b/include/mbgl/renderer/fill_bucket.hpp index 15868e4092..ae766ec28d 100644 --- a/include/mbgl/renderer/fill_bucket.hpp +++ b/include/mbgl/renderer/fill_bucket.hpp @@ -44,7 +44,7 @@ public: const StyleBucketFill& properties); ~FillBucket(); - virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); virtual bool hasData() const; void addGeometry(pbf& data); diff --git a/include/mbgl/renderer/line_bucket.hpp b/include/mbgl/renderer/line_bucket.hpp index 8babb734ed..7337ca80ad 100644 --- a/include/mbgl/renderer/line_bucket.hpp +++ b/include/mbgl/renderer/line_bucket.hpp @@ -1,13 +1,12 @@ #ifndef MBGL_RENDERER_LINEBUCKET #define MBGL_RENDERER_LINEBUCKET -#include "bucket.hpp" +#include <mbgl/renderer/bucket.hpp> #include <mbgl/geometry/vao.hpp> #include <mbgl/geometry/elements_buffer.hpp> #include <mbgl/geometry/line_buffer.hpp> #include <mbgl/style/style_bucket.hpp> -#include <memory> #include <vector> namespace mbgl { @@ -30,7 +29,7 @@ public: PointElementsBuffer& pointElementsBuffer, const StyleBucketLine& properties); - virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); virtual bool hasData() const; void addGeometry(pbf& data); diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index 75529d1136..13c2050bd0 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -22,6 +22,7 @@ #include <mbgl/shader/gaussian_shader.hpp> #include <mbgl/map/transform_state.hpp> +#include <mbgl/util/ptr.hpp> #include <map> #include <unordered_map> @@ -72,7 +73,7 @@ public: void changeMatrix(); // Renders a particular layer from a tile. - void renderTileLayer(const Tile& tile, std::shared_ptr<StyleLayer> layer_desc, const mat4 &matrix); + void renderTileLayer(const Tile& tile, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); // Renders debug information for a tile. void renderTileDebug(const Tile& tile); @@ -82,11 +83,11 @@ public: void renderDebugText(DebugBucket& bucket, const mat4 &matrix); void renderDebugText(const std::vector<std::string> &strings); - void renderFill(FillBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - void renderLine(LineBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - void renderSymbol(SymbolBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - void renderRaster(RasterBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - void renderBackground(std::shared_ptr<StyleLayer> layer_desc); + void renderFill(FillBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + void renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + void renderSymbol(SymbolBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + void renderRaster(RasterBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + void renderBackground(util::ptr<StyleLayer> layer_desc); float saturationFactor(float saturation); float contrastFactor(float contrast); @@ -96,7 +97,7 @@ public: void renderPrerenderedTexture(RasterBucket &bucket, const mat4 &matrix, const RasterProperties& properties); - void createPrerendered(RasterBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id); + void createPrerendered(RasterBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id); void resize(); @@ -110,7 +111,7 @@ public: // Configures the painter strata that is used for early z-culling of fragments. void setStrata(float strata); - void drawClippingMasks(const std::set<std::shared_ptr<StyleSource>> &sources); + void drawClippingMasks(const std::set<util::ptr<StyleSource>> &sources); void drawClippingMask(const mat4& matrix, const ClipID& clip); void resetFramebuffer(); diff --git a/include/mbgl/renderer/raster_bucket.hpp b/include/mbgl/renderer/raster_bucket.hpp index 66cceac8e7..794da3b143 100644 --- a/include/mbgl/renderer/raster_bucket.hpp +++ b/include/mbgl/renderer/raster_bucket.hpp @@ -16,9 +16,9 @@ class VertexArrayObject; class RasterBucket : public Bucket { public: - RasterBucket(const std::shared_ptr<Texturepool> &texturepool, const StyleBucketRaster& properties); + RasterBucket(const util::ptr<Texturepool> &texturepool, const StyleBucketRaster& properties); - virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); virtual bool hasData() const; bool setImage(const std::string &data); diff --git a/include/mbgl/renderer/symbol_bucket.hpp b/include/mbgl/renderer/symbol_bucket.hpp index c71d276456..42682401ef 100644 --- a/include/mbgl/renderer/symbol_bucket.hpp +++ b/include/mbgl/renderer/symbol_bucket.hpp @@ -56,7 +56,7 @@ class SymbolBucket : public Bucket { public: SymbolBucket(const StyleBucketSymbol &properties, Collision &collision); - virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); + virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); virtual bool hasData() const; virtual bool hasTextData() const; virtual bool hasIconData() const; diff --git a/include/mbgl/storage/base_request.hpp b/include/mbgl/storage/base_request.hpp index 05ef1e4a7b..c903742f4b 100644 --- a/include/mbgl/storage/base_request.hpp +++ b/include/mbgl/storage/base_request.hpp @@ -1,11 +1,13 @@ #ifndef MBGL_STORAGE_BASE_REQUEST #define MBGL_STORAGE_BASE_REQUEST +#include <mbgl/util/ptr.hpp> + #include <string> #include <forward_list> -#include <memory> #include <functional> + typedef struct uv_loop_s uv_loop_t; typedef struct uv_async_s uv_async_t; @@ -28,7 +30,7 @@ public: BaseRequest(const std::string &path); virtual ~BaseRequest(); - Callback *add(Callback &&callback, const std::shared_ptr<BaseRequest> &request); + Callback *add(Callback &&callback, const util::ptr<BaseRequest> &request); void remove(Callback *callback); void notify(); @@ -40,7 +42,7 @@ public: private: // This object may hold a shared_ptr to itself. It does this to prevent destruction of this object // while a request is in progress. - std::shared_ptr<BaseRequest> self; + util::ptr<BaseRequest> self; std::forward_list<std::unique_ptr<Callback>> callbacks; }; diff --git a/include/mbgl/storage/file_request.hpp b/include/mbgl/storage/file_request.hpp index 331ed8421f..c99237ad4b 100644 --- a/include/mbgl/storage/file_request.hpp +++ b/include/mbgl/storage/file_request.hpp @@ -1,11 +1,6 @@ #ifndef MBGL_STORAGE_FILE_REQUEST #define MBGL_STORAGE_FILE_REQUEST - -#include <string> -#include <memory> -#include <cassert> - #include <mbgl/storage/base_request.hpp> namespace mbgl { diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp index 4cc95ae24e..06d416d0c6 100644 --- a/include/mbgl/storage/file_source.hpp +++ b/include/mbgl/storage/file_source.hpp @@ -5,7 +5,6 @@ #include <mbgl/storage/request.hpp> #include <string> -#include <memory> #include <unordered_map> #include <functional> @@ -44,7 +43,7 @@ private: std::string base; std::unordered_map<std::string, std::weak_ptr<BaseRequest>> pending; - std::shared_ptr<SQLiteStore> store; + util::ptr<SQLiteStore> store; uv_loop_t *loop = nullptr; uv_messenger_t *queue = nullptr; }; diff --git a/include/mbgl/storage/http_request.hpp b/include/mbgl/storage/http_request.hpp index 30f7b3aa6d..ef3210d48d 100644 --- a/include/mbgl/storage/http_request.hpp +++ b/include/mbgl/storage/http_request.hpp @@ -19,7 +19,7 @@ class SQLiteStore; class HTTPRequest : public BaseRequest { public: - HTTPRequest(ResourceType type, const std::string &path, uv_loop_t *loop, std::shared_ptr<SQLiteStore> store); + HTTPRequest(ResourceType type, const std::string &path, uv_loop_t *loop, util::ptr<SQLiteStore> store); ~HTTPRequest(); private: @@ -29,7 +29,7 @@ private: const unsigned long thread_id; CacheRequestBaton *cache_baton = nullptr; HTTPRequestBaton *http_baton = nullptr; - std::shared_ptr<SQLiteStore> store; + util::ptr<SQLiteStore> store; const ResourceType type; }; diff --git a/include/mbgl/storage/request.hpp b/include/mbgl/storage/request.hpp index fa27fbc781..10c938ed15 100644 --- a/include/mbgl/storage/request.hpp +++ b/include/mbgl/storage/request.hpp @@ -2,8 +2,8 @@ #define MBGL_STORAGE_REQUEST #include <mbgl/storage/response.hpp> +#include <mbgl/util/ptr.hpp> -#include <memory> #include <functional> #include <forward_list> @@ -22,7 +22,7 @@ private: Request& operator=(Request &&) = delete; public: - Request(const std::shared_ptr<BaseRequest> &base); + Request(const util::ptr<BaseRequest> &base); ~Request(); void onload(Callback cb); @@ -30,7 +30,7 @@ public: private: const unsigned long thread_id; - std::shared_ptr<BaseRequest> base; + util::ptr<BaseRequest> base; std::forward_list<Callback *> callbacks; }; diff --git a/include/mbgl/storage/sqlite_store.hpp b/include/mbgl/storage/sqlite_store.hpp index e03e6cf2bc..cb7730d0bf 100644 --- a/include/mbgl/storage/sqlite_store.hpp +++ b/include/mbgl/storage/sqlite_store.hpp @@ -38,7 +38,7 @@ private: private: const unsigned long thread_id; - std::shared_ptr<mapbox::sqlite::Database> db; + util::ptr<mapbox::sqlite::Database> db; uv_worker_t *worker = nullptr; }; diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp index c09de6ebba..56f318ecbb 100644 --- a/include/mbgl/style/style.hpp +++ b/include/mbgl/style/style.hpp @@ -6,6 +6,7 @@ #include <mbgl/util/time.hpp> #include <mbgl/util/uv.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <map> @@ -13,7 +14,6 @@ #include <unordered_map> #include <vector> #include <set> -#include <memory> namespace mbgl { @@ -49,7 +49,7 @@ public: const std::string &getSpriteURL() const; public: - std::shared_ptr<StyleLayerGroup> layers; + util::ptr<StyleLayerGroup> layers; std::vector<std::string> appliedClasses; std::string glyph_url; diff --git a/include/mbgl/style/style_bucket.hpp b/include/mbgl/style/style_bucket.hpp index c2cde52aa5..c4a8f6037e 100644 --- a/include/mbgl/style/style_bucket.hpp +++ b/include/mbgl/style/style_bucket.hpp @@ -8,8 +8,8 @@ #include <mbgl/util/vec.hpp> #include <mbgl/util/variant.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/ptr.hpp> -#include <memory> #include <forward_list> namespace mbgl { @@ -93,12 +93,12 @@ typedef mapbox::util::variant<StyleBucketFill, StyleBucketLine, StyleBucketSymbo class StyleBucket { public: - typedef std::shared_ptr<StyleBucket> Ptr; + typedef util::ptr<StyleBucket> Ptr; StyleBucket(StyleLayerType type); std::string name; - std::shared_ptr<StyleSource> style_source; + util::ptr<StyleSource> style_source; std::string source_layer; FilterExpression filter; StyleBucketRender render = std::false_type(); diff --git a/include/mbgl/style/style_layer.hpp b/include/mbgl/style/style_layer.hpp index 84981e3fb4..641dc1e71c 100644 --- a/include/mbgl/style/style_layer.hpp +++ b/include/mbgl/style/style_layer.hpp @@ -6,8 +6,9 @@ #include <mbgl/style/style_properties.hpp> #include <mbgl/style/applied_class_properties.hpp> +#include <mbgl/util/ptr.hpp> + #include <vector> -#include <memory> #include <string> #include <map> #include <set> @@ -64,7 +65,7 @@ public: // Bucket information, telling the renderer how to generate the geometries // for this layer (feature property filters, tessellation instructions, ...). - std::shared_ptr<StyleBucket> bucket; + util::ptr<StyleBucket> bucket; // Contains all style classes that can be applied to this layer. const std::map<ClassID, ClassProperties> styles; @@ -80,7 +81,7 @@ public: StyleProperties properties; // Child layer array (if this layer has child layers). - std::shared_ptr<StyleLayerGroup> layers; + util::ptr<StyleLayerGroup> layers; }; } diff --git a/include/mbgl/style/style_layer_group.hpp b/include/mbgl/style/style_layer_group.hpp index 983dd136f0..1af6e23bd7 100644 --- a/include/mbgl/style/style_layer_group.hpp +++ b/include/mbgl/style/style_layer_group.hpp @@ -15,7 +15,7 @@ public: bool hasTransitions() const; public: - std::vector<std::shared_ptr<StyleLayer>> layers; + std::vector<util::ptr<StyleLayer>> layers; }; } diff --git a/include/mbgl/style/style_parser.hpp b/include/mbgl/style/style_parser.hpp index e4e1b7f632..fc253bb1dd 100644 --- a/include/mbgl/style/style_parser.hpp +++ b/include/mbgl/style/style_parser.hpp @@ -27,7 +27,7 @@ public: void parse(JSVal document); - std::shared_ptr<StyleLayerGroup> getLayers() { + util::ptr<StyleLayerGroup> getLayers() { return root; } @@ -46,14 +46,14 @@ private: void parseSources(JSVal value); std::unique_ptr<StyleLayerGroup> createLayers(JSVal value); - std::shared_ptr<StyleLayer> createLayer(JSVal value); + util::ptr<StyleLayer> createLayer(JSVal value); void parseLayers(); - void parseLayer(std::pair<JSVal, std::shared_ptr<StyleLayer>> &pair); + void parseLayer(std::pair<JSVal, util::ptr<StyleLayer>> &pair); void parseStyles(JSVal value, std::map<ClassID, ClassProperties> &styles); void parseStyle(JSVal, ClassProperties &properties); - void parseReference(JSVal value, std::shared_ptr<StyleLayer> &layer); - void parseBucket(JSVal value, std::shared_ptr<StyleLayer> &layer); - void parseRender(JSVal value, std::shared_ptr<StyleLayer> &layer); + void parseReference(JSVal value, util::ptr<StyleLayer> &layer); + void parseBucket(JSVal value, util::ptr<StyleLayer> &layer); + void parseRender(JSVal value, util::ptr<StyleLayer> &layer); void parseSprite(JSVal value); void parseGlyphURL(JSVal value); @@ -94,13 +94,13 @@ private: private: std::unordered_map<std::string, const rapidjson::Value *> constants; - std::unordered_map<std::string, const std::shared_ptr<StyleSource>> sources; + std::unordered_map<std::string, const util::ptr<StyleSource>> sources; // This stores the root layer. - std::shared_ptr<StyleLayerGroup> root; + util::ptr<StyleLayerGroup> root; // This maps ids to Layer objects, with all items being at the root level. - std::unordered_map<std::string, std::pair<JSVal, std::shared_ptr<StyleLayer>>> layers; + std::unordered_map<std::string, std::pair<JSVal, util::ptr<StyleLayer>>> layers; // Store a stack of layers we're parsing right now. This is to prevent reference cycles. std::forward_list<StyleLayer *> stack; diff --git a/include/mbgl/style/style_source.hpp b/include/mbgl/style/style_source.hpp index b598550c65..4b89a6557c 100644 --- a/include/mbgl/style/style_source.hpp +++ b/include/mbgl/style/style_source.hpp @@ -2,13 +2,12 @@ #define MBGL_STYLE_STYLE_SOURCE #include <mbgl/style/types.hpp> +#include <mbgl/util/ptr.hpp> +#include <rapidjson/document.h> -#include <memory> #include <vector> #include <string> -#include <rapidjson/document.h> - namespace mbgl { class Source; @@ -34,7 +33,7 @@ public: SourceInfo info; bool enabled = false; - std::shared_ptr<Source> source; + util::ptr<Source> source; StyleSource(const SourceInfo &info) : info(info) diff --git a/include/mbgl/text/glyph_store.hpp b/include/mbgl/text/glyph_store.hpp index 9730967053..f8a7cb4d0c 100644 --- a/include/mbgl/text/glyph_store.hpp +++ b/include/mbgl/text/glyph_store.hpp @@ -4,6 +4,7 @@ #include <mbgl/text/glyph.hpp> #include <mbgl/util/pbf.hpp> #include <mbgl/util/vec.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <vector> @@ -47,7 +48,7 @@ private: class GlyphPBF { public: - GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const std::shared_ptr<FileSource> &fileSource); + GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const util::ptr<FileSource> &fileSource); private: GlyphPBF(const GlyphPBF &) = delete; @@ -70,7 +71,7 @@ private: // Manages Glyphrange PBF loading. class GlyphStore { public: - GlyphStore(const std::shared_ptr<FileSource> &fileSource); + GlyphStore(const util::ptr<FileSource> &fileSource); // Block until all specified GlyphRanges of the specified font stack are loaded. void waitForGlyphRanges(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges); @@ -89,7 +90,7 @@ public: std::string glyphURL; private: - const std::shared_ptr<FileSource> fileSource; + const util::ptr<FileSource> fileSource; std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges; std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks; std::mutex mtx; diff --git a/include/mbgl/util/ptr.hpp b/include/mbgl/util/ptr.hpp new file mode 100644 index 0000000000..5511083fc6 --- /dev/null +++ b/include/mbgl/util/ptr.hpp @@ -0,0 +1,29 @@ +#ifndef MBGL_UTIL_PTR +#define MBGL_UTIL_PTR + +#include <memory> +#include <cassert> + +namespace mbgl { +namespace util { + +template <typename T> +class ptr : public ::std::shared_ptr<T> { +public: + template <typename... Args> + inline ptr(Args &&... args) + : ::std::shared_ptr<T>(::std::forward<Args>(args)...) {} + + inline auto operator->() const -> decltype(::std::shared_ptr<T>::operator->()) { + assert(*this); + return ::std::shared_ptr<T>::operator->(); + } + inline auto operator*() const -> decltype(::std::shared_ptr<T>::operator*()) { + assert(*this); + return ::std::shared_ptr<T>::operator*(); + } +}; +} +} + +#endif
\ No newline at end of file diff --git a/include/mbgl/util/raster.hpp b/include/mbgl/util/raster.hpp index e526ffa5ac..7051c30091 100644 --- a/include/mbgl/util/raster.hpp +++ b/include/mbgl/util/raster.hpp @@ -4,11 +4,11 @@ #include <mbgl/util/transition.hpp> #include <mbgl/util/texturepool.hpp> #include <mbgl/util/image.hpp> +#include <mbgl/util/ptr.hpp> #include <mbgl/renderer/prerendered_texture.hpp> #include <string> #include <mutex> -#include <memory> typedef struct uv_loop_s uv_loop_t; @@ -17,7 +17,7 @@ namespace mbgl { class Raster : public std::enable_shared_from_this<Raster> { public: - Raster(const std::shared_ptr<Texturepool> &texturepool); + Raster(const util::ptr<Texturepool> &texturepool); ~Raster(); // load image data @@ -57,7 +57,7 @@ private: bool loaded = false; // shared texture pool - std::shared_ptr<Texturepool> texturepool; + util::ptr<Texturepool> texturepool; // min/mag filter uint32_t filter = 0; @@ -66,7 +66,7 @@ private: std::unique_ptr<util::Image> img; // fade in transition - std::shared_ptr<util::transition> fade_transition = nullptr; + util::ptr<util::transition> fade_transition = nullptr; }; } diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp index eefb5ac8df..272ca41495 100644 --- a/include/mbgl/util/uv_detail.hpp +++ b/include/mbgl/util/uv_detail.hpp @@ -1,6 +1,8 @@ #ifndef MBGL_UTIL_UV_DETAIL #define MBGL_UTIL_UV_DETAIL +#include <mbgl/util/ptr.hpp> + #include <uv.h> #include <functional> @@ -113,7 +115,7 @@ public: typedef void (*after_work_callback)(T &object); template<typename... Args> - work(const std::shared_ptr<loop> &loop, work_callback work_cb, after_work_callback after_work_cb, Args&&... args) + work(const mbgl::util::ptr<loop> &loop, work_callback work_cb, after_work_callback after_work_cb, Args&&... args) : loop(loop), data(std::forward<Args>(args)...), work_cb(work_cb), @@ -135,7 +137,7 @@ private: } private: - std::shared_ptr<uv::loop> loop; + mbgl::util::ptr<uv::loop> loop; uv_work_t req; T data; work_callback work_cb; |