Image Component Library (ICL)
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
icl::utils::SmartPtrBase< T, delOp > Class Template Reference

Base class for reference counting smart-pointers. More...

#include <SmartPtrBase.h>

Public Member Functions

 SmartPtrBase ()
 e and c will become NULL More...
 
template<class DerivedT >
 SmartPtrBase (DerivedT *ptData, bool bOwn=true)
 ptData is given, reference counter is set to 1 More...
 
template<class DerivedT >
 SmartPtrBase (const SmartPtrBase< DerivedT, delOp > &r)
 Create a copy of given smart pointer with more general type. More...
 
 SmartPtrBase (const SmartPtrBase< T, delOp > &r)
 Create a copy of given smart pointer. More...
 
template<class DerivedT >
SmartPtrBase< T, delOp > & operator= (const SmartPtrBase< DerivedT, delOp > &r)
 sets the pointer to hold another reference More...
 
SmartPtrBase< T, delOp > & operator= (const SmartPtrBase< T, delOp > &r)
 explicit implmentation of the same type assignment operator More...
 
template<class DerivedT >
SmartPtrBase< T, delOp > & operator= (DerivedT *p)
 allows for direct assignment of pointers to a SmartPtr object More...
 
SmartPtrBase< T, delOp > & operator= (T *p)
 allows for direct assignment of pointers to a SmartPtr object More...
 
virtual ~SmartPtrBase ()
 decreases the reference counter (cleanup on demand) More...
 
T & operator * ()
 returns a reference of the currently hold element More...
 
const T & operator * () const
 returns a reference of the currently hold element (const) More...
 
T * get ()
 returns the pointer to the data More...
 
const T * get () const
 returns the pointer to the data (const) More...
 
T * operator-> ()
 returns the currently hold element More...
 
const T * operator-> () const
 returns the currently hold element (const) More...
 
 operator bool () const
 this may be used to check if * or -> operator may be used More...
 
int use_count () const
 current reference count More...
 
void setNull ()
 sets the smart pointer to null More...
 

Protected Member Functions

void inc ()
 save reference counter increment More...
 
void dec ()
 save reference counter decrement (cleanup on demand) More...
 
void set (T *e, int *c, bool d)
 sets e and c More...
 
template<class DerivedT >
SmartPtrBase< T, delOp > & assign (const SmartPtrBase< DerivedT, delOp > &r)
 utility assignment method used in the SmartPtrBase assignment operators More...
 

Protected Attributes

T * e
 
int * c
 
bool d
 

Friends

template<class A , class B >
class SmartPtrBase
 for template-based assignment More...
 

Detailed Description

template<class T, class delOp = ArrayDelOp>
class icl::utils::SmartPtrBase< T, delOp >

Base class for reference counting smart-pointers.

General Information

The icl::SmartPtrBase class defines an abstract interface for managed pointers that use reference counting for save memory management It is not recommended to use the SmartPtrBase class itself. Most of the time, either The icl::SmartPtr or the icl::SmartArray

Important: The data of a SmartPtrBase is released using the second template class parameter delOp::delete_func. Predefined delOps are:

How a SmartPtrBase works

In contrast with the auto pointers provided by the stdlib an SmartPtrBase has an internal reference counter, which is used to care about the deletion of the managed data segment.

Constructor & Destructor Documentation

◆ SmartPtrBase() [1/4]

template<class T, class delOp = ArrayDelOp>
icl::utils::SmartPtrBase< T, delOp >::SmartPtrBase ( )
inline

e and c will become NULL

◆ SmartPtrBase() [2/4]

template<class T, class delOp = ArrayDelOp>
template<class DerivedT >
icl::utils::SmartPtrBase< T, delOp >::SmartPtrBase ( DerivedT *  ptData,
bool  bOwn = true 
)
inline

ptData is given, reference counter is set to 1

◆ SmartPtrBase() [3/4]

template<class T, class delOp = ArrayDelOp>
template<class DerivedT >
icl::utils::SmartPtrBase< T, delOp >::SmartPtrBase ( const SmartPtrBase< DerivedT, delOp > &  r)
inline

Create a copy of given smart pointer with more general type.

This does of course only work, if DeriveT is T or if it extends T

◆ SmartPtrBase() [4/4]

template<class T, class delOp = ArrayDelOp>
icl::utils::SmartPtrBase< T, delOp >::SmartPtrBase ( const SmartPtrBase< T, delOp > &  r)
inline

Create a copy of given smart pointer.

This does of course only work, if DeriveT is T or if it extends T

◆ ~SmartPtrBase()

template<class T, class delOp = ArrayDelOp>
virtual icl::utils::SmartPtrBase< T, delOp >::~SmartPtrBase ( )
inlinevirtual

decreases the reference counter (cleanup on demand)

Member Function Documentation

◆ assign()

template<class T, class delOp = ArrayDelOp>
template<class DerivedT >
SmartPtrBase<T,delOp>& icl::utils::SmartPtrBase< T, delOp >::assign ( const SmartPtrBase< DerivedT, delOp > &  r)
inlineprotected

utility assignment method used in the SmartPtrBase assignment operators

