null_pointer Class Template Reference

SmartPointer basically to give support for "null objects" without loosing RAII. More...

List of all members.

Public Member Functions

const T * get () const
 Returns the contained pointer value.
T * get ()
 Returns the contained pointer value.
 null_pointer (const null_pointer &rhs)
 Copy constructor.
 null_pointer ()
 Constructs an empty null_pointer.
 null_pointer (T *t)
 Constructs a smart pointer with the value of t.
const T & operator * () const
 Returns the contained pointer content by reference.
T & operator * ()
 Returns the contained pointer content by reference.
const T * operator-> () const
 Returns the contained pointer value.
T * operator-> ()
 Returns the contained pointer value.
null_pointeroperator= (T *rhs)
 Assignment operator.
null_pointeroperator= (const null_pointer &rhs)
 Assignment operator.
 ~null_pointer ()
 Destructor, deletes the contained pointer.


Detailed Description

template<class T, template< class > class CopyPolicy = NewClone>
class SmartUtil::null_pointer< T, CopyPolicy >

SmartPointer basically to give support for "null objects" without loosing RAII.

This pointer have ONE thing it does, it makes sure it's possible to have "null objects" meaning objects that have a "null" value. This behaviour could easily have been done by normal pointers, but the problem then is RAII or cleanup of heap memory. Therefor we can use this smart pointer instead. Note also that the copy constructor and assignment operator does a DEEP copy of the contain pointer! This means that the copy CTOR and the assignment operator might have a big runtime overhead! If you need a shared_ptr use the boost namespace!


Constructor & Destructor Documentation

null_pointer ( T *  t  )  [explicit]

Constructs a smart pointer with the value of t.

Note that the smart pointer will take "ownership" over the t parameter meaning that it will delete t when the null_pointer object goes out of scope!

null_pointer ( const null_pointer< T, CopyPolicy > &  rhs  ) 

Copy constructor.

Makes a DEEP copy of the contained object!!


Member Function Documentation

const T* get (  )  const

Returns the contained pointer value.

Use this one to check if pointer actually have a value or not

T* get (  ) 

Returns the contained pointer value.

Use this one to check if pointer actually have a value or not

const T& operator * (  )  const

Returns the contained pointer content by reference.

Basically a dereference operator

T& operator * (  ) 

Returns the contained pointer content by reference.

Basically a dereference operator

null_pointer& operator= ( T *  rhs  ) 

Assignment operator.

Note that this assignment operator takes OWNERSHIP over the contained pointer. Meaning it will free or delete the contained pointer when the object goes out of scope!

null_pointer& operator= ( const null_pointer< T, CopyPolicy > &  rhs  ) 

Assignment operator.

Makes a DEEP copy of the contained pointer if there is data in it after freeing up it's old contained value (if there was an old value)

Back to SmartWin website
SourceForge.net Logo