PUMA Library Reference Manual
Loading...
Searching...
No Matches
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();
Template based smart pointer implementation.
Definition SmartPtr.h:40

Classes

class  RefCnt
 Reference counter for objects used with SmartPtr. More...
 

Public Member Functions

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

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.