Image Component Library (ICL)
|
Base class for reference counting smart-pointers. More...
#include <SmartPtrBase.h>
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 |
Base class for reference counting smart-pointers.
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:
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.
icl::utils::SmartPtrBase< T, delOp >::SmartPtrBase | ( | ) | [inline] |
e and c will become NULL
icl::utils::SmartPtrBase< T, delOp >::SmartPtrBase | ( | DerivedT * | ptData, |
bool | bOwn = true |
||
) | [inline] |
ptData is given, reference counter is set to 1
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
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
icl::utils::SmartPtrBase< T, delOp >::~SmartPtrBase | ( | ) | [inline] |
decreases the reference counter (cleanup on demand)
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
void icl::utils::SmartPtrBase< T, delOp >::dec | ( | ) | [inline, protected] |
save reference counter decrement (cleanup on demand)
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;
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;
void icl::utils::SmartPtrBase< T, delOp >::inc | ( | ) | [inline, protected] |
save reference counter increment
icl::utils::SmartPtrBase< T, delOp >::operator bool | ( | ) | const [inline] |
this may be used to check if * or -> operator may be used
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;
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;
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;
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;
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.
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.
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
SmartPtrBase<T,delOp>& icl::utils::SmartPtrBase< T, delOp >::operator= | ( | T * | p | ) | [inline] |
allows for direct assignment of pointers to a SmartPtr object
void icl::utils::SmartPtrBase< T, delOp >::set | ( | T * | e, |
int * | c, | ||
bool | d | ||
) | [inline, protected] |
sets e and c
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>();
int icl::utils::SmartPtrBase< T, delOp >::use_count | ( | ) | const [inline] |
current reference count
friend class SmartPtrBase [friend] |
for template-based assignment
int* icl::utils::SmartPtrBase< T, delOp >::c [protected] |
reference counters
bool icl::utils::SmartPtrBase< T, delOp >::d [protected] |
deletion flag (indicates if the hold data must be deleted)
T* icl::utils::SmartPtrBase< T, delOp >::e [protected] |
corresponding data element