Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends

cmtk::SmartConstPointer< T > Class Template Reference
[cmtkSystem Library]

Smart pointer with reference counting. More...

#include <cmtkSmartConstPtr.h>

Inheritance diagram for cmtk::SmartConstPointer< T >:
Inheritance graph
[legend]
Collaboration diagram for cmtk::SmartConstPointer< T >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef SmartConstPointer< T > Self
 This class instance.
typedef const T * PointerType
 The underlying raw pointer type.

Public Member Functions

unsigned int GetReferenceCount () const
 Get current reference counter value: use with caution!
 SmartConstPointer ()
 Default constructor.
 SmartConstPointer (T *const object)
 Construct from dumb pointer.
template<class T2 >
 SmartConstPointer (const SmartConstPointer< T2 > &ptr)
 Copy constructor template.
 SmartConstPointer (const Self &ptr)
 Copy constructor to prevent compiler-generated copy constructor.
 ~SmartConstPointer ()
 Destruct: decrease reference pointer and free dumb pointer if necessary.
const T & operator* () const
 De-referencing operator (returns constant object).
const T * operator-> () const
 De-referencing operator (returns constant object pointer).
 operator const T * () const
 Implicit conversion to constant pointer.
const T * GetConstPtr () const
 Explicit conversion to constant pointer.
const T * ReleasePtr ()
 Release control of this pointer.
const Selfoperator= (const Self other) const
 Assignment operator.
bool operator== (const Self &other) const
 Equality operator using pointer.
bool operator!= (const Self &other) const
 Inequality operator.
bool operator< (const Self &other) const
 "Smaller than" operator (necessay for storing objects in std::map).

Static Public Member Functions

template<class T2 >
static Self DynamicCastFrom (const T2 &from_P)
 Dynamic cast between smart pointer types.

Static Public Attributes

static Self Null
 Null object.

Protected Member Functions

 SmartConstPointer (const T *const object, SafeCounter *const counter)
 Construct from dumb pointer and existing reference counter.

Protected Attributes

SafeCounterm_ReferenceCount
 Pointer to detached reference counter for this object.
