OpenCurves  0.9
plotutil::RefCountObject< T > Class Template Reference

A base class for adding reference counting to a class. More...

#include <refcountobject.h>

Public Member Functions

 RefCountObject ()
 Constructor, setting a zero reference count.
 
 RefCountObject (int initialCount)
 Constructor, setting the given initial reference count. More...
 
int referenceCount () const
 Access the current reference count. More...
 
int addReference ()
 Increment and return the reference count. More...
 
int decReference ()
 Decrement the reference count. More...
 

Detailed Description

template<class T>
class plotutil::RefCountObject< T >

A base class for adding reference counting to a class.

Usage: derive this class, using the derived class as the template type. For example:

class MyRefClass : public RefCountObject<MyRefClass>
{
//...
};

Call addReference() and decReference() to adjust the reference count. A call to decReference() may immediately delete the object when the decremented reference count is zero or less.

Note
This class is non-virtual and will not introduce a virtual function table. This is the reason for the template type parameter.

Constructor & Destructor Documentation

template<class T>
plotutil::RefCountObject< T >::RefCountObject ( int  initialCount)
inline

Constructor, setting the given initial reference count.

Parameters
initialCountThe initial reference count.

Member Function Documentation

template<class T>
int plotutil::RefCountObject< T >::addReference ( )
inline

Increment and return the reference count.

Returns
The post increment reference count.
template<class T >
int plotutil::RefCountObject< T >::decReference ( )

Decrement the reference count.

The object is deleted if this results in a zero or negative reference count.

Returns
The decremented reference count.
template<class T>
int plotutil::RefCountObject< T >::referenceCount ( ) const
inline

Access the current reference count.

Returns
The current reference count.

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