Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] ResoureOptions explicit copy via clone()
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Mar 25, 2019
1 parent ee5be6d commit 067ff28
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
3 changes: 1 addition & 2 deletions include/mbgl/map/map_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class MapOptions final {
MapOptions();
~MapOptions();

MapOptions(MapOptions&&);
explicit MapOptions(const MapOptions&);
MapOptions(MapOptions&&) noexcept;

/**
* @brief Sets the map rendering mode. By default, it is set to Continuous
Expand Down
7 changes: 5 additions & 2 deletions include/mbgl/storage/resource_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class ResourceOptions final {
ResourceOptions();
~ResourceOptions();

ResourceOptions(ResourceOptions&&);
explicit ResourceOptions(const ResourceOptions&);
ResourceOptions(ResourceOptions&&) noexcept;

ResourceOptions clone() const;

/**
* @brief Sets the Mapbox access token - see https://docs.mapbox.com/help/how-mapbox-works/access-tokens/ for details.
Expand Down Expand Up @@ -112,6 +113,8 @@ class ResourceOptions final {
void* platformContext() const;

private:
ResourceOptions(const ResourceOptions&);

class Impl;
std::unique_ptr<Impl> impl_;
};
Expand Down
2 changes: 1 addition & 1 deletion platform/android/src/file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ FileSource* FileSource::getNativePeer(jni::JNIEnv& env, const jni::Object<FileSo
mbgl::ResourceOptions FileSource::getSharedResourceOptions(jni::JNIEnv& env, const jni::Object<FileSource>& jFileSource) {
FileSource* fileSource = FileSource::getNativePeer(env, jFileSource);
assert(fileSource != nullptr);
return mbgl::ResourceOptions(fileSource->resourceOptions);
return fileSource->resourceOptions.clone();
}

void FileSource::registerNative(jni::JNIEnv& env) {
Expand Down
2 changes: 1 addition & 1 deletion platform/default/src/mbgl/map/map_snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ MapSnapshotter::MapSnapshotter(std::shared_ptr<Scheduler> scheduler,
const ResourceOptions& resourceOptions)
: impl(std::make_unique<util::Thread<MapSnapshotter::Impl>>(
"Map Snapshotter", std::move(scheduler), style, size, pixelRatio, cameraOptions,
region, programCacheDir, localFontFamily, resourceOptions)) {}
region, programCacheDir, localFontFamily, resourceOptions.clone())) {}

MapSnapshotter::~MapSnapshotter() = default;

Expand Down
3 changes: 1 addition & 2 deletions src/mbgl/map/map_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class MapOptions::Impl {
// These requires the complete type of Impl.
MapOptions::MapOptions() : impl_(std::make_unique<Impl>()) {}
MapOptions::~MapOptions() = default;
MapOptions::MapOptions(MapOptions&&) = default;
MapOptions::MapOptions(const MapOptions& other) : impl_(std::make_unique<Impl>(*other.impl_)) {}
MapOptions::MapOptions(MapOptions&&) noexcept = default;

MapOptions& MapOptions::withMapMode(MapMode mode) {
impl_->mapMode = mode;
Expand Down
6 changes: 5 additions & 1 deletion src/mbgl/storage/resource_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ class ResourceOptions::Impl {
// These requires the complete type of Impl.
ResourceOptions::ResourceOptions() : impl_(std::make_unique<Impl>()) {}
ResourceOptions::~ResourceOptions() = default;
ResourceOptions::ResourceOptions(ResourceOptions&&) = default;
ResourceOptions::ResourceOptions(ResourceOptions&&) noexcept = default;
ResourceOptions::ResourceOptions(const ResourceOptions& other) : impl_(std::make_unique<Impl>(*other.impl_)) {}

ResourceOptions ResourceOptions::clone() const {
return ResourceOptions(*this);
}

ResourceOptions& ResourceOptions::withAccessToken(std::string token) {
impl_->accessToken = std::move(token);
return *this;
Expand Down

0 comments on commit 067ff28

Please sign in to comment.