◆ dec()

template<class T, class delOp = ArrayDelOp>
void icl::utils::SmartPtrBase< T, delOp >::dec ( )
inlineprotected

save reference counter decrement (cleanup on demand)

◆ get() [1/2]

template<class T, class delOp = ArrayDelOp>
T* icl::utils::SmartPtrBase< T, delOp >::get ( void  )
inline

returns the pointer to the data

If the element pointer is null, an error will terminate the program with -1;

◆ get() [2/2]

template<class T, class delOp = ArrayDelOp>
const T* icl::utils::SmartPtrBase< T, delOp >::get ( void  ) const
inline

returns the pointer to the data (const)

If the element pointer is null, an error will terminate the program with -1;

◆ inc()

template<class T, class delOp = ArrayDelOp>
void icl::utils::SmartPtrBase< T, delOp >::inc ( )
inlineprotected

save reference counter increment

◆ operator *() [1/2]

template<class T, class delOp = ArrayDelOp>
T& icl::utils::SmartPtrBase< T, delOp >::operator * ( )
inline

returns a reference of the currently hold element

If the element pointer is null, an error will terminate the program with -1;

◆ operator *() [2/2]

template<class T, class delOp = ArrayDelOp>
const T& icl::utils::SmartPtrBase< T, delOp >::operator * ( ) const
inline

returns a reference of the currently hold element (const)

If the element pointer is null, an error will terminate the program with -1;

◆ operator bool()

template<class T, class delOp = ArrayDelOp>
icl::utils::SmartPtrBase< T, delOp >::operator bool ( ) const
inline

this may be used to check if * or -> operator may be used

◆ operator->() [1/2]

template<class T, class delOp = ArrayDelOp>
T* icl::utils::SmartPtrBase< T, delOp >::operator-> ( )
inline

returns the currently hold element

If the element pointer is null, an error will terminate the program with -1;

◆ operator->() [2/2]

template<class T, class delOp = ArrayDelOp>
const T* icl::utils::SmartPtrBase< T, delOp >::operator-> ( ) const
inline

returns the currently hold element (const)

If the element pointer is null, an error will terminate the program with -1;

◆ operator=() [1/4]

template<class T, class delOp = ArrayDelOp>
template<class DerivedT >
SmartPtrBase<T,delOp>& icl::utils::SmartPtrBase< T, delOp >::operator= ( const SmartPtrBase< DerivedT, delOp > &  r)
inline

sets the pointer to hold another reference

If the new reference r.e is identical to the current reference, nothing is done at all. Else, the current reference counter is decreased by 1, if it becomes NULL, the hold reference is deleted. Following, the current reference and reference counter is copied from the given r. At the end, the copied reference counter is increased by 1.

◆ operator=() [2/4]

template<class T, class delOp = ArrayDelOp>
SmartPtrBase<T,delOp>& icl::utils::SmartPtrBase< T, delOp >::operator= ( const SmartPtrBase< T, delOp > &  r)
inline

explicit implmentation of the same type assignment operator

This operator needs to be implemented explicitly because the template based assignment operator does not match the default assignment operator type for some reason.

◆ operator=() [3/4]

template<class T, class delOp = ArrayDelOp>
template<class DerivedT >
SmartPtrBase<T,delOp>& icl::utils::SmartPtrBase< T, delOp >::operator= ( DerivedT *  p)
inline

allows for direct assignment of pointers to a SmartPtr object

Rvalue pointer must be of type T of a type is derived from T

◆ operator=() [4/4]

template<class T, class delOp = ArrayDelOp>
SmartPtrBase<T,delOp>& icl::utils::SmartPtrBase< T, delOp >::operator= ( T *  p)
inline

allows for direct assignment of pointers to a SmartPtr object

◆ set()

template<class T, class delOp = ArrayDelOp>
void icl::utils::SmartPtrBase< T, delOp >::set ( T *  e,
int *  c,
bool  d 
)
inlineprotected

sets e and c

◆ setNull()

template<class T, class delOp = ArrayDelOp>
void icl::utils::SmartPtrBase< T, delOp >::setNull ( )
inline

sets the smart pointer to null

This is equivalent to

SmartPtr<X> p(new X);
p = SmartPtr<X>();

◆ use_count()

template<class T, class delOp = ArrayDelOp>
int icl::utils::SmartPtrBase< T, delOp >::use_count ( ) const
inline

current reference count

Friends And Related Function Documentation

◆ SmartPtrBase

template<class T, class delOp = ArrayDelOp>
template<class A , class B >
friend class SmartPtrBase
friend

for template-based assignment

Member Data Documentation

◆ c

template<class T, class delOp = ArrayDelOp>
int* icl::utils::SmartPtrBase< T, delOp >::c
protected

reference counters

◆ d

template<class T, class delOp = ArrayDelOp>
bool icl::utils::SmartPtrBase< T, delOp >::d
protected

deletion flag (indicates if the hold data must be deleted)

◆ e

template<class T, class delOp = ArrayDelOp>
T* icl::utils::SmartPtrBase< T, delOp >::e
protected

corresponding data element


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