Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
icl::utils::SmartPtrBase< T, delOp > Class Template Reference

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

#include <SmartPtrBase.h>

List of all members.

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

T * e
int * c
bool d

Friends

class SmartPtrBase
 for template-based assignment

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

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

e and c will become NULL

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

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

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

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

decreases the reference counter (cleanup on demand)


Member Function Documentation

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

utility assignment method used in the SmartPtrBase assignment operators

template<class T, class delOp = ArrayDelOp>
void icl::utils::SmartPtrBase< T, delOp >::dec ( ) [inline, protected]

save reference counter decrement (cleanup on demand)

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;

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;

template<class T, class delOp = ArrayDelOp>
void icl::utils::SmartPtrBase< T, delOp >::inc ( ) [inline, protected]

save reference counter increment

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

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;

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;

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;

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;

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.

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.

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

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

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

sets e and c

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>();
template<class T, class delOp = ArrayDelOp>
int icl::utils::SmartPtrBase< T, delOp >::use_count ( ) const [inline]

current reference count


Friends And Related Function Documentation

template<class T, class delOp = ArrayDelOp>
friend class SmartPtrBase [friend]

for template-based assignment


Member Data Documentation

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

reference counters

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

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

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines