Poco::AutoPtr< C > Class Template Reference

#include <AutoPtr.h>

Inheritance diagram for Poco::AutoPtr< C >:

Inheritance graph
[legend]
Collaboration diagram for Poco::AutoPtr< C >:

Collaboration graph
[legend]

Detailed Description

template<class C>
class Poco::AutoPtr< C >

AutoPtr is a "smart" pointer for classes implementing reference counting based garbage collection. To be usable with the AutoPtr template, a class must implement the following behaviour: A class must maintain a reference count. The constructors of the object initialize the reference count to one. The class must implement a public duplicate() method: void duplicate(); that increments the reference count by one. The class must implement a public release() method: void release() that decrements the reference count by one, and, if the reference count reaches zero, deletes the object.

AutoPtr works in the following way: If an AutoPtr is assigned an ordinary pointer to an object (via the constructor or the assignment operator), it takes ownership of the object and the object's reference count remains unchanged. If the AutoPtr is assigned another AutoPtr, the object's reference count is incremented by one by calling duplicate() on its object. The destructor of AutoPtr calls release() on its object. AutoPtr supports dereferencing with both the -> and the * operator. An attempt to dereference a null AutoPtr results in a NullPointerException being thrown. AutoPtr also implements all relational operators. Note that AutoPtr allows casting of its encapsulated data types.

Definition at line 88 of file AutoPtr.h.


Public Member Functions

 AutoPtr ()
 AutoPtr (C *ptr)
 AutoPtr (C *ptr, bool shared)
 AutoPtr (const AutoPtr &ptr)
template<class Other>
 AutoPtr (const AutoPtr< Other > &ptr)
 ~AutoPtr ()
AutoPtrassign (C *ptr)
AutoPtrassign (C *ptr, bool shared)
AutoPtrassign (const AutoPtr &ptr)
template<class Other>
AutoPtrassign (const AutoPtr< Other > &ptr)
AutoPtroperator= (C *ptr)
AutoPtroperator= (const AutoPtr &ptr)
template<class Other>
AutoPtroperator= (const AutoPtr< Other > &ptr)
void swap (AutoPtr &ptr)
template<class Other>
AutoPtr< Other > cast () const
 Casts the AutoPtr via a dynamic cast to the given type. Returns an AutoPtr containing NULL if the cast fails. Example: (assume class Sub: public Super) AutoPtr<Super> super(new Sub()); AutoPtr<Sub> sub = super.cast<Sub>(); poco_assert (sub.get());.
template<class Other>
AutoPtr< Other > unsafeCast () const
 Casts the AutoPtr via a static cast to the given type. Example: (assume class Sub: public Super) AutoPtr<Super> super(new Sub()); AutoPtr<Sub> sub = super.unsafeCast<Sub>(); poco_assert (sub.get());.
C * operator-> ()
const C * operator-> () const
C & operator* ()
const C & operator* () const
C * get ()
const C * get () const
 operator C * ()
 operator const C * () const
bool operator! () const
bool isNull () const
C * duplicate ()
bool operator== (const AutoPtr &ptr) const
bool operator== (const C *ptr) const
bool operator== (C *ptr) const
bool operator!= (const AutoPtr &ptr) const
bool operator!= (const C *ptr) const
bool operator!= (C *ptr) const
bool operator< (const AutoPtr &ptr) const
bool operator< (const C *ptr) const
bool operator< (C *ptr) const
bool operator<= (const AutoPtr &ptr) const
bool operator<= (const C *ptr) const
bool operator<= (C *ptr) const
bool operator> (const AutoPtr &ptr) const
bool operator> (const C *ptr) const
bool operator> (C *ptr) const
bool operator>= (const AutoPtr &ptr) const
bool operator>= (const C *ptr) const
bool operator>= (C *ptr) const

Private Attributes

C * _ptr

Constructor & Destructor Documentation

template<class C>
Poco::AutoPtr< C >::AutoPtr (  )  [inline]

Definition at line 122 of file AutoPtr.h.

template<class C>
Poco::AutoPtr< C >::AutoPtr ( C *  ptr  )  [inline]

Definition at line 126 of file AutoPtr.h.

template<class C>
Poco::AutoPtr< C >::AutoPtr ( C *  ptr,
bool  shared 
) [inline]

Definition at line 130 of file AutoPtr.h.

template<class C>
Poco::AutoPtr< C >::AutoPtr ( const AutoPtr< C > &  ptr  )  [inline]

Definition at line 135 of file AutoPtr.h.

template<class C>
template<class Other>
Poco::AutoPtr< C >::AutoPtr ( const AutoPtr< Other > &  ptr  )  [inline]

Definition at line 141 of file AutoPtr.h.

template<class C>
Poco::AutoPtr< C >::~AutoPtr (  )  [inline]

Definition at line 146 of file AutoPtr.h.


Member Function Documentation

template<class C>
AutoPtr& Poco::AutoPtr< C >::assign ( C *  ptr  )  [inline]

Definition at line 151 of file AutoPtr.h.

Referenced by Poco::AutoPtr< Poco::ThreadImpl::ThreadData >::operator=().

template<class C>
AutoPtr& Poco::AutoPtr< C >::assign ( C *  ptr,
bool  shared 
) [inline]

