NAME
OTC_VecReaper -
Destroys arrays of objects.
SYNOPSIS
#include <OTC/memory/vcreaper.hh>
template<class T>
class OTC_VecReaper
{
public:
inline OTC_VecReaper();
inline ~OTC_VecReaper();
inline void grab(T* theData);
inline void release();
};
CLASS TYPE
Concrete
DESCRIPTION
The class OTC_VecReaper assists in ensuring that arrays of
objects allocated from the free store are deleted when the stack
is unwound as a result of an exception. This is achieved by using
an instance of this class as a handle to an array of objects
allocated using new. Once an array of objects is grabbed using an
instance of this class, the section of code in which an exception
could be raised is executed. If an exception does occur then the
instance of this class will be destroyed and the array of objects
deleted. If no exception occurs a call can be made to release
the array of objects. When the destructor is finally called the
array of objects would not be deleted.
EXAMPLE
void function()
{
OTC_VecReaper<Object> xxxArray;
Object* theArray = new Object[2];
OTCLIB_ASSERT(theArray != 0);
xxxArray.grab(theArray);
... code which could throw an exception
xxxArray.release();
}
INITIALISATION
inline OTC_VecReaper();
Initialises the handle to 0.
DESTRUCTION
inline ~OTC_VecReaper();
If the handle references an array, ie.,
the handle is not 0, the array is
deleted.
GRAB/RELEASE
inline void grab(T* theData);
Sets the handle to theData.
If the handle was set to point at another
array, it will now point to the new
array and the first array will not be
changed.
inline void release();
Sets the handle to 0. This is equivalent
to calling grab(0).
SEE ALSO
OTC_Reaper, OTC_MallocReaper
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1993 TELSTRA CORPORATION LIMITED