diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-06-21 17:32:41 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-06-26 16:32:21 +0300 |
commit | 6beccef517250ecb24361caf5b71da6ce4f93c97 (patch) | |
tree | 30f1a1ce6a21ffbca2f099756a27e72bb575d275 | |
parent | 54c3ccc37d4534f699437f9c1854d8f5a857069e (diff) | |
download | qtlocation-mapboxgl-6beccef517250ecb24361caf5b71da6ce4f93c97.tar.gz |
[core] Introduce the ResourceTransform
Wrapper for transforming URLs on the OnlineFileSource.
-rw-r--r-- | cmake/core-files.cmake | 2 | ||||
-rw-r--r-- | include/mbgl/storage/resource_transform.hpp | 26 | ||||
-rw-r--r-- | src/mbgl/storage/resource_transform.cpp | 13 |
3 files changed, 41 insertions, 0 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index d58a36424a..fc476fcd15 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -310,6 +310,7 @@ set(MBGL_CORE_FILES include/mbgl/storage/offline.hpp include/mbgl/storage/online_file_source.hpp include/mbgl/storage/resource.hpp + include/mbgl/storage/resource_transform.hpp include/mbgl/storage/response.hpp src/mbgl/storage/asset_file_source.hpp src/mbgl/storage/file_source_request.cpp @@ -318,6 +319,7 @@ set(MBGL_CORE_FILES src/mbgl/storage/local_file_source.hpp src/mbgl/storage/network_status.cpp src/mbgl/storage/resource.cpp + src/mbgl/storage/resource_transform.cpp src/mbgl/storage/response.cpp # style diff --git a/include/mbgl/storage/resource_transform.hpp b/include/mbgl/storage/resource_transform.hpp new file mode 100644 index 0000000000..738c497176 --- /dev/null +++ b/include/mbgl/storage/resource_transform.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include <mbgl/actor/actor_ref.hpp> +#include <mbgl/storage/resource.hpp> + +#include <functional> +#include <string> + +namespace mbgl { + +class Mailbox; + +class ResourceTransform { +public: + using TransformCallback = std::function<std::string(Resource::Kind kind, const std::string&& url)>; + using FinishedCallback = std::function<void(const std::string&&)>; + + ResourceTransform(ActorRef<ResourceTransform>, TransformCallback&&); + + void transform(Resource::Kind, const std::string&& url, FinishedCallback&&); + +private: + TransformCallback transformCallback; +}; + +} // namespace mbgl diff --git a/src/mbgl/storage/resource_transform.cpp b/src/mbgl/storage/resource_transform.cpp new file mode 100644 index 0000000000..a5e62b2c1a --- /dev/null +++ b/src/mbgl/storage/resource_transform.cpp @@ -0,0 +1,13 @@ +#include <mbgl/storage/resource_transform.hpp> + +namespace mbgl { + +ResourceTransform::ResourceTransform(ActorRef<ResourceTransform>, TransformCallback&& callback) + : transformCallback(std::move(callback)) { +} + +void ResourceTransform::transform(Resource::Kind kind, const std::string&& url, FinishedCallback&& finished) { + finished(transformCallback(kind, std::move(url))); +} + +} // namespace mbgl |