The Micro C++ Library
|
The RefCountPtr template is used by SharedPtr to store a shared pointer that keeps a reference counter. More...
#include <micxx.hxx>
Public Member Functions | |
RefCountPtr (T *pointer=0) | |
Create a new RefCountPtr instance to pointer pointer. The reference counter is initialized with 1 . | |
virtual | ~RefCountPtr () |
Delete the stored pointer if is not 0 . | |
virtual RefCountPtr< T > & | operator++ () |
Increment the reference counter by 1 . | |
virtual RefCountPtr< T > & | operator-- () |
Decrement the reference counter by 1 . If the reference counter is decremented to 0 , the stored pointer is deleted. | |
virtual bool | operator! () |
Check, if the reference counter is 0 . | |
virtual RefCountPtr< T > & | operator= (T *pointer) |
Replace the old stored pointer with new pointer. The old stored pointer is deleted and the reference counter is reset to 1 . | |
virtual | operator T * () |
virtual | operator const T * () const |
virtual T * | release () |
Replace the old stored pointer with 0 . The old stored pointer is returned and not deleted. |
The RefCountPtr template is used by SharedPtr to store a shared pointer that keeps a reference counter.
A RefCountPtr maintains a pointer of type T*
and a reference counter. The reference counter could be incremented, decremented or checked against 0
. RefCountPtr itself only checks and guarantees, that the stored pointer is deleted either
0
, or1
.micxx::RefCountPtr< T >::RefCountPtr | ( | T * | pointer = 0 | ) |
Create a new RefCountPtr instance to pointer pointer. The reference counter is initialized with 1
.
pointer | The pointer to be stored, or 0 . |
: referenceCounter(1), pointer(apointer) { }
micxx::RefCountPtr< T >::~RefCountPtr | ( | ) | [virtual] |
Delete the stored pointer if is not 0
.
{ __MICXXTRY__ if (pointer) { delete pointer; pointer = 0; } __MICXXEND__ }
micxx::RefCountPtr< T >::operator const T * | ( | ) | const [virtual] |
const
. {
return pointer;
}
micxx::RefCountPtr< T >::operator T * | ( | ) | [virtual] |
{
return pointer;
}
bool micxx::RefCountPtr< T >::operator! | ( | ) | [virtual] |
Check, if the reference counter is 0
.
true
, if the reference counter is 0
false
, otherwise {
return !referenceCounter;
}
RefCountPtr< T > & micxx::RefCountPtr< T >::operator++ | ( | ) | [virtual] |
Increment the reference counter by 1
.
{ ++referenceCounter; return *this; }
RefCountPtr< T > & micxx::RefCountPtr< T >::operator-- | ( | ) | [virtual] |
Decrement the reference counter by 1
. If the reference counter is decremented to 0
, the stored pointer is deleted.
{ __MICXXTRY__ if (referenceCounter) { --referenceCounter; if (!referenceCounter && pointer) { delete pointer; pointer = 0; } } return *this; __MICXXEND__ }
RefCountPtr< T > & micxx::RefCountPtr< T >::operator= | ( | T * | pointer | ) | [virtual] |
Replace the old stored pointer with new pointer. The old stored pointer is deleted and the reference counter is reset to 1
.
{ __MICXXTRY__ if (pointer) { delete pointer; } referenceCounter = 1; pointer = apointer; return *this; __MICXXEND__ }
T * micxx::RefCountPtr< T >::release | ( | ) | [virtual] |
Replace the old stored pointer with 0
. The old stored pointer is returned and not deleted.
{
T * apointer = pointer;
referenceCounter = 1;
pointer = 0;
return apointer;
}