Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

DelPtr Class Template Reference

An utility class to handle exceptions The porpuse of DelPtr is to make the compiler, rather than you, do as much of the extra work that sometimes comes when mixing dynamic memory allocation with exceptions. More...

#include <DelPtr.h>

List of all members.

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.


Detailed Description

template<class T> template class DelPtr

An utility class to handle exceptions The porpuse of DelPtr is to make the compiler, rather than you, do as much of the extra work that sometimes comes when mixing dynamic memory allocation with exceptions.

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.


The documentation for this class was generated from the following file:
Generated at Mon Nov 27 01:46:44 2000 for LibPenguinPlay by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000