theplu::yat::utility::SmartPtr< T > Class Template Reference

#include <yat/utility/SmartPtr.h>

List of all members.

Public Member Functions

 SmartPtr (T *p=NULL, bool owner=true)
 Constructor.
 SmartPtr (const SmartPtr &other)
 Copy constructor.
virtual ~SmartPtr ()
 Destructor.
SmartPtroperator= (const SmartPtr &rhs)
T * operator-> (void) const
T & operator* (void) const


Detailed Description

template<typename T>
class theplu::yat::utility::SmartPtr< T >

SmartPtr is a wrapper around a pointer. Default SmartPtr is set to be owner of pointer, which implies pointer will be deleted in destructor. Pointer can be shared between many SmartPtr, in which case a counter is kept updated in copying and assignment telling how many owners there are. When the counter reaches zero, the pointer is deleted.

Constructor & Destructor Documentation

template<typename T>
theplu::yat::utility::SmartPtr< T >::SmartPtr ( T *  p = NULL,
bool  owner = true 
) [inline, explicit]

Constructor.

Parameters:
p underlying pointer
owner if true SmartPtr will be owner of pointer and if there is no more owner delete it in destructor.
Never use this constructor to create two SmartPtr to the same pointer such as
       MyClass* my_pointer = new MyClass;
       SmartPtr<MyClass> sp(my_pointer);
       SmartPtr<MyClass> sp2(my_pointer); // this is evil
since this will cause multiple deletion. Instead use copy constructor
       MyClass* my_pointer = new MyClass;
       SmartPtr<MyClass> sp(my_pointer);
       SmartPtr<MyClass> sp2(sp);
so the internal reference counter is updated.

template<typename T>
virtual theplu::yat::utility::SmartPtr< T >::~SmartPtr (  )  [inline, virtual]

Destructor.

If SmartPtr is owner and the only owner, underlying pointer is deleted.


Member Function Documentation

template<typename T>
SmartPtr& theplu::yat::utility::SmartPtr< T >::operator= ( const SmartPtr< T > &  rhs  )  [inline]

If SmartPtr is owner and the only owner, underlying pointer is deleted.

If rhs is owner, lhs become also owner.

template<typename T>
T* theplu::yat::utility::SmartPtr< T >::operator-> ( void   )  const [inline]

Returns:
underlying pointer

template<typename T>
T& theplu::yat::utility::SmartPtr< T >::operator* ( void   )  const [inline]

Returns:
reference to underlying object


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

Generated on Tue Jan 18 02:21:18 2011 for yat by  doxygen 1.5.5