|
SleakEngine 1.0.0
C++23 multi-backend game engine
|
#include <RefPtr.hpp>
Public Member Functions | |
| RefPtr (const RefPtr &other) | |
| template<typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>> | |
| RefPtr (const RefPtr< U > &other) | |
| RefPtr (RefPtr &&other) noexcept | |
| RefPtr (T *p=nullptr) | |
| ~RefPtr () | |
| T * | get () const |
| RefPtr & | operator= (const RefPtr &other) |
| template<typename U> | |
| RefPtr & | operator= (const RefPtr< U > &other) |
| RefPtr & | operator= (RefPtr &&other) noexcept |
| RefPtr & | operator= (std::nullptr_t) noexcept |
| void | release () |
| Drops one reference, deleting the object and control block at zero. | |
| void | reset (T *newPtr=nullptr) override |
| size_t | use_count () const |
| Public Member Functions inherited from Sleak::SmartPointer< T > | |
| SmartPointer (const SmartPointer &)=delete | |
| virtual | ~SmartPointer () |
| T * | get () const |
| Raw pointer access; throws NullPointerException if unset. | |
| virtual bool | IsValid () const |
| True if the pointer is non-null. | |
| operator bool () const | |
| T & | operator* () const |
| T * | operator-> () const |
| SmartPointer & | operator= (const SmartPointer &)=delete |
Protected Member Functions | |
| SharedControlBlock * | getControlBlock () const |
| Protected Member Functions inherited from Sleak::SmartPointer< T > | |
| SmartPointer (T *p=nullptr) | |
Protected Attributes | |
| SharedControlBlock * | controlBlock |
| Protected Attributes inherited from Sleak::SmartPointer< T > | |
| T * | ptr |
Friends | |
| template<typename U> | |
| class | RefPtr |
Atomic, intrusive-refcount smart pointer for engine resources. This is the standard owning pointer in the engine, used instead of shared_ptr.
Construct one from a raw pointer and it takes ownership, deleting the object when the last RefPtr to it goes away. Copies share the count; moves transfer it. Use this wherever the public API asks for an owning pointer, notably Material and the GPU buffer handles on MeshHandle.
The constructor is explicit, so ownership transfer is always visible at the call site. Converting RefPtr<Derived> to RefPtr<Base> is allowed and keeps the same control block. use_count() reports the current reference count.
The reference count is thread-safe. The object it guards is not: two threads calling into the same pointed-to object still need their own synchronization. Note also that get() on the SmartPointer base throws NullPointerException when the pointer is null, so test with IsValid() or the bool conversion before dereferencing an optional resource.
Definition at line 62 of file RefPtr.hpp.
|
inlineexplicit |
Definition at line 81 of file RefPtr.hpp.
|
inline |
Definition at line 85 of file RefPtr.hpp.
|
inline |
Definition at line 88 of file RefPtr.hpp.
|
inlinenoexcept |
Definition at line 109 of file RefPtr.hpp.
|
inline |
Definition at line 129 of file RefPtr.hpp.
|
inline |
Definition at line 170 of file RefPtr.hpp.
|
inlineprotected |
Definition at line 174 of file RefPtr.hpp.
|
inline |
Definition at line 96 of file RefPtr.hpp.
|
inline |
Definition at line 136 of file RefPtr.hpp.
|
inlinenoexcept |
Definition at line 116 of file RefPtr.hpp.
|
inlinenoexcept |
Definition at line 150 of file RefPtr.hpp.
|
inline |
Drops one reference, deleting the object and control block at zero.
Definition at line 74 of file RefPtr.hpp.
|
inlineoverridevirtual |
Implements Sleak::SmartPointer< T >.
Definition at line 158 of file RefPtr.hpp.
|
inline |
Definition at line 165 of file RefPtr.hpp.
|
friend |
Definition at line 65 of file RefPtr.hpp.
|
protected |
Definition at line 68 of file RefPtr.hpp.