Deleted the Pass file, replacing it with [[nodiscard]] (#1030)
This commit is contained in:
@@ -283,7 +283,6 @@ list(APPEND INCLUDE_FILES
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/util/interpolate.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/util/logging.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/util/noncopyable.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/util/pass_types.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/util/platform.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/util/premultiply.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/mbgl/util/projection.hpp
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/pass_types.hpp>
|
||||
|
||||
#include <mapbox/std/weak.hpp>
|
||||
|
||||
@@ -74,7 +73,7 @@ public:
|
||||
/// The scheduled tasks might run in parallel on different
|
||||
/// threads.
|
||||
/// TODO : Rename to GetPool()
|
||||
static PassRefPtr<Scheduler> GetBackground();
|
||||
[[nodiscard]] static std::shared_ptr<Scheduler> GetBackground();
|
||||
|
||||
/// Get the *sequenced* scheduler for asynchronous tasks.
|
||||
/// Unlike the method above, the returned scheduler
|
||||
@@ -84,7 +83,7 @@ public:
|
||||
///
|
||||
/// Sequenced scheduler can be used for running tasks
|
||||
/// on the same thread-unsafe object.
|
||||
static PassRefPtr<Scheduler> GetSequenced();
|
||||
[[nodiscard]] static std::shared_ptr<Scheduler> GetSequenced();
|
||||
|
||||
protected:
|
||||
template <typename TaskFn, typename ReplyFn>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/util/pass_types.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -31,7 +30,7 @@ public:
|
||||
// Returns shared instance of a file source for (type, options) tuple.
|
||||
// Creates new instance via registered factory if needed. If new instance cannot be
|
||||
// created, nullptr would be returned.
|
||||
PassRefPtr<FileSource> getFileSource(FileSourceType, const ResourceOptions&, const ClientOptions& = ClientOptions()) noexcept;
|
||||
[[nodiscard]] std::shared_ptr<FileSource> getFileSource(FileSourceType, const ResourceOptions&, const ClientOptions& = ClientOptions()) noexcept;
|
||||
|
||||
// Registers file source factory for a provided FileSourceType type. If factory for the
|
||||
// same type was already registered, will unregister previously registered factory.
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
/// Using this type as a return type enforces the client to retain the returned object.
|
||||
template <typename T>
|
||||
class Pass {
|
||||
public:
|
||||
Pass(T obj_) : obj(std::move(obj_)) {}
|
||||
Pass(Pass&&) noexcept = default;
|
||||
Pass(const Pass&) = delete;
|
||||
Pass& operator=(const Pass&) = delete;
|
||||
operator T() && { return std::move(obj); }
|
||||
|
||||
private:
|
||||
T obj;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using PassRefPtr = Pass<std::shared_ptr<T>>;
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -27,7 +27,7 @@ Scheduler* Scheduler::GetCurrent() {
|
||||
}
|
||||
|
||||
// static
|
||||
PassRefPtr<Scheduler> Scheduler::GetBackground() {
|
||||
std::shared_ptr<Scheduler> Scheduler::GetBackground() {
|
||||
static std::weak_ptr<Scheduler> weak;
|
||||
static std::mutex mtx;
|
||||
|
||||
@@ -38,11 +38,11 @@ PassRefPtr<Scheduler> Scheduler::GetBackground() {
|
||||
weak = scheduler = std::make_shared<ThreadPool>();
|
||||
}
|
||||
|
||||
return PassRefPtr<Scheduler>(std::move(scheduler));
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
// static
|
||||
PassRefPtr<Scheduler> Scheduler::GetSequenced() {
|
||||
std::shared_ptr<Scheduler> Scheduler::GetSequenced() {
|
||||
const std::size_t kSchedulersCount = 10;
|
||||
static std::vector<std::weak_ptr<Scheduler>> weaks(kSchedulersCount);
|
||||
static std::mutex mtx;
|
||||
@@ -65,7 +65,7 @@ PassRefPtr<Scheduler> Scheduler::GetSequenced() {
|
||||
break;
|
||||
}
|
||||
|
||||
return PassRefPtr<Scheduler>(std::move(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
} //namespace mbgl
|
||||
|
||||
@@ -31,7 +31,7 @@ FileSourceManager::FileSourceManager() : impl(std::make_unique<Impl>()) {}
|
||||
|
||||
FileSourceManager::~FileSourceManager() = default;
|
||||
|
||||
PassRefPtr<FileSource> FileSourceManager::getFileSource(FileSourceType type, const ResourceOptions& resourceOptions, const ClientOptions& clientOptions) noexcept {
|
||||
std::shared_ptr<FileSource> FileSourceManager::getFileSource(FileSourceType type, const ResourceOptions& resourceOptions, const ClientOptions& clientOptions) noexcept {
|
||||
std::lock_guard<std::recursive_mutex> lock(impl->mutex);
|
||||
|
||||
// Remove released file sources.
|
||||
|
||||
@@ -94,7 +94,6 @@ add_library(
|
||||
${PROJECT_SOURCE_DIR}/test/util/memory.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/util/merge_lines.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/util/number_conversions.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/util/pass.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/util/position.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/util/projection.test.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/util/rotation.test.cpp
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#include <mbgl/test/util.hpp>
|
||||
|
||||
#include <mbgl/util/pass_types.hpp>
|
||||
|
||||
TEST(Pass, NoCopy) {
|
||||
static int copyCount = 0;
|
||||
struct A {
|
||||
A() = default;
|
||||
A(A&&) = default;
|
||||
A(const A&) { ++copyCount; }
|
||||
static mbgl::Pass<A> create() { return A(); }
|
||||
};
|
||||
A a = A::create();
|
||||
(void)a;
|
||||
EXPECT_EQ(0, copyCount);
|
||||
}
|
||||
Reference in New Issue
Block a user