Simple reference-counted object. More...
#include <Refcount.h>
Public Member Functions | |
void | decref () const |
Decrease the reference count. More... | |
bool | decref_will_delete () const |
Return true if calling decref() will delete the object. Otherwise return FALSE. More... | |
void | incref () const |
Increment the reference count. More... | |
Refcount () | |
Constructor, initialize the reference count to 0. More... | |
bool | unowned () const |
Return true if incref() has never been called or if the object is being deleted. Otherwise return FALSE. More... | |
virtual | ~Refcount () |
Destructor, it is an error to try to delete an object if the reference count is not 0. More... | |
Protected Member Functions | |
void | nuke_refcount () |
Reset the reference count to zero. This should only be used in the context of a destructor of a derived class that wants to throw an exception. It may also be used to implement a "release" function. More... | |
Private Attributes | |
unsigned | _refcount |
Simple reference-counted object.
To make a reference-counted type, derive from this class. When the object is first created, its refcount is initialy set to 0. The first action taken by the creator should be to call incref() to increase the refcount to 1. Thereafter, the refcount may be incremented by incref() and decremented by decref(). If the reference count reaches 0, the object calls delete on itself.
If the object is deleted explicitly, the reference count must be 0 or 1. Otherwise, an assertion violation will be reported.
Definition at line 67 of file Refcount.h.
hitfit::Refcount::Refcount | ( | ) |
Constructor, initialize the reference count to 0.
|
virtual |
Destructor, it is an error to try to delete an object if the reference count is not 0.
void hitfit::Refcount::decref | ( | ) | const |
Decrease the reference count.
bool hitfit::Refcount::decref_will_delete | ( | ) | const |
Return true if calling decref() will delete the object. Otherwise return FALSE.
void hitfit::Refcount::incref | ( | ) | const |
Increment the reference count.
Referenced by hitfit::Fit_Result_Vec::push().
|
protected |
Reset the reference count to zero. This should only be used in the context of a destructor of a derived class that wants to throw an exception. It may also be used to implement a "release" function.
Definition at line 41 of file Refcount.cc.
References _refcount.
bool hitfit::Refcount::unowned | ( | ) | const |
Return true if incref() has never been called or if the object is being deleted. Otherwise return FALSE.
|
mutableprivate |
The reference count itself.
Definition at line 131 of file Refcount.h.
Referenced by nuke_refcount().