#include <RefCountMemory.h>
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... | |
(no, not radio controlled, sorry)
To use reference counting on your objects, inherit from this class.
NOTES:
class Object : public vpr::RefCountMemory
Definition at line 70 of file RefCountMemory.h.
|
|
Definition at line 73 of file RefCountMemory.h.
00074 {
00075 BAD = -69,
00076 };
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
Definition at line 105 of file RefCountMemory.h. References RefCountMemory.
00106 {
00107 //dont copy ref number.
00108 return *this;
00109 }
|
|
|
Increases the reference count.
Definition at line 161 of file RefCountMemory.h.
|
|
|
Decreases the reference count by 1, then call checkDelete. This is equivalent to calling RefCountMemory::unref followed by RefCountMemory::checkDelete
Definition at line 204 of file RefCountMemory.h. References checkDelete, and unref.
00205 {
00206 this->unref();
00207 return this->checkDelete();
00208 }
|
|
|
Decreases the reference count.
Definition at line 169 of file RefCountMemory.h. 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 }
|
|
|
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 }
|
|
|
Decreases the reference count by 1, return the new refcount.
Definition at line 211 of file RefCountMemory.h.
|
|
|
If refcount <= 0, then delete the memory. If the object has any refcountable children, then they will have RefCountMemory::unrefDelete() called on them.
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 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002