CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Attributes

hitfit::Refcount Class Reference

Simple reference-counted object. More...

#include <Refcount.h>

Inheritance diagram for hitfit::Refcount:
hitfit::Fit_Result

List of all members.

Public Member Functions

void decref () const
 Decrease the reference count.
bool decref_will_delete () const
 Return true if calling decref() will delete the object. Otherwise return FALSE.
void incref () const
 Increment the reference count.
 Refcount ()
 Constructor, initialize the reference count to 0.
bool unowned () const
 Return true if incref() has never been called or if the object is being deleted. Otherwise return FALSE.
virtual ~Refcount ()
 Destructor, it is an error to try to delete an object if the reference count is not 0.

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.

Private Attributes

unsigned _refcount

Detailed Description

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 68 of file Refcount.h.


Constructor & Destructor Documentation

hitfit::Refcount::Refcount ( )

Constructor, initialize the reference count to 0.

virtual hitfit::Refcount::~Refcount ( ) [virtual]

Destructor, it is an error to try to delete an object if the reference count is not 0.


Member Function Documentation

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().

void hitfit::Refcount::nuke_refcount ( ) [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 42 of file Refcount.cc.

References _refcount.

{
  _refcount = 0;
}
bool hitfit::Refcount::unowned ( ) const

Return true if incref() has never been called or if the object is being deleted. Otherwise return FALSE.


Member Data Documentation

unsigned hitfit::Refcount::_refcount [mutable, private]

The reference count itself.

Definition at line 132 of file Refcount.h.

Referenced by nuke_refcount().