From 93c543b2fd98f9fa391b9c27da099d9aded34f45 Mon Sep 17 00:00:00 2001 From: OEOTYAN Date: Thu, 18 Jan 2024 20:13:05 +0800 Subject: [PATCH] refactor: refactoring SharedPtr --- src/mc/common/wrapper/SharedPtr.h | 22 +++++++++---------- src/mc/common/wrapper/WeakPtr.h | 20 ++++++++--------- .../level/block/registry/BlockTypeRegistry.h | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/mc/common/wrapper/SharedPtr.h b/src/mc/common/wrapper/SharedPtr.h index 768839d09b..b0853f41a4 100644 --- a/src/mc/common/wrapper/SharedPtr.h +++ b/src/mc/common/wrapper/SharedPtr.h @@ -10,17 +10,17 @@ template class SharedPtr { public: template - static SharedPtr makeShared(Args&&... args) { + [[nodiscard]] static SharedPtr make(Args&&... args) { return SharedPtr(new T(std::forward(args)...)); } - SharedPtr() noexcept : counter(nullptr) {} // NOLINT - SharedPtr(std::nullptr_t) noexcept : counter(nullptr) {} // NOLINT + [[nodiscard]] SharedPtr() noexcept : counter(nullptr) {} // NOLINT + [[nodiscard]] SharedPtr(std::nullptr_t) noexcept : counter(nullptr) {} // NOLINT - explicit SharedPtr(T* p) : counter(new SharedCounter(p)) {} + [[nodiscard]] explicit SharedPtr(T* p) : counter(new SharedCounter(p)) {} template - explicit SharedPtr(SharedPtr const& other) + [[nodiscard]] explicit SharedPtr(SharedPtr const& other) requires(std::convertible_to) { counter = (SharedCounter*)other.counter; @@ -30,7 +30,7 @@ class SharedPtr { } template - explicit SharedPtr(SharedPtr&& other) + [[nodiscard]] explicit SharedPtr(SharedPtr&& other) requires(std::convertible_to) { counter = (SharedCounter*)other.counter; @@ -38,7 +38,7 @@ class SharedPtr { } template - explicit SharedPtr(WeakPtr const& other) + [[nodiscard]] explicit SharedPtr(WeakPtr const& other) requires(std::convertible_to) { counter = (SharedCounter*)other.counter; @@ -88,13 +88,13 @@ class SharedPtr { return *this; } - T* get() const { return counter ? counter->get() : nullptr; } + [[nodiscard]] T* get() const { return counter ? counter->get() : nullptr; } - T* operator->() const { return get(); } + [[nodiscard]] T* operator->() const { return get(); } - T& operator*() const { return *get(); } + [[nodiscard]] T& operator*() const { return *get(); } - explicit operator bool() const { return get() != nullptr; } + [[nodiscard]] explicit operator bool() const { return get() != nullptr; } [[nodiscard]] int use_count() const { return counter ? counter->getShareCount() : 0; } diff --git a/src/mc/common/wrapper/WeakPtr.h b/src/mc/common/wrapper/WeakPtr.h index 1071e2e372..881869b77c 100644 --- a/src/mc/common/wrapper/WeakPtr.h +++ b/src/mc/common/wrapper/WeakPtr.h @@ -9,11 +9,11 @@ class SharedPtr; template class WeakPtr { public: - WeakPtr() noexcept : counter(nullptr) {} // NOLINT - WeakPtr(std::nullptr_t) noexcept : counter(nullptr) {} // NOLINT + [[nodiscard]] WeakPtr() noexcept : counter(nullptr) {} // NOLINT + [[nodiscard]] WeakPtr(std::nullptr_t) noexcept : counter(nullptr) {} // NOLINT template - explicit WeakPtr(SharedPtr const& other) + [[nodiscard]] explicit WeakPtr(SharedPtr const& other) requires(std::convertible_to) { counter = (SharedCounter*)other.counter; @@ -23,7 +23,7 @@ class WeakPtr { } template - explicit WeakPtr(WeakPtr const& other) + [[nodiscard]] explicit WeakPtr(WeakPtr const& other) requires(std::convertible_to) { counter = (SharedCounter*)other.counter; @@ -33,7 +33,7 @@ class WeakPtr { } template - explicit WeakPtr(WeakPtr&& other) + [[nodiscard]] explicit WeakPtr(WeakPtr&& other) requires(std::convertible_to) { counter = (SharedCounter*)other.counter; @@ -87,15 +87,15 @@ class WeakPtr { [[nodiscard]] bool expired() const { return use_count() == 0; } - SharedPtr lock() const { return expired() ? SharedPtr() : SharedPtr(*this); } + [[nodiscard]] SharedPtr lock() const { return expired() ? SharedPtr() : SharedPtr(*this); } - T* get() const { return counter ? counter->get() : nullptr; } + [[nodiscard]] T* get() const { return counter ? counter->get() : nullptr; } - T* operator->() const { return get(); } + [[nodiscard]] T* operator->() const { return get(); } - T& operator*() const { return *get(); } + [[nodiscard]] T& operator*() const { return *get(); } - explicit operator bool() const { return get() != nullptr; } + [[nodiscard]] explicit operator bool() const { return get() != nullptr; } SharedCounter* counter; }; diff --git a/src/mc/world/level/block/registry/BlockTypeRegistry.h b/src/mc/world/level/block/registry/BlockTypeRegistry.h index 574278c6ea..6059370383 100644 --- a/src/mc/world/level/block/registry/BlockTypeRegistry.h +++ b/src/mc/world/level/block/registry/BlockTypeRegistry.h @@ -162,7 +162,7 @@ class BlockTypeRegistry { // NOLINTBEGIN // symbol: // ?_lookupByNameImpl@BlockTypeRegistry@@CA?AULookupByNameImplReturnType@1@AEBVHashedString@@HW4LookupByNameImplResolve@1@_N@Z - MCAPI static struct BlockTypeRegistry::LookupByNameImplReturnType _lookupByNameImpl( + MCAPI static struct ::BlockTypeRegistry::LookupByNameImplReturnType _lookupByNameImpl( class HashedString const& name, int data, ::BlockTypeRegistry::LookupByNameImplResolve resolve,