cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy > Class Template Reference

Policy-based smart-pointer-class. More...

#include <cxxtools/smartptr.h>

Public Member Functions

 SmartPtr ()
 SmartPtr (ObjectType *ptr)
 SmartPtr (const SmartPtr &ptr)
template<typename T >
 SmartPtr (const SmartPtr< T > &ptr)
 ~SmartPtr ()
SmartPtroperator= (const SmartPtr &ptr)
template<typename T >
SmartPtroperator= (const SmartPtr< T > &ptr)
SmartPtroperator= (ObjectType *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
 operator bool () const
ObjectType * getPointer () 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.

Constructor & Destructor Documentation

template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::SmartPtr ( )
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::SmartPtr ( ObjectType *  ptr)
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::SmartPtr ( const SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy > &  ptr)
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
template<typename T >
cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::SmartPtr ( const SmartPtr< T > &  ptr)
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::~SmartPtr ( )
inline

Member Function Documentation

template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
ObjectType* cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::getPointer ( ) const
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::operator bool ( ) const
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
bool cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::operator! ( ) const
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
ObjectType& cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::operator* ( ) const
inline

The object can be dereferenced like the held object.

template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
ObjectType* cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::operator-> ( ) const
inline

The object can be dereferenced like the held object.

template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
SmartPtr& cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::operator= ( const SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy > &  ptr)
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
template<typename T >
SmartPtr& cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::operator= ( const SmartPtr< T > &  ptr)
inline
template<typename ObjectType, template< class > class OwnershipPolicy = InternalRefCounted, template< class > class DestroyPolicy = DefaultDestroyPolicy>
SmartPtr& cxxtools::SmartPtr< ObjectType, OwnershipPolicy, DestroyPolicy >::operator= ( ObjectType *  ptr)
inline

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