Definition at line 161 of file AutoPtr.h.

template<class C>
AutoPtr& Poco::AutoPtr< C >::assign ( const AutoPtr< C > &  ptr  )  [inline]

Definition at line 172 of file AutoPtr.h.

template<class C>
template<class Other>
AutoPtr& Poco::AutoPtr< C >::assign ( const AutoPtr< Other > &  ptr  )  [inline]

Definition at line 184 of file AutoPtr.h.

template<class C>
AutoPtr& Poco::AutoPtr< C >::operator= ( C *  ptr  )  [inline]

Definition at line 195 of file AutoPtr.h.

template<class C>
AutoPtr& Poco::AutoPtr< C >::operator= ( const AutoPtr< C > &  ptr  )  [inline]

Definition at line 200 of file AutoPtr.h.

template<class C>
template<class Other>
AutoPtr& Poco::AutoPtr< C >::operator= ( const AutoPtr< Other > &  ptr  )  [inline]

Definition at line 206 of file AutoPtr.h.

template<class C>
void Poco::AutoPtr< C >::swap ( AutoPtr< C > &  ptr  )  [inline]

Definition at line 211 of file AutoPtr.h.

Referenced by Poco::swap().

template<class C>
template<class Other>
AutoPtr<Other> Poco::AutoPtr< C >::cast (  )  const [inline]

Casts the AutoPtr via a dynamic cast to the given type. Returns an AutoPtr containing NULL if the cast fails. Example: (assume class Sub: public Super) AutoPtr<Super> super(new Sub()); AutoPtr<Sub> sub = super.cast<Sub>(); poco_assert (sub.get());.

Definition at line 217 of file AutoPtr.h.

template<class C>
template<class Other>
AutoPtr<Other> Poco::AutoPtr< C >::unsafeCast (  )  const [inline]

Casts the AutoPtr via a static cast to the given type. Example: (assume class Sub: public Super) AutoPtr<Super> super(new Sub()); AutoPtr<Sub> sub = super.unsafeCast<Sub>(); poco_assert (sub.get());.

Definition at line 230 of file AutoPtr.h.

template<class C>
C* Poco::AutoPtr< C >::operator-> (  )  [inline]

Definition at line 241 of file AutoPtr.h.

template<class C>
const C* Poco::AutoPtr< C >::operator-> (  )  const [inline]

Definition at line 249 of file AutoPtr.h.

template<class C>
C& Poco::AutoPtr< C >::operator* (  )  [inline]

Definition at line 257 of file AutoPtr.h.

template<class C>
const C& Poco::AutoPtr< C >::operator* (  )  const [inline]

Definition at line 265 of file AutoPtr.h.

template<class C>
C* Poco::AutoPtr< C >::get (  )  [inline]

Definition at line 273 of file AutoPtr.h.

Referenced by Poco::AutoPtr< Poco::ThreadImpl::ThreadData >::assign().

template<class C>
const C* Poco::AutoPtr< C >::get (  )  const [inline]

Definition at line 278 of file AutoPtr.h.

template<class C>
Poco::AutoPtr< C >::operator C * (  )  [inline]

Definition at line 283 of file AutoPtr.h.

template<class C>
Poco::AutoPtr< C >::operator const C * (  )  const [inline]

Definition at line 288 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator! (  )  const [inline]

Definition at line 293 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::isNull (  )  const [inline]

Definition at line 298 of file AutoPtr.h.

template<class C>
C* Poco::AutoPtr< C >::duplicate (  )  [inline]

Definition at line 303 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator== ( const AutoPtr< C > &  ptr  )  const [inline]

Definition at line 309 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator== ( const C *  ptr  )  const [inline]

Definition at line 314 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator== ( C *  ptr  )  const [inline]

Definition at line 319 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator!= ( const AutoPtr< C > &  ptr  )  const [inline]

Definition at line 324 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator!= ( const C *  ptr  )  const [inline]

Definition at line 329 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator!= ( C *  ptr  )  const [inline]

Definition at line 334 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator< ( const AutoPtr< C > &  ptr  )  const [inline]

Definition at line 339 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator< ( const C *  ptr  )  const [inline]

Definition at line 344 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator< ( C *  ptr  )  const [inline]

Definition at line 349 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator<= ( const AutoPtr< C > &  ptr  )  const [inline]

Definition at line 354 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator<= ( const C *  ptr  )  const [inline]

Definition at line 359 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator<= ( C *  ptr  )  const [inline]

Definition at line 364 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator> ( const AutoPtr< C > &  ptr  )  const [inline]

Definition at line 369 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator> ( const C *  ptr  )  const [inline]

Definition at line 374 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator> ( C *  ptr  )  const [inline]

Definition at line 379 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator>= ( const AutoPtr< C > &  ptr  )  const [inline]

Definition at line 384 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator>= ( const C *  ptr  )  const [inline]

Definition at line 389 of file AutoPtr.h.

template<class C>
bool Poco::AutoPtr< C >::operator>= ( C *  ptr  )  const [inline]

Definition at line 394 of file AutoPtr.h.


Field Documentation

template<class C>
C* Poco::AutoPtr< C >::_ptr [private]


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

SourceForge.net Logo
Project space on SourceForge.net