test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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

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
 

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 67 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 41 of file Refcount.cc.

References _refcount.

47 {
48  _refcount = 0;
49 }
unsigned _refcount
Definition: Refcount.h:131
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
mutableprivate

The reference count itself.

Definition at line 131 of file Refcount.h.

Referenced by nuke_refcount().