yat  0.14.5pre
Public Member Functions | List of all members
theplu::yat::utility::SmartPtr< T > Class Template Reference

#include <yat/utility/SmartPtr.h>

Public Member Functions

 SmartPtr (T *p=NULL, bool owner=true)
 Constructor. More...
 
 SmartPtr (const SmartPtr &other)
 Copy constructor.
 
virtual ~SmartPtr ()
 Destructor. More...
 
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.

This is an internal class kept for backward compabitility. User are adviced to use boost::shared_ptr.

See Also
Deleter

Constructor & Destructor Documentation

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

Constructor.

Parameters
punderlying pointer
ownerif 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 Tue Sep 26 2017 02:33:31 for yat by  doxygen 1.8.5