GClasses

GClasses::Holder< T > Class Template Reference

This class is very similar to the standard C++ class auto_ptr, except it throws an exception if you try to make a copy of it. This way, it will fail early if you use it in a manner that could result in non-deterministic behavior. (For example, if you create a vector of auto_ptrs, wierd things happen if an oom exception is thrown while resizing the buffer--part of the data will be lost when it reverts back to the original buffer. But if you make a vector of these, it will fail quickly, thus alerting you to the issue.) More...

#include <GHolders.h>

List of all members.

Public Member Functions

 Holder (T *p=NULL)
 ~Holder ()
 Deletes the object that is being held.
void reset (T *p=NULL)
 Deletes the object that is being held, and sets the holder to hold p. Will not delete the held pointer if the new pointer is the same.
T * get ()
 Returns a pointer to the object being held.
T * release ()
 Releases the object. (After calling this method, it is your job to delete the object.)
T & operator* () const
T * operator-> () const

Detailed Description

template<class T>
class GClasses::Holder< T >

This class is very similar to the standard C++ class auto_ptr, except it throws an exception if you try to make a copy of it. This way, it will fail early if you use it in a manner that could result in non-deterministic behavior. (For example, if you create a vector of auto_ptrs, wierd things happen if an oom exception is thrown while resizing the buffer--part of the data will be lost when it reverts back to the original buffer. But if you make a vector of these, it will fail quickly, thus alerting you to the issue.)


Constructor & Destructor Documentation

template<class T >
GClasses::Holder< T >::Holder ( T *  p = NULL) [inline]
template<class T >
GClasses::Holder< T >::~Holder ( ) [inline]

Deletes the object that is being held.


Member Function Documentation

template<class T >
T* GClasses::Holder< T >::get ( ) [inline]

Returns a pointer to the object being held.

template<class T >
T& GClasses::Holder< T >::operator* ( ) const [inline]
template<class T >
T* GClasses::Holder< T >::operator-> ( ) const [inline]
template<class T >
T* GClasses::Holder< T >::release ( ) [inline]

Releases the object. (After calling this method, it is your job to delete the object.)

template<class T >
void GClasses::Holder< T >::reset ( T *  p = NULL) [inline]

Deletes the object that is being held, and sets the holder to hold p. Will not delete the held pointer if the new pointer is the same.