#include <cxxtools/smartptr.h>
Public Member Functions | |
| SmartPtr (objectType *ptr) | |
| SmartPtr (const SmartPtr &ptr) | |
| SmartPtr & | operator= (const SmartPtr &ptr) |
| objectType * | operator-> () const |
| The object can be dereferenced like the held object. | |
| objectType & | operator * () const |
| The object can be dereferenced like the held object. | |
| bool | operator== (const objectType *p) const |
| bool | operator!= (const objectType *p) const |
| bool | operator< (const objectType *p) const |
| bool | operator! () const |
| operator bool () const | |
| objectType * | getPointer () |
| const objectType * | getPointer () const |
| operator objectType * () | |
| operator const objectType * () const | |
This class works like a pointer, but the destructor deletes the held object if this is the last reference. The policy specifies, how the class counts the references. There are 4 policies:
ExternalRefCounted: allocates a reference-count
ExternalAtomicRefCounted: like ExternalRefCounted, but thread safe
InternalRefCounted: the pointed object needs to have a reference-counter with methods addRef() and release(). The release-method deletes the object, when the reference-count drops to 0.
RefLinked: all pointers to a object are linked
The default policy is InternalRefCounted. Another class cxxtools::RefCounted implements proper methods for the pointer, which makes it straight-forward to use.