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

A class whose instances act like pointers that manage their reference count automatically. More...

#include <TCSharedPtr.h>

Collaboration diagram for TC::SharedPtr< T >:

Collaboration graph
[legend]

List of all members.

Public Types

typedef T ValueType
typedef T * PointerType
typedef SharedPtrTraits< T >
::Reference 
ReferenceType
typedef T *ThisType::* unspecified_bool_type
typedef void * unspecified_pointer_type

Public Member Functions

 SharedPtr ()
 Construct the object pointing to a 0 object.
template<class N_PTR >
 SharedPtr (N_PTR *ptr)
 Construct the object pointing to a specified object.
template<class N_PTR , class DELETER >
 SharedPtr (N_PTR *ptr, DELETER deleter)
 Construct the object pointing to a specified object + deleter.
template<class N_PTR >
 SharedPtr (std::auto_ptr< N_PTR > &ptr)
 Construct the object pointing to a specified std::auto_ptr.
template<class N_PTR >
 SharedPtr (const WeakPtr< N_PTR > &ptr)
 Construct the object pointing to a specified weak pointer.
template<class N_PTR >
 SharedPtr (const SharedPtr< N_PTR > &src)
 automatic downcast if possible
const T * operator-> () const
 User define conversion to the const Template pointer type.
T * operator-> ()
 User define conversion to the const Template pointer type.
 operator unspecified_bool_type () const
 User define conversion for if like "if ( smartPointer)".
bool operator! () const
 User define conversion for if like "if ( !smartPointer)".
uint32 GetUseCount () const
 Get how many shared pointer point to the same pointer.
bool IsUnique () const
 return true if there exists only one instance of this shared pointer
void Reset ()
 Let the shared pointer point to a null pointer.
template<class N_PTR >
void Reset (N_PTR *p)
 Let the shared pointer point to the new given pointer.
template<class N_PTR , class DELETER >
void Reset (N_PTR *p, DELETER deleter)
 Let the shared pointer point to the new given pointer and its deleter.
void Swap (SharedPtr< T > &a)
 Swap two smart pointers.
template<class N_PTR >
bool Equal (const SharedPtr< N_PTR > &src) const
 Check if a smart pointer is equal with another.
template<class N_PTR >
bool Less (const SharedPtr< N_PTR > &src) const
 Check if a smart pointer is less then another.

Static Public Member Functions

template<class N_PTR >
static ThisType DynamicCast (const SharedPtr< N_PTR > &src)
 Dynamic cast method for Smart pointer.
template<class N_PTR >
static ThisType StaticCast (const SharedPtr< N_PTR > &src)
 Static cast method for Smart pointer.
template<class N_PTR >
static ThisType ConstCast (const SharedPtr< N_PTR > &src)
 Static cast method for Smart pointer.

Public Attributes

T * m_ptr
SharedPtrCount m_count

Private Types

typedef SharedPtr< T > ThisType

Friends

bool operator== (const SharedPtr< T > &a, unspecified_pointer_type b)
 equal operator with a unspecified pointer type
bool operator!= (const SharedPtr< T > &a, unspecified_pointer_type b)
 not equal operator with a unspecified pointer type


Detailed Description

template<class T>
class TC::SharedPtr< T >

A class whose instances act like pointers that manage their reference count automatically.

This shared pointer avoids destruction of an object in use. It can be used just like a pointer. First Template argument is the data type of the pointer.

Notes: Always pass shared pointers by value. Never create two smart pointers to the same regular pointer. Once a smart pointer is set to equal a pointer it owns that pointer, and will delete it when no more shared pointers point to the same ref.

Author:
Thomas Goessler

Definition at line 79 of file TCSharedPtr.h.


Member Typedef Documentation

template<class T >
typedef SharedPtr<T> TC::SharedPtr< T >::ThisType [private]

Definition at line 82 of file TCSharedPtr.h.

template<class T >
typedef T TC::SharedPtr< T >::ValueType

Definition at line 85 of file TCSharedPtr.h.

template<class T >
typedef T* TC::SharedPtr< T >::PointerType

Definition at line 86 of file TCSharedPtr.h.

template<class T >
typedef SharedPtrTraits<T>::Reference TC::SharedPtr< T >::ReferenceType

Definition at line 87 of file TCSharedPtr.h.

template<class T >
typedef T* ThisType::* TC::SharedPtr< T >::unspecified_bool_type

Definition at line 118 of file TCSharedPtr.h.

template<class T >
typedef void* TC::SharedPtr< T >::unspecified_pointer_type

Definition at line 124 of file TCSharedPtr.h.


Constructor & Destructor Documentation

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

Construct the object pointing to a 0 object.

Definition at line 91 of file TCSharedPtr.h.

template<class T >
template<class N_PTR >
TC::SharedPtr< T >::SharedPtr ( N_PTR *  ptr  )  [inline, explicit]

