Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ReferenceCounter Class Reference

#include <ReferenceCounter.h>

Inheritance diagram for ReferenceCounter:

Inheritance graph
[legend]
List of all members.

Detailed Description

Performs simple reference counting, will delete the object when removing the last reference.

Remember to call SetAutoDelete(false) if you instantiate a subclass on the stack instead of the heap -- don't want to try to free memory on the stack if/when last reference is removed! (The stack limits the allocation of the behavior to the current scope, so reference counting is moot.)

Todo:
It would be nice if there was a way for ReferenceCounter to automatically know whether it has been allocated on the stack... is that possible?

Definition at line 16 of file ReferenceCounter.h.

Public Member Functions

 ReferenceCounter ()
 constructor
 ReferenceCounter (const ReferenceCounter &rc)
 copy constructor - uses autodelete setting of rc, but references will still start at 0
ReferenceCounteroperator= (const ReferenceCounter &)
 assignment operator - does nothing because the reference count shouldn't be copied
virtual ~ReferenceCounter ()
 destructor - will std::cout a warning if still has references
virtual void AddReference ()
 adds one to references
virtual bool RemoveReference ()
 subtracts one from references AND DELETES the object IF ZERO (and RC_autodelete is set)
virtual unsigned int GetReferences () const
 returns the number of references
void SetAutoDelete (bool b)
 if true, next time a RemoveReference() causes references to hit 0, the object will delete itself
bool GetAutoDelete ()
 returns RC_autodelete

Protected Attributes

unsigned int references
 the current number of references
bool RC_autodelete
 if false, prevents deletion when counter hits 0


Member Function Documentation

virtual unsigned int ReferenceCounter::GetReferences (  )  const [inline, virtual]

returns the number of references

Returns:
references

Definition at line 48 of file ReferenceCounter.h.

virtual bool ReferenceCounter::RemoveReference (  )  [inline, virtual]


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

Tekkotsu v3.0
Generated Fri May 11 20:08:38 2007 by Doxygen 1.4.7