Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

SmartPtr Class Template Reference

#include <cxxtools/smartptr.h>

List of all members.

Public Member Functions

 SmartPtr (objectType *ptr)
 SmartPtr (const SmartPtr &ptr)
SmartPtroperator= (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


Detailed Description

template<typename objectType, template< class > class ownershipPolicy = InternalRefCounted, template< class > class destroyPolicy = DefaultDestroyPolicy>
class cxxtools::SmartPtr< objectType, ownershipPolicy, destroyPolicy >

Policy-based smart-pointer-class.

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.

Copyright © 2008 The Tntnet Development Team
Tntnet 1.6