Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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,
PointerDelOp
super
 

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...
 
 ~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

        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

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

Constructor & Destructor Documentation

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

creates a null pointer

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

gets pointer, ownership is passed optionally

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

gets pointer, ownership is passed optionally

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

reference counting copy constructor

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: