10#include <detail/preprocessor.hpp>
68 return this->counter.load(std::memory_order_relaxed);
87 int value = this->counter.fetch_add(-1, std::memory_order_seq_cst);
91 throw std::runtime_error(
"bad unref() call");
105 template <typename T, typename... Args>
107 friend inline auto make_refcounted();
109 std::atomic_int counter = 0;
146 requires std::convertible_to<U*, T*>
149 this->counter().ref();
169 requires std::convertible_to<U*, T*>
181 this->raw = std::exchange(other.raw,
nullptr);
195 requires std::convertible_to<U*, T*>
197 this->raw = std::exchange(other.raw,
nullptr);
202 this->counter().unref();
213 requires std::convertible_to<U*, T*>
216 this->counter().unref();
217 this->raw = other->
get();
219 this->counter().ref();
233 requires std::convertible_to<U*, T*>
236 this->counter().unref();
237 this->raw = std::exchange(other.raw,
nullptr);
247 this->counter().unref();
259 requires std::convertible_to<U*, T*>
262 this->counter().unref();
265 this->counter().ref();
274 std::swap(this->raw, other.raw);
311 explicit operator bool() const noexcept {
327template <
typename T,
typename U>
330 return lhs.
get() == rhs.
get();
337template <
typename T,
typename U>
340 return lhs.
get() <=> rhs.
get();
347template <
typename T,
typename U>
349 return lhs.
get() ==
nullptr;
356template <
typename T,
typename U>
359 return lhs.
get() <=>
nullptr;
363LIBER_ASSERT_SIZE(0x10);
368LIBER_ASSERT_SIZE(0x8);
380template <
typename T,
typename... Args>
381 requires std::derived_from<T, DLUT::DLReferenceCountObject>
384 using altraits = std::allocator_traits<
decltype(
allocator)>;
388 altraits::construct(
allocator, p, std::forward<Args>(args)...);
Base class used for non-copyable, but movable objects.
Definition utility.hpp:27
Class for implementing reference counting garbage collection.
Definition utility.hpp:47
DLReferenceCountObject() noexcept=default
Protected DLReferenceCountObject constructor.
void ref() noexcept
Increment the object's reference count.
Definition utility.hpp:75
void unref()
Unreference object; there cannot be more ref() calls than unref() calls.
Definition utility.hpp:86
virtual void deleter()
The deleter method to call when reference count reaches zero.
Definition utility.hpp:55
int count() const noexcept
Get number of references to object.
Definition utility.hpp:67
A refcounted pointer that models std::shared_ptr<T>.
Definition utility.hpp:126
void reset(U *raw)
Replace the owned pointer (and decrement reference count).
Definition utility.hpp:260
void reset()
Reset the owned pointer (and decrement reference count).
Definition utility.hpp:245
T * operator->() const noexcept
Member access for the managed object.
Definition utility.hpp:302
T & operator*() const noexcept
Dereference the managed pointer.
Definition utility.hpp:293
DLReferenceCountPtr(DLReferenceCountPtr &&other) noexcept
Construct a new DLReferenceCountPtr object (move).
Definition utility.hpp:180
DLReferenceCountPtr & operator=(DLReferenceCountPtr< U > &&other)
Move assignment operator.
Definition utility.hpp:234
DLReferenceCountPtr(std::nullptr_t) noexcept
Construct a new DLReferenceCountPtr (std::nullptr_t).
Definition utility.hpp:136
DLReferenceCountPtr(const DLReferenceCountPtr &other) noexcept
Construct a new DLReferenceCountPtr object (copy).
Definition utility.hpp:157
DLReferenceCountPtr & operator=(const DLReferenceCountPtr< U > &other)
Copy assignment operator.
Definition utility.hpp:214
void swap(DLReferenceCountPtr &other)
Swap for DLReferenceCountPtr.
Definition utility.hpp:273
DLReferenceCountPtr(const DLReferenceCountPtr< U > &other) noexcept
Construct a new DLReferenceCountPtr object (copy, pointer conversion).
Definition utility.hpp:170
T * get() const noexcept
Get the managed pointer.
Definition utility.hpp:282
DLReferenceCountPtr(DLReferenceCountPtr< U > &&other) noexcept
Construct a new DLReferenceCountPtr object (move, pointer conversion).
Definition utility.hpp:196
DLReferenceCountPtr(U *raw) noexcept
Construct a new DLReferenceCountPtr (raw pointer).
Definition utility.hpp:147
The main libER stand-in for ER allocator proxies.
Definition from_allocator.hpp:308
ELDEN RING allocation interface and from::allocator.
from::allocator< T > get_allocator_of(const T *p) noexcept
Get the allocator of an object allocated by ELDEN RING.
Definition from_allocator.hpp:426
Definition utility.hpp:366
std::strong_ordering operator<=>(const DLReferenceCountPtr< T > &lhs, const DLReferenceCountPtr< U > &rhs)
DLReferenceCountPtr comparison.
Definition utility.hpp:338
auto make_refcounted(Args &&... args)
Construct a reference counted object with the default libER allocator.
Definition utility.hpp:382
bool operator==(const DLReferenceCountPtr< T > &lhs, const DLReferenceCountPtr< U > &rhs)
DLReferenceCountPtr comparison.
Definition utility.hpp:328