Construct the object pointing to a specified object.

Definition at line 95 of file TCSharedPtr.h.

template<class T >
template<class N_PTR , class DELETER >
TC::SharedPtr< T >::SharedPtr ( N_PTR *  ptr,
DELETER  deleter 
) [inline]

Construct the object pointing to a specified object + deleter.

Definition at line 99 of file TCSharedPtr.h.

template<class T >
template<class N_PTR >
TC::SharedPtr< T >::SharedPtr ( std::auto_ptr< N_PTR > &  ptr  )  [inline]

Construct the object pointing to a specified std::auto_ptr.

Definition at line 103 of file TCSharedPtr.h.

template<class T >
template<class N_PTR >
TC::SharedPtr< T >::SharedPtr ( const WeakPtr< N_PTR > &  ptr  )  [inline, explicit]

Construct the object pointing to a specified weak pointer.

Definition at line 107 of file TCSharedPtr.h.

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

automatic downcast if possible

Definition at line 111 of file TCSharedPtr.h.


Member Function Documentation

template<class T >
const T* TC::SharedPtr< T >::operator-> (  )  const [inline]

User define conversion to the const Template pointer type.

Definition at line 114 of file TCSharedPtr.h.

template<class T >
T* TC::SharedPtr< T >::operator-> (  )  [inline]

User define conversion to the const Template pointer type.

Definition at line 116 of file TCSharedPtr.h.

template<class T >
TC::SharedPtr< T >::operator unspecified_bool_type (  )  const [inline]

User define conversion for if like "if ( smartPointer)".

Definition at line 120 of file TCSharedPtr.h.

template<class T >
bool TC::SharedPtr< T >::operator! (  )  const [inline]

User define conversion for if like "if ( !smartPointer)".

Definition at line 122 of file TCSharedPtr.h.

template<class T >
uint32 TC::SharedPtr< T >::GetUseCount (  )  const [inline]

Get how many shared pointer point to the same pointer.

Definition at line 131 of file TCSharedPtr.h.

template<class T >
bool TC::SharedPtr< T >::IsUnique (  )  const [inline]

return true if there exists only one instance of this shared pointer

Definition at line 134 of file TCSharedPtr.h.

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

Let the shared pointer point to a null pointer.

Definition at line 137 of file TCSharedPtr.h.

template<class T >
template<class N_PTR >
void TC::SharedPtr< T >::Reset ( N_PTR *  p  )  [inline]

Let the shared pointer point to the new given pointer.

Definition at line 140 of file TCSharedPtr.h.

template<class T >
template<class N_PTR , class DELETER >
void TC::SharedPtr< T >::Reset ( N_PTR *  p,
DELETER  deleter 
) [inline]

Let the shared pointer point to the new given pointer and its deleter.

Definition at line 143 of file TCSharedPtr.h.

template<class T >
void TC::SharedPtr< T >::Swap ( SharedPtr< T > &  a  )  [inline]

Swap two smart pointers.

Definition at line 146 of file TCSharedPtr.h.

Referenced by TC::SharedPtr< TC::MT::Semaphore >::Reset().

Here is the caller graph for this function:

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

Check if a smart pointer is equal with another.

Definition at line 150 of file TCSharedPtr.h.

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

Here is the caller graph for this function:

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

Check if a smart pointer is less then another.

Definition at line 154 of file TCSharedPtr.h.

template<class T >
template<class N_PTR >
static ThisType TC::SharedPtr< T >::DynamicCast ( const SharedPtr< N_PTR > &  src  )  [inline, static]

Dynamic cast method for Smart pointer.

Definition at line 163 of file TCSharedPtr.h.

template<class T >
template<class N_PTR >
static ThisType TC::SharedPtr< T >::StaticCast ( const SharedPtr< N_PTR > &  src  )  [inline, static]

Static cast method for Smart pointer.

Definition at line 176 of file TCSharedPtr.h.

template<class T >
template<class N_PTR >
static ThisType TC::SharedPtr< T >::ConstCast ( const SharedPtr< N_PTR > &  src  )  [inline, static]

Static cast method for Smart pointer.

Definition at line 187 of file TCSharedPtr.h.


Friends And Related Function Documentation

template<class T >
bool operator== ( const SharedPtr< T > &  a,
unspecified_pointer_type  b 
) [friend]

equal operator with a unspecified pointer type

Definition at line 126 of file TCSharedPtr.h.

template<class T >
bool operator!= ( const SharedPtr< T > &  a,
unspecified_pointer_type  b 
) [friend]

not equal operator with a unspecified pointer type

Definition at line 128 of file TCSharedPtr.h.


Member Data Documentation

template<class T >
T* TC::SharedPtr< T >::m_ptr

template<class T >
SharedPtrCount TC::SharedPtr< T >::m_count


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

Copyright (c) Thomas Goessler 2003 - 2008