Intrusive reference-counted smart pointer. More...
#include <Ref.h>
Public Member Functions | |
| Ref (T *ptr=nullptr) | |
| Constructs a Ref from a raw pointer. | |
| Ref (const Ref &other) noexcept | |
| Copy constructor. Increments reference count. | |
| Ref (Ref &&other) noexcept | |
| Move constructor. Transfers ownership without increment. | |
| template<typename T2> requires (std::is_convertible_v<T2*, T*>) | |
| Ref (const Ref< T2 > &other) noexcept | |
| Copy constructor from compatible Ref<T2>. | |
| template<typename T2> requires (std::is_convertible_v<T2*, T*>) | |
| Ref (Ref< T2 > &&other) noexcept | |
| Move constructor from compatible Ref<T2>. | |
| ~Ref () | |
| Destructor. Decrements reference count and deletes if zero. | |
| Ref & | operator= (const Ref &other) noexcept |
| Copy assignment. Adjusts reference counts appropriately. | |
| Ref & | operator= (Ref &&other) noexcept |
| Move assignment. Transfers ownership. | |
| template<typename T2> | |
| Ref< T2 > | As () const |
| Casts this Ref to a compatible Ref<T2>. | |
| T * | Get () noexcept |
| Gets the raw managed pointer. | |
| const T * | Get () const noexcept |
| Gets the raw managed pointer (const). | |
| T & | operator* () |
| Dereference operator. | |
| const T & | operator* () const |
| Dereference operator (const). | |
| T * | operator-> () |
| Arrow operator. | |
| const T * | operator-> () const |
| Arrow operator (const). | |
| operator bool () const noexcept | |
| Bool conversion. True if managing a non-null pointer. | |
| bool | operator== (const Ref< T > &other) const noexcept |
| Equality comparison. | |
| bool | operator!= (const Ref< T > &other) const noexcept |
| Inequality comparison. | |
| void | Release () |
| Manually releases this reference. | |
| void | Delete () |
| Deletes the managed object immediately. | |
| void | Reset (T *ptr=nullptr) noexcept |
| Resets this Ref to manage a new pointer. | |
Static Public Member Functions | |
| template<typename... Args> | |
| static Ref< T > | Create (Args &&... args) |
| Creates a Ref<T> by allocating with rnew. | |
Friends | |
| template<typename T2> | |
| class | Ref |
Intrusive reference-counted smart pointer.
Ref<T> provides shared ownership of an object derived from RefCounted. The lifetime of the object is automatically managed through an atomic reference counter stored inside the object.
When the last Ref<T> referencing an object is destroyed or reset, the object is deleted using rdelete.
| T | Type of the managed object. |
|
inline |
Constructs a Ref from a raw pointer.
| ptr | Pointer to manage (must inherit RefCounted). |
|
inlinenoexcept |
Copy constructor. Increments reference count.
|
inlinenoexcept |
Move constructor. Transfers ownership without increment.
|
inlinenoexcept |
Copy constructor from compatible Ref<T2>.
| T2 | Convertible type to T. |
|
inlinenoexcept |
Move constructor from compatible Ref<T2>.
| T2 | Convertible type to T. |
|
inline |
Destructor. Decrements reference count and deletes if zero.
Casts this Ref to a compatible Ref<T2>.
Allows upcasting or downcasting between related types. Compile-time checked to ensure types are related.
| T2 | Target type. |
|
inlinestatic |
Creates a Ref<T> by allocating with rnew.
Constructs T in-place and returns a Ref managing it.
| Args | Constructor argument types. |
| args | Arguments forwarded to T constructor. |
|
inline |
Deletes the managed object immediately.
Forces deletion via rdelete and clears the pointer. Use with caution.
|
inlinenoexcept |
Gets the raw managed pointer (const).
|
inlinenoexcept |
Gets the raw managed pointer.
|
inlineexplicitnoexcept |
Bool conversion. True if managing a non-null pointer.
|
inlinenoexcept |
Inequality comparison.
|
inline |
Dereference operator.
|
inline |
Dereference operator (const).
|
inline |
Arrow operator.
|
inline |
Arrow operator (const).
|
inlinenoexcept |
Copy assignment. Adjusts reference counts appropriately.
|
inlinenoexcept |
Move assignment. Transfers ownership.
|
inlinenoexcept |
Equality comparison.
|
inline |
Manually releases this reference.
Decrements reference count and deletes the object if this was the last owner.
|
inlinenoexcept |
Resets this Ref to manage a new pointer.
| ptr | New pointer (default nullptr). |
|
friend |
Allow Ref<T2> access.