libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
ObjectBasePtr Class Reference

Object that holds a pointer to an ObjectBase (or derived) object. This class will register itself with the given ObjectBase object. When the registered ObjectBase object is destroyed, it will null the internal pointer. You can use this object to ensure you don't have dangling pointers to ObjectBase objects. More...

#include <objectbase.h>

Public Member Functions

 ObjectBasePtr (ObjectBase *object=nullptr)
 
 ObjectBasePtr (const ObjectBasePtr &object)
 Copy constructor. Tracks the same ObjectBase as the source.
 
 ~ObjectBasePtr ()
 Destructor. Unlinks from the tracked ObjectBase.
 
ObjectBasePtroperator= (const ObjectBasePtr &object)
 Copy assignment operator. Re-links to the new ObjectBase.
 
bool isValid () const
 Returns true if the tracked pointer is not null.
 
ObjectBasedata ()
 Returns a mutable pointer to the tracked ObjectBase.
 
const ObjectBasedata () const
 Returns a const pointer to the tracked ObjectBase.
 

Friends

class ObjectBase
 

Detailed Description

Object that holds a pointer to an ObjectBase (or derived) object. This class will register itself with the given ObjectBase object. When the registered ObjectBase object is destroyed, it will null the internal pointer. You can use this object to ensure you don't have dangling pointers to ObjectBase objects.

Note
Thread safety: The internal pointer is stored as a std::atomic, and the ObjectBase pointer map is protected by a Mutex. This allows an ObjectBasePtr to be safely invalidated from a different thread than the one holding it, as happens during cross-thread object destruction. However, the ObjectBasePtr itself is not designed for concurrent read/write from multiple threads without external synchronization.

The documentation for this class was generated from the following file: