Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

vpr::RefCountMemory Class Reference

reference countable memory. More...

#include <RefCountMemory.h>

List of all members.

Public Types

enum  States { BAD = -69 }

Public Methods

 RefCountMemory ()
 Default constructor. More...

 RefCountMemory (const RefCountMemory &r)
 On creation, refcount == 0, so if you intend to own the memory created, you should ref it. More...

RefCountMemory & operator= (const RefCountMemory &r)
const int & ref ()
 Increases the reference count. More...

bool unrefDelete ()
 Decreases the reference count by 1, then call checkDelete. More...

const int & unref ()
 Decreases the reference count. More...

const int & getRef () const
 Gets the reference count. More...

const int & unrefGetRef ()
 Decreases the reference count by 1, return the new refcount. More...

virtual bool checkDelete ()
 If refcount <= 0, then delete the memory. More...


Protected Methods

virtual ~RefCountMemory ()
 Destructor. More...


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

Definition at line 70 of file RefCountMemory.h.


Member Enumeration Documentation

enum vpr::RefCountMemory::States
 

Enumeration values:
BAD 

Definition at line 73 of file RefCountMemory.h.

00074       {
00075          BAD = -69,
00076       };


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 149 of file RefCountMemory.h.

Referenced by operator=, and RefCountMemory.

00149                                          : ___mNumTimesReferenced( 0 )
00150    {
00151    }

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 88 of file RefCountMemory.h.

References RefCountMemory.

00088                                                 : ___mNumTimesReferenced( 0 )
00089        {
00090           //dont copy ref number.
00091        }

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

Destructor.

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

Definition at line 98 of file RefCountMemory.h.

References BAD.

00099        {
00100           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." );
00101           ___mNumTimesReferenced = BAD;
00102        }


Member Function Documentation

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

Definition at line 105 of file RefCountMemory.h.

References RefCountMemory.

00106        {
00107           //dont copy ref number.
00108           return *this;
00109        }

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

Increases the reference count.

Definition at line 161 of file RefCountMemory.h.

References BAD, and getRef.

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

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 204 of file RefCountMemory.h.

References checkDelete, and unref.

00205    {
00206       this->unref();
00207       return this->checkDelete();
00208    }

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

Decreases the reference count.

Definition at line 169 of file RefCountMemory.h.

References BAD, and getRef.

Referenced by unrefDelete, and unrefGetRef.

00170    {
00171       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." );
00172       --___mNumTimesReferenced;
00173       return this->getRef();
00174    }

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

Gets the reference count.

Definition at line 154 of file RefCountMemory.h.

References BAD.

Referenced by ref, unref, and unrefGetRef.

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

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

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

Definition at line 211 of file RefCountMemory.h.

References getRef, and unref.

00212    {
00213       this->unref();
00214       return this->getRef();
00215    }

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 183 of file RefCountMemory.h.

References BAD.

Referenced by unrefDelete.

00184    {
00185       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." );
00186       if (___mNumTimesReferenced <= 0)
00187       {
00188          delete this;
00189          return true;
00190       }
00191       else
00192       {
00193          return false;
00194       }   
00195    }


The documentation for this class was generated from the following file:
Generated on Sun May 2 14:47:17 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002