5 #ifndef DOXYGEN_SHOULD_SKIP_THIS
8 template<
typename T>
struct WeakRef;
29 Ref(std::nullptr_t) noexcept {}
35 explicit Ref(T* ptr) noexcept { *
this = ptr; }
41 Ref(
const Ref& other) noexcept { *
this = other; }
43 #ifndef DOXYGEN_SHOULD_SKIP_THIS
48 Ref(
const WeakRef<T>& other) noexcept { *
this = other; }
73 this->
get()->release();
85 return this->
get() == other.get();
93 return !(*
this == other);
96 #ifndef DOXYGEN_SHOULD_SKIP_THIS
111 return assign(other.get());
137 if(this->
get() != ptr)
140 this->
get()->release();
147 if(this->
get() && this->
get()->retain() < 1)
158 if(this->
get() != ptr)
161 this->
get()->release();
174 T* ptr = this->
get();
183 return Ref<S>(
static_cast<S*
>(this->
get()));
203 template<
typename S,
typename T>
205 return Ref<S>(
static_cast<S*
>(ptr));
226 template<
typename S,
typename T>
229 ref.
acquire(static_cast<S*>(ptr));
bool operator==(const Ref &other) const noexcept
Check if two refs are the same.
Definition: Ref.h:84
Ref & operator=(const Ref &other) noexcept
Assign a strong reference.
Definition: Ref.h:110
Ref & acquire(T *ptr) noexcept
Acquire ownership of the object.
Definition: Ref.h:157
Ref< T > make_ref(T *ptr) noexcept
Make smart reference to a IRefCounted based object.
Definition: Ref.h:193
Ref< S > as() const noexcept
Make smart reference with relative type.
Definition: Ref.h:182
Ref(const Ref &other) noexcept
Initializes object pointer with other and retains a reference.
Definition: Ref.h:41
Smart pointer for reference counted objects.
Definition: Ref.h:20
~Ref() noexcept
Releases reference being held (if any).
Definition: Ref.h:54
T * reset() noexcept
Reset reference counted object and assign nullptr to the pointer.
Definition: Ref.h:173
bool operator!=(const Ref &other) const noexcept
Check if two refs are not the same.
Definition: Ref.h:92
Generic base class of a pointer for reference counted objects.
Definition: RefBase.h:15
T * m_ptr
Raw pointer.
Definition: RefBase.h:104
Ref(T *ptr) noexcept
Initializes object pointer with ptr and retains a reference.
Definition: Ref.h:35
void set(T *ptr) noexcept
Replace object pointer without any checks or reference management.
Definition: RefBase.h:99
Ref(std::nullptr_t) noexcept
Initializes object pointer to nullptr.
Definition: Ref.h:29
bool isNull() const noexcept
Check for nullptr.
Definition: RefBase.h:68
Ref< S > acquire_as(T *ptr) noexcept
Acquire ownership of IRefCounted based object with a cast to a given type.
Definition: Ref.h:227
Ref & assign(T *ptr) noexcept
Assign an object. Presumes shared ownership, increases reference count.
Definition: Ref.h:136
T ** getInitReference() noexcept
Access pointer for initialization.
Definition: Ref.h:71
T * operator->() const noexcept
Access pointer.
Definition: Ref.h:62
Ref< S > make_ref_as(T *ptr) noexcept
Make smart reference to a IRefCounted based object.
Definition: Ref.h:204
Ref() noexcept
Constructor. Initializes object pointer to nullptr.
Definition: Ref.h:25
Ref< T > acquire(T *ptr) noexcept
Acquire ownership of IRefCounted based object.
Definition: Ref.h:214