yat  0.21pre
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. Users are adviced to use std::shared_ptr.

See also
Deleter

Constructor & Destructor Documentation

◆ SmartPtr()

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.

◆ ~SmartPtr()

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

◆ operator*()

template<typename T>
T& theplu::yat::utility::SmartPtr< T >::operator* ( void  ) const
inline
Returns
reference to underlying object

◆ operator->()

template<typename T>
T* theplu::yat::utility::SmartPtr< T >::operator-> ( void  ) const
inline
Returns
underlying pointer

◆ operator=()

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 Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14