Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::AutoDestructor< T > Class Template Reference

#include <elm/util/AutoDestructor.h>

Public Member Functions

 AutoDestructor (void)
 
 AutoDestructor (T *ptr)
 
 ~AutoDestructor (void)
 
bool isNull (void) const
 
void clean (void)
 
T * detach (void)
 
void set (T *ptr)
 
T * get (void) const
 
AutoDestructoroperator= (T *ptr)
 
AutoDestructoroperator= (AutoDestructor &ad)
 
 operator T * (void) const
 
T * operator-> (void) const
 
 operator bool (void) const
 

Detailed Description

template<class T>
class elm::AutoDestructor< T >

This class is wrapper around allocated pointer to manager its deletion. This type supports all operation on pointer and ensures that the pointed memory will be fried when the the pointer will be deleted. Notice that it takes as much memory as a usual pointer.

It may be useful in a generic data structure where the user has no access to the destructor.

Parameters
TType of pointed data.

Constructor & Destructor Documentation

template<class T >
elm::AutoDestructor< T >::AutoDestructor ( void  )

Build an autodestructor with a null pointer.

template<class T >
elm::AutoDestructor< T >::AutoDestructor ( T *  ptr)

Build an autodestructor with the given pointer.

Parameters
ptrUsed pointer.
template<class T >
elm::AutoDestructor< T >::~AutoDestructor ( void  )

Member Function Documentation

template<class T >
void elm::AutoDestructor< T >::clean ( void  )

Free the pointed memory and set the pointer to null.

Referenced by elm::AutoDestructor< T >::operator=(), elm::AutoDestructor< T >::set(), and elm::AutoDestructor< T >::~AutoDestructor().

template<class T >
T * elm::AutoDestructor< T >::detach ( void  )

Return the pointer and set it in the object to null (it will no more be automatically fried).

Returns
Stored pointer.
template<class T >
T* elm::AutoDestructor< T >::get ( void  ) const
template<class T >
bool elm::AutoDestructor< T >::isNull ( void  ) const

Test if the pointer is null.

Returns
True if the pointer is null, false else.

Referenced by elm::AutoDestructor< T >::operator bool().

template<class T >
elm::AutoDestructor< T >::operator bool ( void  ) const

Same as !isNull().

References elm::AutoDestructor< T >::isNull().

template<class T >
elm::AutoDestructor< T >::operator T * ( void  ) const

Same as get().

template<class T >
T * elm::AutoDestructor< T >::operator-> ( void  ) const

Indirect access to the members of stored pointer.

Returns
Stored pointer.
template<class T >
AutoDestructor & elm::AutoDestructor< T >::operator= ( T *  ptr)

Change the pointer contained in the auto-destructor, the old pointer begin fried. Same as set().

Returns
Pointer to set.

References elm::AutoDestructor< T >::set().

template<class T >
AutoDestructor & elm::AutoDestructor< T >::operator= ( AutoDestructor< T > &  ad)

Change the current pointer with the one of the given auto-destructor. The old pointer is first fried and the ad pointer is set to null.

Parameters
adAuto-destructor to set the pointer form.

References elm::AutoDestructor< T >::clean().

template<class T >
void elm::AutoDestructor< T >::set ( T *  ptr)

The documentation for this class was generated from the following files: