yat  0.8.3pre
Public Member Functions
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 
)
inlineexplicit

Constructor.

  \param p underlying pointer
  \param 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 ( )
inlinevirtual

Destructor.

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


Member Function Documentation

template<typename T>
T& theplu::yat::utility::SmartPtr< T >::operator* ( void  ) const
inline
Returns:
reference to underlying object
template<typename T>
T* theplu::yat::utility::SmartPtr< T >::operator-> ( void  ) const
inline
Returns:
underlying pointer
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.


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

Generated on Thu Dec 20 2012 03:13:00 for yat by  doxygen 1.8.0-20120409