MADNESS  version 0.9
Public Types | Public Member Functions | List of all members
madness::ScopedPtr< ptrT > Class Template Reference

Scoped pointer. More...

#include <scopedptr.h>

Public Types

typedef ptrT element_type
 the pointer type More...
 

Public Member Functions

 ScopedPtr (ptrT *p=NULL)
 Construct a scoped pointer. More...
 
 ~ScopedPtr ()
 Destructor. More...
 
void reset (ptrT *p=NULL)
 Reset the current pointer. More...
 
ptrT & operator* () const
 Dereference operator. More...
 
ptrT * operator-> () const
 Pointer member accessor. More...
 
ptrT * get () const
 Pointer accessor. More...
 
 operator bool () const
 bool conversion operator More...
 
bool operator! () const
 Not operator. More...
 
void swap (ScopedPtr< ptrT > &other)
 Swap the pointers. More...
 

Detailed Description

template<typename ptrT>
class madness::ScopedPtr< ptrT >

Scoped pointer.

Holds a pointer until it goes out of scope, then automatically deletes it. A scoped pointer should be used to wrap pointers where the lifetime of the pointer should be limited to a specific scope. The pointer cannot be copied. The pointer will be deleted with the delete operator.

Template Parameters
ptrTThe pointer type
Note
A pointer to type ptrT must be a complete type
This class is based on Boost scoped_ptr.

Member Typedef Documentation

template<typename ptrT>
typedef ptrT madness::ScopedPtr< ptrT >::element_type

the pointer type

Constructor & Destructor Documentation

template<typename ptrT>
madness::ScopedPtr< ptrT >::ScopedPtr ( ptrT *  p = NULL)
inlineexplicit

Construct a scoped pointer.

Parameters
pThe pointer to hold [default = NULL]
Exceptions
nothing
template<typename ptrT>
madness::ScopedPtr< ptrT >::~ScopedPtr ( )
inline

Destructor.

calls delete operator

Member Function Documentation

template<typename ptrT>
ptrT* madness::ScopedPtr< ptrT >::get ( ) const
inline

Pointer accessor.

Returns
The pointer
Exceptions
nothing

Referenced by madness::get_pointer().

template<typename ptrT>
madness::ScopedPtr< ptrT >::operator bool ( ) const
inline

bool conversion operator

Returns
pointer != NULL
Exceptions
nothing
template<typename ptrT>
bool madness::ScopedPtr< ptrT >::operator! ( ) const
inline

Not operator.

Returns
pointer == NULL
Exceptions
nothing
template<typename ptrT>
ptrT& madness::ScopedPtr< ptrT >::operator* ( ) const
inline

Dereference operator.

Returns
A reference to the pointer's data
Exceptions
madness::MadnessExceptionIf the pointer is NULL
template<typename ptrT>
ptrT* madness::ScopedPtr< ptrT >::operator-> ( ) const
inline

Pointer member accessor.

Returns
The pointer
Exceptions
madness::MadnessExceptionIf the pointer is NULL
template<typename ptrT>
void madness::ScopedPtr< ptrT >::reset ( ptrT *  p = NULL)
inline

Reset the current pointer.

This will destroy the current pointer. If an new pointer is provided this pointer will be set to that value.

Parameters
pThe pointer that will replace this pointer after deletion
Exceptions
madness::MadnessExceptionIf p is the same as this pointer, except when this pointer is NULL.

References madness::ScopedPtr< ptrT >::swap().

template<typename ptrT>
void madness::ScopedPtr< ptrT >::swap ( ScopedPtr< ptrT > &  other)
inline

Swap the pointers.

Parameters
otherThe pointer to swap with this pointer
Exceptions
nothing

Referenced by madness::ScopedPtr< ptrT >::reset(), and madness::swap().


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