TC::WeakPtr< T > Class Template Reference
[Base Classes and Functions]

The WeakPtr class template stores a "weak reference" to an object that's already managed by a SharedPtr. More...

#include <TCWeakPtr.h>

Collaboration diagram for TC::WeakPtr< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 WeakPtr ()
 null pointer construction
template<class M_PTR >
 WeakPtr (const WeakPtr< M_PTR > &r)
 Copy constructor.
template<class M_PTR >
 WeakPtr (const SharedPtr< M_PTR > &r)
 Construct a weak pointer out of an shared pointer.
SharedPtr< T > Lock () const
 Get the shared pointer of this weak pointer.
long GetUseCount () const
 Get how many shared pointer point to the same pointer.
bool IsExpired () const
 True if the the pointer pointing to is already deleted.
void Reset ()
 Let the weak pointer point to a null pointer.
void Swap (WeakPtr< T > &other)
 Swap two weak pointers.
template<class N_PTR >
bool Equal (const WeakPtr< N_PTR > &src) const
 Check if a weak pointer is equal with another.
template<class M_PTR >
bool Less (const WeakPtr< M_PTR > &src) const
 Check if a weak pointer is less then another.

Private Attributes

T * m_ptr
WeakPtrCount m_count

Friends

class WeakPtr
class SharedPtr


Detailed Description

template<class T>
class TC::WeakPtr< T >

The WeakPtr class template stores a "weak reference" to an object that's already managed by a SharedPtr.

To access the object, a WeakPtr can be converted to a SharedPtr using the SharedPtr constructor or the member function Lock. When the last SharedPtr to the object goes away and the object is deleted, the attempt to obtain a SharedPtr from the WeakPtr instances that refer to the deleted object will fail: WeakPtr::Lock will return an empty SharedPtr.

The class template is parameterized on PTR, the type of the object pointed to.

Author:
Thomas Goessler

Definition at line 68 of file TCWeakPtr.h.


Constructor & Destructor Documentation

template<class T >
TC::WeakPtr< T >::WeakPtr (  )  [inline]

null pointer construction

Definition at line 72 of file TCWeakPtr.h.

template<class T >
template<class M_PTR >
TC::WeakPtr< T >::WeakPtr ( const WeakPtr< M_PTR > &  r  )  [inline]

Copy constructor.

Definition at line 76 of file TCWeakPtr.h.

template<class T >
template<class M_PTR >
TC::WeakPtr< T >::WeakPtr ( const SharedPtr< M_PTR > &  r  )  [inline]

Construct a weak pointer out of an shared pointer.

Definition at line 80 of file TCWeakPtr.h.


Member Function Documentation

template<class T >
SharedPtr<T> TC::WeakPtr< T >::Lock (  )  const [inline]

Get the shared pointer of this weak pointer.

Definition at line 83 of file TCWeakPtr.h.

References TC::WeakPtr< T >::IsExpired().

Here is the call graph for this function:

template<class T >
long TC::WeakPtr< T >::GetUseCount (  )  const [inline]

Get how many shared pointer point to the same pointer.

Definition at line 86 of file TCWeakPtr.h.

References TC::WeakPtrCount::GetUseCount(), and TC::WeakPtr< T >::m_count.

Here is the call graph for this function:

template<class T >
bool TC::WeakPtr< T >::IsExpired (  )  const [inline]

True if the the pointer pointing to is already deleted.

Definition at line 89 of file TCWeakPtr.h.

References TC::WeakPtrCount::GetUseCount(), and TC::WeakPtr< T >::m_count.

Referenced by TC::WeakPtr< T >::Lock().

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
void TC::WeakPtr< T >::Reset (  )  [inline]

Let the weak pointer point to a null pointer.

Definition at line 92 of file TCWeakPtr.h.

References TC::WeakPtr< T >::Swap().

Here is the call graph for this function:

template<class T >
void TC::WeakPtr< T >::Swap ( WeakPtr< T > &  other  )  [inline]

Swap two weak pointers.

Definition at line 95 of file TCWeakPtr.h.

References TC::WeakPtr< T >::m_count, TC::WeakPtr< T >::m_ptr, and TC::WeakPtrCount::Swap().

Referenced by TC::WeakPtr< T >::Reset().

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
template<class N_PTR >
bool TC::WeakPtr< T >::Equal ( const WeakPtr< N_PTR > &  src  )  const [inline]

Check if a weak pointer is equal with another.

Definition at line 99 of file TCWeakPtr.h.

References TC::WeakPtr< T >::m_ptr.

Referenced by TC::operator!=(), and TC::operator==().

Here is the caller graph for this function:

template<class T >
template<class M_PTR >
bool TC::WeakPtr< T >::Less ( const WeakPtr< M_PTR > &  src  )  const [inline]

Check if a weak pointer is less then another.

Definition at line 103 of file TCWeakPtr.h.

References TC::WeakPtr< T >::m_count.


Friends And Related Function Documentation

template<class T >
friend class WeakPtr [friend]

Definition at line 109 of file TCWeakPtr.h.

template<class T >
friend class SharedPtr [friend]

Definition at line 110 of file TCWeakPtr.h.


Member Data Documentation

template<class T >
T* TC::WeakPtr< T >::m_ptr [private]

Definition at line 106 of file TCWeakPtr.h.

Referenced by TC::WeakPtr< T >::Equal(), and TC::WeakPtr< T >::Swap().

template<class T >
WeakPtrCount TC::WeakPtr< T >::m_count [private]


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

Copyright (c) Thomas Goessler 2003 - 2008