RefCnt Pile
version 0.0.1
C++ class implementing a simple reference counting mechanism.
|
A reference counted base class. More...
#include <refcnt.h>
Public Member Functions | |
int | reference (void *owner) |
int | dereference (void *owner) |
int | release (void *owner) |
int | referenceCount () |
int | forceRelease () |
void | changeOwner (void *, void *) |
bool | isOwner (void *) |
Protected Member Functions | |
RefCnt () | |
Default constructor. | |
virtual | ~RefCnt () |
Destructor. | |
A reference counted base class.
In debug builds an internal list of owners is stored so that allocations can be traced. In release builds this adds no overhead. This is controlled using the REFCNT_DEBUG definition.
|
inline |
change the owner of a reference
This does absolutely nothing in release builds.
int RefCnt::dereference | ( | void * | owner | ) |
decrements the reference counter
int RefCnt::forceRelease | ( | ) |
deletes the instance
|
inline |
tell if a pointer owns a reference to this object
In release builds this always returns false.
int RefCnt::reference | ( | void * | owner | ) |
increments the reference counter
|
inline |
get the value of the reference count
int RefCnt::release | ( | void * | owner | ) |
decrements the reference counter and deletes the instance if 0
The caller must make sure that the reference count does not go below 0.