Image Component Library (ICL)
Public Types | Public Member Functions | List of all members
icl::utils::SmartPtr< T > Struct Template Reference

Specialization of the SmartPtrBase class for Pointers. More...

#include <SmartPtr.h>

Inheritance diagram for icl::utils::SmartPtr< T >:
icl::utils::SmartPtrBase< T, PointerDelOp >

Public Types

typedef SmartPtrBase< T, PointerDelOpsuper
 

Public Member Functions

 SmartPtr ()
 creates a null pointer More...
 
template<class DerivedT >
 SmartPtr (DerivedT *ptData, bool bOwn=true)
 gets pointer, ownership is passed optionally More...
 
 SmartPtr (T *ptData, bool bOwn=true)
 gets pointer, ownership is passed optionally More...
 
template<class DerivedT >
 SmartPtr (const SmartPtrBase< DerivedT, PointerDelOp > &r)
 reference counting copy constructor More...
 
 SmartPtr (const SmartPtrBase< T, PointerDelOp > &r)
 reference counting copy constructor More...
 
- Public Member Functions inherited from icl::utils::SmartPtrBase< T, PointerDelOp >
 SmartPtrBase ()
 e and c will become NULL More...
 
 SmartPtrBase (DerivedT *ptData, bool bOwn=true)
 ptData is given, reference counter is set to 1 More...
 
 SmartPtrBase (const SmartPtrBase< DerivedT, PointerDelOp > &r)
 Create a copy of given smart pointer with more general type. More...
 
 SmartPtrBase (const SmartPtrBase< T, PointerDelOp > &r)
 Create a copy of given smart pointer. More...
 
SmartPtrBase< T, PointerDelOp > & operator= (const SmartPtrBase< DerivedT, PointerDelOp > &r)
 sets the pointer to hold another reference More...
 
SmartPtrBase< T, PointerDelOp > & operator= (const SmartPtrBase< T, PointerDelOp > &r)
 explicit implmentation of the same type assignment operator More...
 
SmartPtrBase< T, PointerDelOp > & operator= (DerivedT *p)
 allows for direct assignment of pointers to a SmartPtr object More...
 
SmartPtrBase< T, PointerDelOp > & 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...
 

Additional Inherited Members

- Protected Member Functions inherited from icl::utils::SmartPtrBase< T, PointerDelOp >
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...
 
SmartPtrBase< T, PointerDelOp > & assign (const SmartPtrBase< DerivedT, PointerDelOp > &r)
 utility assignment method used in the SmartPtrBase assignment operators More...
 
- Protected Attributes inherited from icl::utils::SmartPtrBase< T, PointerDelOp >
T * e
 
int * c
 
bool d
 

Detailed Description

template<class T>
struct icl::utils::SmartPtr< T >

Specialization of the SmartPtrBase class for Pointers.

If the internal reference counter becomes 0, the contained data pointer is release using delete

Example (Image Convolution)

class MyClass{...};
typedef SmartPtr<MyClass> MyClassPtr;
//create an array of empty auto pointers
MyClassPtr ps[100];
// fill the first element of the array with one reference
// of type MyClass*
ps[0] = new MyClass;
// fill the other elements of the array with the
// SAME reference
std::fill(ps+1,ps+100,ps[0])
// reference counter is 100 now
// delete all except the last one
for(int i=0;i<99;i++){
   array[i].setNull();
}
// now the reference counter of array[99] is 1, if it
// is deleted, the hold element is deleted as well
array[99].setNull();

Member Typedef Documentation

◆ super

template<class T>
typedef SmartPtrBase<T,PointerDelOp> icl::utils::SmartPtr< T >::super

Constructor & Destructor Documentation

◆ SmartPtr() [1/5]

template<class T>
icl::utils::SmartPtr< T >::SmartPtr ( )
inline

creates a null pointer

◆ SmartPtr() [2/5]

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

gets pointer, ownership is passed optionally

◆ SmartPtr() [3/5]

template<class T>
icl::utils::SmartPtr< T >::SmartPtr ( T *  ptData,
bool  bOwn = true 
)
inline

gets pointer, ownership is passed optionally

◆ SmartPtr() [4/5]

template<class T>
template<class DerivedT >
icl::utils::SmartPtr< T >::SmartPtr ( const SmartPtrBase< DerivedT, PointerDelOp > &  r)
inline

reference counting copy constructor

◆ SmartPtr() [5/5]

template<class T>
icl::utils::SmartPtr< T >::SmartPtr ( const SmartPtrBase< T, PointerDelOp > &  r)
inline

reference counting copy constructor


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