#include <DelPtr.h>
Public Methods | |
DelPtr (T* pPtr = 0) | |
The only argument of the constructor, that defaults to 0, is a pointer type. The value of this argument is the value that the stored pointer is intialised to. | |
~DelPtr () | |
The destructor deletes the object pointed to by the stored pointer. Notice that this happens even if the stored pointer is 0 (NULL), but of course delete doesn't do anything in this situation. | |
T* | operator-> () const |
The selection operator effectively returns GetPtr(), so that the expression obj->m behaves the same as (obj.GetPtr())->m, where obj is an object of type DelPtr. Do not call this function if the stored pointer is 0 (NULL). | |
T* | GetPtr () const |
GetPtr() returns the value of the stored pointer. | |
void | SetPtr (T* pPtr) |
SetPtr() assigns the value of the pPtr argument to the stored pointer. | |
ppInt8 | IsNull () const |
IsNull() returns zero if the stored pointer is equal to 0 (NULL). In any other case, IsNull() returns a non-zero value. | |
void | Release () |
Release() sets the stored pointer to 0 (NULL). This means that the destructor will not delete anything, as no object is pointed to. | |
DelPtr<T>& | operator= (T* pPtr) |
The assignment operator assigns the value of the pPtr argument to the stored pointer. The return value of the assignment operator is the object for which it was envoked(ie,equal to *this). | |
operator T * () const | |
The T* conversion operator returns the value of the stored pointer. | |
Protected Attributes | |
T* | m_pPtr |
This is the variable used to hold the stored pointer. |
DelPtr is a toned-down version of the standard library class auto_ptr. The difference is that DelPtr does not store an ownership indicator, which allows it to have a smaller overhead than auto_ptr.
The only overhead imposed by using DelPtr is that the stored pointer is deleted in the destructor of DelPtr, regardless of wheter or not this is really nessecary.
DelPtr should not be used if the pointer it encapsulates, the stored pointer, doesn't have to be deleted at the point DelPtr gets destructed. This means that in many, or perhaps even most, situations, DelPtr has no overhead.
Notice that if an object of type DelPtr is const, this does not mean that the object the stored pointer points to is const, but rather that the stored pointer itself is const.