PUMA Library Reference Manual
Puma::SmartPtr< T > Class Template Reference

#include <Puma/SmartPtr.h>

+ Inheritance diagram for Puma::SmartPtr< T >:

Description

template<class T>
class Puma::SmartPtr< T >

Template based smart pointer implementation. Classes must be derived from SmartPtr::RefCnt to be compatible with this implementation. Example:

class Object : public SmartPtr<Object>::RefCnt {
//...
};
SmartPtr<Object> object = new Object();

Classes

class  RefCnt
 

Public Member Functions

 SmartPtr ()
 Construct an empty smart pointer. More...
 
 SmartPtr (const RefCnt *pointer)
 Construct a new smart pointer. More...
 
 SmartPtr (const SmartPtr &copy)
 Copy a smart pointer. More...
 
 ~SmartPtr ()
 Destroy the smart pointer. More...
 
void clear ()
 Clear this smart pointer. More...
 
bool valid () const
 Check whether the smart pointer is valid. More...
 
bool operator== (const SmartPtr &other) const
 Compare this smart pointer with another smart pointer. More...
 
SmartPtroperator= (const SmartPtr &copy)
 Assign a new object to this smart pointer. More...
 
SmartPtroperator= (const RefCnt *copy)
 Assign a new object to this smart pointer. More...
 
 operator bool () const
 Conversion operator to check whether the smart pointer is valid. More...
 
 operator T* () const
 Conversion operator for the managed object pointer type. More...
 
 operator const T * () const
 Conversion operator for the managed object pointer type. More...
 
T * operator-> ()
 Dereference operator for the managed object pointer type. More...
 
const T * operator-> () const
 Dereference operator for the managed object pointer type. More...
 
T * operator* ()
 Indirection operator for the managed object pointer type. More...
 
const T * operator* () const
 Indirection operator for the managed object pointer type. More...
 

Constructor & Destructor Documentation

◆ SmartPtr() [1/3]

template<class T>
Puma::SmartPtr< T >::SmartPtr ( )
inline

Construct an empty smart pointer.

◆ SmartPtr() [2/3]

template<class T>
Puma::SmartPtr< T >::SmartPtr ( const RefCnt pointer)
inline

Construct a new smart pointer.

Parameters
pointerA pointer to the object to manage.

◆ SmartPtr() [3/3]

template<class T>
Puma::SmartPtr< T >::SmartPtr ( const SmartPtr< T > &  copy)
inline

Copy a smart pointer.

Increases the reference count of the managed object.

Parameters
copyThe smart pointer to copy.

◆ ~SmartPtr()

template<class T>
Puma::SmartPtr< T >::~SmartPtr ( )
inline

Destroy the smart pointer.

If this was the last smart pointer referencing the managed object, the object is destroyed too.

Member Function Documentation

◆ clear()

template<class T >
void Puma::SmartPtr< T >::clear ( )
inline

Clear this smart pointer.

If this was the last smart pointer referencing the managed object, the object is destroyed.

◆ operator bool()

template<class T>
Puma::SmartPtr< T >::operator bool ( ) const
inline

Conversion operator to check whether the smart pointer is valid.

Returns
True if valid.

◆ operator const T *()

template<class T>
Puma::SmartPtr< T >::operator const T * ( ) const
inline

Conversion operator for the managed object pointer type.

Returns
A constant pointer to the managed object.

◆ operator T*()

template<class T>
Puma::SmartPtr< T >::operator T* ( ) const
inline

Conversion operator for the managed object pointer type.

Returns
A pointer to the managed object.

◆ operator*() [1/2]

template<class T>
T* Puma::SmartPtr< T >::operator* ( )
inline

Indirection operator for the managed object pointer type.

Returns
A pointer to the managed object.

◆ operator*() [2/2]

template<class T>
const T* Puma::SmartPtr< T >::operator* ( ) const
inline

Indirection operator for the managed object pointer type.

Returns
A constant pointer to the managed object.

◆ operator->() [1/2]

template<class T>
T* Puma::SmartPtr< T >::operator-> ( )
inline

Dereference operator for the managed object pointer type.

Returns
A pointer to the managed object.

◆ operator->() [2/2]

template<class T>
const T* Puma::SmartPtr< T >::operator-> ( ) const
inline

Dereference operator for the managed object pointer type.

Returns
A constant pointer to the managed object.

◆ operator=() [1/2]

template<class T >
SmartPtr< T > & Puma::SmartPtr< T >::operator= ( const RefCnt copy)
inline

Assign a new object to this smart pointer.

If this smart pointer already points to an object, then this object might be destroyed if not referenced by another smart pointer.

Parameters
copyThe smart pointer to copy.
Returns
A reference to this smart pointer.

◆ operator=() [2/2]

template<class T>
SmartPtr& Puma::SmartPtr< T >::operator= ( const SmartPtr< T > &  copy)
inline

Assign a new object to this smart pointer.

If this smart pointer already points to an object, then this object might be destroyed if not referenced by another smart pointer.

Parameters
copyThe smart pointer to copy.
Returns
A reference to this smart pointer.

◆ operator==()

template<class T>
bool Puma::SmartPtr< T >::operator== ( const SmartPtr< T > &  other) const
inline

Compare this smart pointer with another smart pointer.

Parameters
otherThe smart pointer to compare with.
Returns
True if both smart pointers point to the same object.

◆ valid()

template<class T>
bool Puma::SmartPtr< T >::valid ( ) const
inline

Check whether the smart pointer is valid.

A smart pointer is valid if the managed pointer isn't NULL.

Returns
True if valid.
Puma::SmartPtr::SmartPtr
SmartPtr()
Construct an empty smart pointer.
Definition: SmartPtr.h:59