Base class providing referencing counted objects.
More...
#include <Referenced.h>
|
| Referenced () |
| Default constructor.
|
|
| Referenced (const Referenced &) |
|
template<typename T > |
T * | as () |
| Subclass casting.
|
|
template<typename T > |
const T * | as () const |
|
template<typename T > |
T * | asSafe () |
| Safe subclass casting, return nullptr if template type does not match.
|
|
template<typename T > |
const T * | asSafe () const |
|
int | getReferenceCount () const |
|
template<typename T > |
bool | is () const |
| Subclass test.
|
|
Referenced & | operator= (const Referenced &) |
| Assignment operator. Will increment the number of references to the referenced object.
|
|
void | reference (void *ptr=nullptr) const |
| Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.
|
|
void | unreference (void *ptr=nullptr) const |
| Decrement the reference count by one, indicating that a pointer to this object is referencing it.
|
|
void | unreference_nodelete () const |
| Decrement the reference count by one, indicating that a pointer to this object is referencing it.
|
|
Base class providing referencing counted objects.
Derive from this class when you need automatic reference counting for objects. Always keep the destructor of your derived class protected. One must never create a reference counted object on the stack. This will lead to corrupted memory if any reference pointers try to delete it.
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Smart pointer for handling referenced counted objects.
Definition at line 119 of file Referenced.h.
◆ Referenced() [1/2]
agx::Referenced::Referenced |
( |
| ) |
|
◆ Referenced() [2/2]
agx::Referenced::Referenced |
( |
const Referenced & |
| ) |
|
◆ ~Referenced()
virtual agx::Referenced::~Referenced |
( |
| ) |
|
|
protectedvirtual |
◆ allocateObserverVector()
void agx::Referenced::allocateObserverVector |
( |
| ) |
const |
|
protected |
◆ as() [1/2]
template<typename T >
T * agx::Referenced::as |
( |
| ) |
|
◆ as() [2/2]
template<typename T >
const T * agx::Referenced::as |
( |
| ) |
const |
◆ asSafe() [1/2]
template<typename T >
T * agx::Referenced::asSafe |
( |
| ) |
|
◆ asSafe() [2/2]
template<typename T >
const T * agx::Referenced::asSafe |
( |
| ) |
const |
◆ deleteUsingDeleteHandler()
void agx::Referenced::deleteUsingDeleteHandler |
( |
| ) |
const |
|
protected |
◆ getDeleteHandler()
◆ getReferenceCount()
int agx::Referenced::getReferenceCount |
( |
| ) |
const |
- Returns
- the number pointers currently referencing this object.
◆ is()
template<typename T >
bool agx::Referenced::is |
( |
| ) |
const |
◆ operator=()
Assignment operator. Will increment the number of references to the referenced object.
◆ reference()
void agx::Referenced::reference |
( |
void * |
ptr = nullptr | ) |
const |
Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.
This method should be used with care, always balanced with the same number of calls to unreference.
Referenced by agxData::Val< T >::Val().
◆ setDeleteHandler()
static void agx::Referenced::setDeleteHandler |
( |
DeleteHandler * |
handler | ) |
|
|
staticprotected |
Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.
◆ unreference()
void agx::Referenced::unreference |
( |
void * |
ptr = nullptr | ) |
const |
Decrement the reference count by one, indicating that a pointer to this object is referencing it.
If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.
This method should be used with care, always balanced with the same number of calls to reference.
◆ unreference_nodelete()
void agx::Referenced::unreference_nodelete |
( |
| ) |
const |
Decrement the reference count by one, indicating that a pointer to this object is referencing it.
However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.
◆ ValidateCast()
template<typename T >
static bool agx::Referenced::ValidateCast |
( |
const Referenced * |
object | ) |
|
|
static |
◆ m_mutex
Mutex agx::Referenced::m_mutex |
|
mutableprotected |
◆ m_observers
ObserverContainer agx::Referenced::m_observers |
|
mutableprotected |
◆ m_refCount
The documentation for this class was generated from the following file: