7 #ifndef DOXYGEN_SHOULD_SKIP_THIS
10 template<
typename T>
struct WeakRef;
31 Ref(std::nullptr_t) noexcept {}
37 explicit Ref(T* ptr) noexcept { *
this = ptr; }
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50 Ref(
const WeakRef<T>& other) noexcept { *
this = other; }
75 this->
get()->release();
87 return this->
get() == other.get();
95 return !(*
this == other);
98 #ifndef DOXYGEN_SHOULD_SKIP_THIS
113 return assign(other.get());
139 if(this->
get() != ptr)
142 this->
get()->release();
149 if(this->
get() && this->
get()->retain() < 1)
160 if(this->
get() != ptr)
163 this->
get()->release();
176 T* ptr = this->
get();
185 return Ref<S>(
static_cast<S*
>(this->
get()));
205 template<
typename S,
typename T>
207 return Ref<S>(
static_cast<S*
>(ptr));
228 template<
typename S,
typename T>
231 ref.
acquire(static_cast<S*>(ptr));
bool operator==(const Ref &other) const noexcept
Check if two refs are the same.
Definition: Ref.h:86
Ref & operator=(const Ref &other) noexcept
Assign a strong reference.
Definition: Ref.h:112
Ref & acquire(T *ptr) noexcept
Acquire ownership of the object.
Definition: Ref.h:159
Ref< T > make_ref(T *ptr) noexcept
Make smart reference to a IRefCounted based object.
Definition: Ref.h:195
Ref< S > as() const noexcept
Make smart reference with relative type.
Definition: Ref.h:184
Smart pointer for reference counted objects.
Definition: Ref.h:22
~Ref() noexcept
Releases reference being held (if any).
Definition: Ref.h:56
T * reset() noexcept
Reset reference counted object and assign nullptr to the pointer.
Definition: Ref.h:175
bool operator!=(const Ref &other) const noexcept
Check if two refs are not the same.
Definition: Ref.h:94
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:37
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:31
bool isNull() const noexcept
Check for nullptr.
Definition: RefBase.h:68
Ref(const Ref &other)
Initializes object pointer with other and retains a reference.
Definition: Ref.h:43
Ref< S > acquire_as(T *ptr) noexcept
Acquire ownership of IRefCounted based object with a cast to a given type.
Definition: Ref.h:229
Ref & assign(T *ptr) noexcept
Assign an object. Presumes shared ownership, increases reference count.
Definition: Ref.h:138
T ** getInitReference() noexcept
Access pointer for initialization.
Definition: Ref.h:73
T * operator->() const noexcept
Access pointer.
Definition: Ref.h:64
Ref< S > make_ref_as(T *ptr) noexcept
Make smart reference to a IRefCounted based object.
Definition: Ref.h:206
Ref() noexcept
Constructor. Initializes object pointer to nullptr.
Definition: Ref.h:27
Ref< T > acquire(T *ptr) noexcept
Acquire ownership of IRefCounted based object.
Definition: Ref.h:216