diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-19 16:57:36 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-20 21:30:08 +0200 |
commit | d5868d3da822f2bf3297229bd879e76853108a63 (patch) | |
tree | b3d28aab92b938cf541f917f1027d2bbd06d9780 /include | |
parent | d1762d7111b39d45430bd7bb75ea60b7a5d85bd2 (diff) | |
download | qtlocation-mapboxgl-d5868d3da822f2bf3297229bd879e76853108a63.tar.gz |
[core] Remove file source from public Map ctor
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/map/map.hpp | 11 | ||||
-rw-r--r-- | include/mbgl/map/map_options.hpp | 49 | ||||
-rw-r--r-- | include/mbgl/storage/default_file_source.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/storage/file_source.hpp | 12 | ||||
-rw-r--r-- | include/mbgl/storage/resource_options.hpp | 116 |
5 files changed, 137 insertions, 53 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index b4f60a19ba..be8bf45142 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -12,6 +12,7 @@ #include <mbgl/map/camera.hpp> #include <mbgl/util/geometry.hpp> #include <mbgl/map/projection_mode.hpp> +#include <mbgl/storage/resource_options.hpp> #include <cstdint> #include <string> @@ -21,7 +22,6 @@ namespace mbgl { -class FileSource; class Scheduler; class RendererFrontend; @@ -36,9 +36,9 @@ public: MapObserver&, Size size, float pixelRatio, - FileSource&, Scheduler&, - const MapOptions&); + const MapOptions&, + const ResourceOptions&); ~Map(); // Register a callback that will get called (on the render thread) when all resources have @@ -137,9 +137,12 @@ public: bool isFullyLoaded() const; void dumpDebugLogs() const; -private: +protected: class Impl; const std::unique_ptr<Impl> impl; + + // For testing only. + Map(std::unique_ptr<Impl>); }; } // namespace mbgl diff --git a/include/mbgl/map/map_options.hpp b/include/mbgl/map/map_options.hpp index 13772332a8..f2297484a3 100644 --- a/include/mbgl/map/map_options.hpp +++ b/include/mbgl/map/map_options.hpp @@ -3,14 +3,13 @@ #include <mbgl/map/mode.hpp> #include <memory> -#include <string> namespace mbgl { /** * @brief Holds values for Map options. */ -class MapOptions { +class MapOptions final { public: /** * @brief Constructs a MapOptions object with default values. @@ -69,52 +68,6 @@ public: ViewportMode viewportMode() const; /** - * @brief Sets the cache path. - * - * @param path Cache path. - * @return reference to MapOptions for chaining options together. - */ - MapOptions& withCachePath(std::string path); - - /** - * @brief Gets the previously set (or default) cache path. - * - * @return cache path - */ - const std::string& cachePath() const; - - /** - * @brief Sets the asset path, which is the root directory from where - * the asset:// scheme gets resolved in a style. - * - * @param path Asset path. - * @return reference to MapOptions for chaining options together. - */ - MapOptions& withAssetRoot(std::string path); - - /** - * @brief Gets the previously set (or default) asset path. - * - * @return asset path - */ - const std::string& assetRoot() const; - - /** - * @brief Sets the maximum cache size. - * - * @param size Cache maximum size in bytes. - * @return reference to MapOptions for chaining options together. - */ - MapOptions& withMaximumCacheSize(uint64_t size); - - /** - * @brief Gets the previously set (or default) maximum allowed cache size. - * - * @return maximum allowed cache database size in bytes. - */ - uint64_t maximumCacheSize() const; - - /** * @brief Specify whether to enable cross-source symbol collision detection * or not. By default, it is set to true. * diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp index 5f6999e99f..8f88964acf 100644 --- a/include/mbgl/storage/default_file_source.hpp +++ b/include/mbgl/storage/default_file_source.hpp @@ -28,7 +28,7 @@ public: * of megabytes). */ DefaultFileSource(const std::string& cachePath, - const std::string& assetRoot, + const std::string& assetPath, uint64_t maximumCacheSize = util::DEFAULT_MAX_CACHE_SIZE); DefaultFileSource(const std::string& cachePath, std::unique_ptr<FileSource>&& assetFileSource, diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp index 0709a1c245..868dbf7347 100644 --- a/include/mbgl/storage/file_source.hpp +++ b/include/mbgl/storage/file_source.hpp @@ -1,16 +1,21 @@ #pragma once +#include <mbgl/actor/actor_ref.hpp> #include <mbgl/storage/response.hpp> #include <mbgl/storage/resource.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/async_request.hpp> +#include <mbgl/util/optional.hpp> #include <functional> #include <memory> namespace mbgl { +class ResourceOptions; +class ResourceTransform; + class FileSource : private util::noncopyable { public: virtual ~FileSource() = default; @@ -31,6 +36,13 @@ public: virtual bool supportsCacheOnlyRequests() const { return false; } + + // Factory for creating a platform-specific file source. + static std::shared_ptr<FileSource> createPlatformFileSource(const ResourceOptions&); + + // Singleton for obtaining the shared platform-specific file source. A single instance of a file source is provided + // for each unique combination of a Mapbox API base URL, access token, cache path and platform context. + static std::shared_ptr<FileSource> getSharedFileSource(const ResourceOptions&); }; } // namespace mbgl diff --git a/include/mbgl/storage/resource_options.hpp b/include/mbgl/storage/resource_options.hpp new file mode 100644 index 0000000000..0a4669ea15 --- /dev/null +++ b/include/mbgl/storage/resource_options.hpp @@ -0,0 +1,116 @@ +#pragma once + +#include <memory> +#include <string> + +namespace mbgl { + +/** + * @brief Holds values for resource options. + */ +class ResourceOptions final { +public: + /** + * @brief Constructs a ResourceOptions object with default values. + */ + ResourceOptions(); + ~ResourceOptions(); + + /** + * @brief Sets the Mapbox access token - see https://docs.mapbox.com/help/how-mapbox-works/access-tokens/ for details. + * + * @param token Mapbox access token. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withAccessToken(std::string token); + + /** + * @brief Gets the previously set (or default) Mapbox access token. + * + * @return const std::string& Mapbox access token. + */ + const std::string& accessToken() const; + + /** + * @brief Sets the API base URL. Default is https://api.mapbox.com for Mapbox. + * + * @param baseURL API base URL. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withBaseURL(std::string baseURL); + + /** + * @brief Gets the previously set (or default) API base URL. + * + * @return const std::string& API base URL. + */ + const std::string& baseURL() const; + + /** + * @brief Sets the cache path. + * + * @param path Cache path. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withCachePath(std::string path); + + /** + * @brief Gets the previously set (or default) cache path. + * + * @return cache path + */ + const std::string& cachePath() const; + + /** + * @brief Sets the asset path, which is the root directory from where + * the asset:// scheme gets resolved in a style. + * + * @param path Asset path. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withAssetPath(std::string path); + + /** + * @brief Gets the previously set (or default) asset path. + * + * @return asset path + */ + const std::string& assetPath() const; + + /** + * @brief Sets the maximum cache size. + * + * @param size Cache maximum size in bytes. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withMaximumCacheSize(uint64_t size); + + /** + * @brief Gets the previously set (or default) maximum allowed cache size. + * + * @return maximum allowed cache database size in bytes. + */ + uint64_t maximumCacheSize() const; + + /** + * @brief Sets the platform context. A platform context is usually an object + * that assists the creation of a file source. + * + * @param context Platform context. + * @return reference to ResourceOptions for chaining options together. + */ + ResourceOptions& withPlatformContext(void* context); + + /** + * @brief Gets the previously set (or default) platform context. + * + * @return Platform context. + */ + void* platformContext() const; + +private: + class Impl; + std::shared_ptr<Impl> impl_; +}; + +} // namespace mbgl |