10#include <detail/preprocessor.hpp>
59 requires std::derived_from<T, DLReferenceCountObject>
63 int count() const noexcept {
64 return this->counter.load(std::memory_order_relaxed);
75 int value = this->counter.fetch_add(-1, std::memory_order_seq_cst);
79 throw std::runtime_error(
"bad unref() call");
82 std::atomic_int counter;
98 requires std::derived_from<T, DLReferenceCountObject>
119 requires std::convertible_to<U*, T*>
122 this->counter().ref();
142 requires std::convertible_to<U*, T*>
154 this->raw = std::exchange(other.raw,
nullptr);
168 requires std::convertible_to<U*, T*>
170 this->raw = std::exchange(other.raw,
nullptr);
175 this->counter().unref();
186 requires std::convertible_to<U*, T*>
189 this->counter().unref();
190 this->raw = other->
get();
192 this->counter().ref();
206 requires std::convertible_to<U*, T*>
209 this->counter().unref();
210 this->raw = std::exchange(other.raw,
nullptr);
220 this->counter().unref();
232 requires std::convertible_to<U*, T*>
235 this->counter().unref();
238 this->counter().ref();
247 std::swap(this->raw, other.raw);
284 explicit operator bool() const noexcept {
300template <
typename T,
typename U>
303 return lhs.
get() == rhs.
get();
310template <
typename T,
typename U>
313 return lhs.
get() <=> rhs.
get();
320template <
typename T,
typename U>
322 return lhs.
get() ==
nullptr;
329template <
typename T,
typename U>
332 return lhs.
get() <=>
nullptr;
335LIBER_ASSERTS_BEGIN(DLReferenceCountObject);
336LIBER_ASSERT_SIZE(0x10);
341LIBER_ASSERT_SIZE(0x8);
352template <
typename T,
typename... Args>
353 requires std::derived_from<T, DLUT::DLReferenceCountObject>
357 std::forward<Args>(args)...);
Base class used for non-copyable, but movable objects.
Definition utility.hpp:27
Abstract class for implementing reference counting garbage collection.
Definition utility.hpp:44
virtual void deleter()=0
The deleter method to call when reference count reaches zero.
A refcounted pointer that models std::shared_ptr<T>.
Definition utility.hpp:99
void reset(U *raw)
Replace the owned pointer (and decrement reference count).
Definition utility.hpp:233
void reset()
Reset the owned pointer (and decrement reference count).
Definition utility.hpp:218
T * operator->() const noexcept
Member access for the managed object.
Definition utility.hpp:275
T & operator*() const noexcept
Dereference the managed pointer.
Definition utility.hpp:266
DLReferenceCountPtr(DLReferenceCountPtr &&other) noexcept
Construct a new DLReferenceCountPtr object (move).
Definition utility.hpp:153
DLReferenceCountPtr & operator=(DLReferenceCountPtr< U > &&other)
Move assignment operator.
Definition utility.hpp:207
DLReferenceCountPtr(std::nullptr_t) noexcept
Construct a new DLReferenceCountPtr (std::nullopt).
Definition utility.hpp:109
DLReferenceCountPtr(const DLReferenceCountPtr &other) noexcept
Construct a new DLReferenceCountPtr object (copy).
Definition utility.hpp:130
DLReferenceCountPtr & operator=(const DLReferenceCountPtr< U > &other)
Copy assignment operator.
Definition utility.hpp:187
void swap(DLReferenceCountPtr &other)
Swap for DLReferenceCountPtr.
Definition utility.hpp:246
DLReferenceCountPtr(const DLReferenceCountPtr< U > &other) noexcept
Construct a new DLReferenceCountPtr object (copy, pointer conversion).
Definition utility.hpp:143
T * get() const noexcept
Get the managed pointer.
Definition utility.hpp:255
DLReferenceCountPtr(DLReferenceCountPtr< U > &&other) noexcept
Construct a new DLReferenceCountPtr object (move, pointer conversion).
Definition utility.hpp:169
DLReferenceCountPtr(U *raw) noexcept
Construct a new DLReferenceCountPtr (raw pointer).
Definition utility.hpp:120
The main libER stand-in for ER allocator proxies.
Definition from_allocator.hpp:310
ELDEN RING allocation interface and from::allocator.
Definition utility.hpp:339
std::strong_ordering operator<=>(const DLReferenceCountPtr< T > &lhs, const DLReferenceCountPtr< U > &rhs)
DLReferenceCountPtr comparison.
Definition utility.hpp:311
bool operator==(const DLReferenceCountPtr< T > &lhs, const DLReferenceCountPtr< U > &rhs)
DLReferenceCountPtr comparison.
Definition utility.hpp:301
DLUT::DLReferenceCountPtr< T > make_refcounted(Args &&... args)
Construct a reference counted object with the default libER allocator.
Definition utility.hpp:354