union {
   const T *   ptrConst
 Pointer to const.
   T *   ptr
 Pointer to non-const.
m_Object

Friends

class SmartConstPointer
 Make all template instances friends for easy type casting.

Detailed Description

template<class T>
class cmtk::SmartConstPointer< T >

Smart pointer with reference counting.

Definition at line 57 of file cmtkSmartConstPtr.h.


Member Typedef Documentation

template<class T>
typedef const T* cmtk::SmartConstPointer< T >::PointerType
template<class T>
typedef SmartConstPointer<T> cmtk::SmartConstPointer< T >::Self

Constructor & Destructor Documentation

template<class T>
cmtk::SmartConstPointer< T >::SmartConstPointer (  ) [inline]

Default constructor.

This needs to be separate because the constructor that takes a dumb pointer must be explicit, but the default constructor should not be.

Definition at line 79 of file cmtkSmartConstPtr.h.

template<class T>
cmtk::SmartConstPointer< T >::SmartConstPointer ( T *const   object ) [inline, explicit]

Construct from dumb pointer.

Note that you MUST NEVER use this constructor more than once for each dumb pointer, other than NULL!

Definition at line 89 of file cmtkSmartConstPtr.h.

template<class T>
template<class T2 >
cmtk::SmartConstPointer< T >::SmartConstPointer ( const SmartConstPointer< T2 > &  ptr ) [inline]

Copy constructor template.

Increment reference counter in the process.

Definition at line 99 of file cmtkSmartConstPtr.h.

template<class T>
cmtk::SmartConstPointer< T >::SmartConstPointer ( const Self ptr ) [inline]

Copy constructor to prevent compiler-generated copy constructor.

Increment reference counter in the process.

Definition at line 109 of file cmtkSmartConstPtr.h.

template<class T>
cmtk::SmartConstPointer< T >::~SmartConstPointer (  ) [inline]

Destruct: decrease reference pointer and free dumb pointer if necessary.

Definition at line 117 of file cmtkSmartConstPtr.h.

template<class T>
cmtk::SmartConstPointer< T >::SmartConstPointer ( const T *const   object,
SafeCounter *const   counter 
) [inline, protected]

Construct from dumb pointer and existing reference counter.

The reference counter is increased in the process.

Definition at line 220 of file cmtkSmartConstPtr.h.


Member Function Documentation

template<class T>
template<class T2 >
static Self cmtk::SmartConstPointer< T >::DynamicCastFrom ( const T2 &  from_P ) [inline, static]
template<class T>
const T* cmtk::SmartConstPointer< T >::GetConstPtr (  ) const [inline]

Explicit conversion to constant pointer.

Definition at line 146 of file cmtkSmartConstPtr.h.

template<class T>
unsigned int cmtk::SmartConstPointer< T >::GetReferenceCount (  ) const [inline]

Get current reference counter value: use with caution!

Definition at line 70 of file cmtkSmartConstPtr.h.

template<class T>
cmtk::SmartConstPointer< T >::operator const T * (  ) const [inline]

Implicit conversion to constant pointer.

Definition at line 143 of file cmtkSmartConstPtr.h.

template<class T>
bool cmtk::SmartConstPointer< T >::operator!= ( const Self other ) const [inline]

Inequality operator.

Definition at line 185 of file cmtkSmartConstPtr.h.

template<class T>
const T& cmtk::SmartConstPointer< T >::operator* (  ) const [inline]

De-referencing operator (returns constant object).

Definition at line 137 of file cmtkSmartConstPtr.h.

template<class T>
const T* cmtk::SmartConstPointer< T >::operator-> (  ) const [inline]

De-referencing operator (returns constant object pointer).

Definition at line 140 of file cmtkSmartConstPtr.h.

template<class T>
bool cmtk::SmartConstPointer< T >::operator< ( const Self other ) const [inline]

"Smaller than" operator (necessay for storing objects in std::map).

Definition at line 192 of file cmtkSmartConstPtr.h.

template<class T>
const Self& cmtk::SmartConstPointer< T >::operator= ( const Self  other ) const [inline]

Assignment operator.

This is implemented using the std::swap function.

Warning:
The "other" parameter HAS TO USE CALL BY VALUE for this function to work, because we are not creating an explicit copy of the original object before calling Swap() (see Effective C++, 3rd, Item 11, p.56).
Open question: given that we pass the parameter by value, not reference, does this really prevent the definition of a compiler-generated assignment (which passes parameter by reference)?

Definition at line 167 of file cmtkSmartConstPtr.h.

template<class T>
bool cmtk::SmartConstPointer< T >::operator== ( const Self other ) const [inline]

Equality operator using pointer.

Definition at line 178 of file cmtkSmartConstPtr.h.

template<class T>
const T* cmtk::SmartConstPointer< T >::ReleasePtr (  ) [inline]

Friends And Related Function Documentation

template<class T>
friend class SmartConstPointer [friend]

Make all template instances friends for easy type casting.

Definition at line 228 of file cmtkSmartConstPtr.h.


Member Data Documentation

union { ... } cmtk::SmartConstPointer< T >::m_Object [protected]
template<class T>
SafeCounter* cmtk::SmartConstPointer< T >::m_ReferenceCount [mutable, protected]

Pointer to detached reference counter for this object.

Definition at line 206 of file cmtkSmartConstPtr.h.

Referenced by cmtk::SmartConstPointer< Study >::operator=().

template<class T>
T* cmtk::SmartConstPointer< T >::ptr

Pointer to non-const.

Definition at line 214 of file cmtkSmartConstPtr.h.

template<class T>
const T* cmtk::SmartConstPointer< T >::ptrConst

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines