4#include <Foundation/Threading/AtomicUtils.h>
37 return m_iRefCount > 0;
47 mutable plInt32 m_iRefCount = 0;
69 : m_pReferencedObject(nullptr)
75 : m_pReferencedObject(pReferencedObject)
77 AddReferenceIfValid();
82 m_pReferencedObject = other.m_pReferencedObject;
84 AddReferenceIfValid();
94 if (pNewReference == m_pReferencedObject)
97 ReleaseReferenceIfValid();
99 m_pReferencedObject = pNewReference;
101 AddReferenceIfValid();
108 if (other.m_pReferencedObject == m_pReferencedObject)
111 ReleaseReferenceIfValid();
113 m_pReferencedObject = other.m_pReferencedObject;
115 AddReferenceIfValid();
119 operator const T*()
const {
return m_pReferencedObject; }
122 operator T*() {
return m_pReferencedObject; }
127 PL_ASSERT_DEV(m_pReferencedObject !=
nullptr,
"Pointer is nullptr.");
128 return m_pReferencedObject;
134 PL_ASSERT_DEV(m_pReferencedObject !=
nullptr,
"Pointer is nullptr.");
135 return m_pReferencedObject;
140 inline void AddReferenceIfValid()
142 if (m_pReferencedObject !=
nullptr)
144 m_pReferencedObject->AddRef();
149 inline void ReleaseReferenceIfValid()
151 if (m_pReferencedObject !=
nullptr)
153 m_pReferencedObject->ReleaseRef();
157 T* m_pReferencedObject;
161template <
typename TYPE>
Definition RefCounted.h:163
Base class for reference counted objects.
Definition RefCounted.h:52
virtual ~plRefCounted()=default
Adds a virtual destructor.
Definition RefCounted.h:7
plInt32 ReleaseRef() const
Decrements the reference counter. Returns the new reference count.
Definition RefCounted.h:29
plRefCountingImpl()=default
Constructor.
bool IsReferenced() const
Returns true if the reference count is greater than 0, false otherwise.
Definition RefCounted.h:35
plInt32 GetRefCount() const
Returns the current reference count.
Definition RefCounted.h:41
plInt32 AddRef() const
Increments the reference counter. Returns the new reference count.
Definition RefCounted.h:23
Stores a pointer to a reference counted object and automatically increases / decreases the reference ...
Definition RefCounted.h:65
plScopedRefPointer()
Constructor.
Definition RefCounted.h:68
void operator=(const plScopedRefPointer< T > &other)
Assignment operator, decreases the ref count of the currently referenced object and increases the ref...
Definition RefCounted.h:106
T * operator->()
Returns the referenced object (may be nullptr)
Definition RefCounted.h:132
const T * operator->() const
Returns the referenced object (may be nullptr).
Definition RefCounted.h:125
void operator=(T *pNewReference)
Assignment operator, decreases the ref count of the currently referenced object and increases the ref...
Definition RefCounted.h:92
plScopedRefPointer(T *pReferencedObject)
Constructor, increases the ref count of the given object.
Definition RefCounted.h:74
~plScopedRefPointer()
Destructor - releases the reference on the ref-counted object (if there is one).
Definition RefCounted.h:88
static plInt32 Decrement(plInt32 &ref_iDest)
Decrements dest as an atomic operation and returns the new value.
Definition AtomicUtils_posix.h:31
static plInt32 Increment(plInt32 &ref_iDest)
Increments dest as an atomic operation and returns the new value.
Definition AtomicUtils_posix.h:20