vpr::RefCountMemory Class Reference

Reference countable memory. More...

#include <vpr/Util/RefCountMemory.h>

List of all members.

Public Types

enum  States { BAD = -69 }

Public Member Functions

 RefCountMemory ()
 Default constructor.
 RefCountMemory (const RefCountMemory &r)
 On creation, refcount == 0, so if you intend to own the memory created, you should ref it.
RefCountMemoryoperator= (const RefCountMemory &r)
const int & ref ()
 Increases the reference count.
bool unrefDelete ()
 Decreases the reference count by 1, then call checkDelete.
const int & unref ()
 Decreases the reference count.
const int & getRef () const
 Gets the reference count.
const int & unrefGetRef ()
 Decreases the reference count by 1, return the new refcount.
virtual bool checkDelete ()
 If refcount <= 0, then delete the memory.

Protected Member Functions

virtual ~RefCountMemory ()
 Destructor.


Detailed Description

Reference countable memory.

(No, not radio controlled, sorry.)

To use reference counting on your objects, inherit from this class.

NOTES:

EXAMPLE USAGE: Object obj; obj.ref(); // count == 1; obj.ref(); // count == 2; int count = obj.getRef(); obj.unrefDelete(); // count == 1, memory is not deleted obj.unrefDelete(); // count == 0, memory is deleted

class Object : public vpr::RefCountMemory

Deprecated:
Use boost::shared_ptr<T> instead.

Definition at line 73 of file RefCountMemory.h.


Member Enumeration Documentation

enum vpr::RefCountMemory::States

Enumerator:
BAD 

Definition at line 76 of file RefCountMemory.h.

00077       {
00078          BAD = -69,
00079       };


Constructor & Destructor Documentation

vpr::RefCountMemory::RefCountMemory (  )  [inline]

Default constructor.

On creation, refcount == 0, so if you intend to own the memory created, you should ref it

Definition at line 152 of file RefCountMemory.h.

00152                                          : ___mNumTimesReferenced( 0 )
00153    {
00154    }

vpr::RefCountMemory::RefCountMemory ( const RefCountMemory r  )  [inline]

On creation, refcount == 0, so if you intend to own the memory created, you should ref it.

Definition at line 91 of file RefCountMemory.h.

00091                                                 : ___mNumTimesReferenced( 0 )
00092        {
00093           //dont copy ref number.
00094        }

virtual vpr::RefCountMemory::~RefCountMemory (  )  [inline, protected, virtual]

Destructor.

You MUST call checkDelete to delete, do not call delete!!!!!

Definition at line 101 of file RefCountMemory.h.

References BAD.

00102        {
00103           assert( ___mNumTimesReferenced != BAD && ___mNumTimesReferenced >= 0 && "this data has been dereferenced more times than referenced, someone is probably holding on to the data after they called deref(), or someone called deref too many times. also, make sure you use checkDelete, or unrefDelete." );
00104           ___mNumTimesReferenced = BAD;
00105        }


Member Function Documentation

RefCountMemory& vpr::RefCountMemory::operator= ( const RefCountMemory r  )  [inline]

Definition at line 108 of file RefCountMemory.h.

00109        {
00110           //dont copy ref number.
00111           return *this;
00112        }

const int & vpr::RefCountMemory::ref (  )  [inline]

Increases the reference count.

Definition at line 164 of file RefCountMemory.h.

References BAD, and getRef().

00165    {
00166       assert( ___mNumTimesReferenced != BAD && "this data has been deleted, someone is probably holding on to the data after they called deref()" );
00167       ++___mNumTimesReferenced;
00168       return this->getRef();
00169    }

bool vpr::RefCountMemory::unrefDelete (  )  [inline]

Decreases the reference count by 1, then call checkDelete.

This is equivalent to calling RefCountMemory::unref followed by RefCountMemory::checkDelete

Returns:
true if deleted; false if not.

Definition at line 207 of file RefCountMemory.h.

References checkDelete(), and unref().

00208    {
00209       this->unref();
00210       return this->checkDelete();
00211    }

const int & vpr::RefCountMemory::unref (  )  [inline]

Decreases the reference count.

Definition at line 172 of file RefCountMemory.h.

References BAD, and getRef().

Referenced by unrefDelete(), and unrefGetRef().

00173    {
00174       assert( ___mNumTimesReferenced != BAD && ___mNumTimesReferenced >= 0 && "this data has been dereferenced more times than referenced, someone is probably holding on to the data after they called deref(), or someone called deref too many times. also, make sure you use checkDelete, or unrefDelete." );
00175       --___mNumTimesReferenced;
00176       return this->getRef();
00177    }

const int & vpr::RefCountMemory::getRef (  )  const [inline]

Gets the reference count.

Definition at line 157 of file RefCountMemory.h.

References BAD.

Referenced by ref(), unref(), and unrefGetRef().

00158    {
00159       assert( ___mNumTimesReferenced != BAD && "this data has been deleted, someone is probably holding on to the data after they called deref()" );
00160       return ___mNumTimesReferenced;
00161    }

const int & vpr::RefCountMemory::unrefGetRef (  )  [inline]

Decreases the reference count by 1, return the new refcount.

Definition at line 214 of file RefCountMemory.h.

References getRef(), and unref().

00215    {
00216       this->unref();
00217       return this->getRef();
00218    }

bool vpr::RefCountMemory::checkDelete (  )  [inline, virtual]

If refcount <= 0, then delete the memory.

If the object has any refcountable children, then they will have RefCountMemory::unrefDelete() called on them.

Returns:
true if deleted, false if not

Definition at line 186 of file RefCountMemory.h.

References BAD.

Referenced by unrefDelete().

00187    {
00188       assert( ___mNumTimesReferenced != BAD && ___mNumTimesReferenced >= 0 && "this data has been dereferenced more times than referenced, someone is probably holding on to the data after they called deref(), or someone called deref too many times. also, make sure you use checkDelete, or unrefDelete." );
00189       if (___mNumTimesReferenced <= 0)
00190       {
00191          delete this;
00192          return true;
00193       }
00194       else
00195       {
00196          return false;
00197       }   
00198    }


The documentation for this class was generated from the following file:
Generated on Thu Jan 4 10:56:07 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1