CMS 3D CMS Logo

DeepCopyPointer< T > Class Template Reference

A "smart" pointer that implements deep copy and ownership. More...

#include <DataFormats/GeometryCommonDetAlgo/interface/DeepCopyPointer.h>

List of all members.

Public Member Functions

 DeepCopyPointer (const DeepCopyPointer &other)
 DeepCopyPointer (T *t)
 DeepCopyPointer ()
const T & operator * () const
T & operator * ()
 operator bool () const
 to allow test like " if (p) {...}"
const T * operator-> () const
T * operator-> ()
DeepCopyPointeroperator= (const DeepCopyPointer &other)
bool operator== (const T *otherP) const
 to allow test like " if (p == &someT) {...}"
void replaceWith (T *otherP)
 Assing a new bare pointer to this DeepCopyPointer, taking ownership of it.
 ~DeepCopyPointer ()

Private Attributes

T * theData


Detailed Description

template<class T>
class DeepCopyPointer< T >

A "smart" pointer that implements deep copy and ownership.

In other words, when the pointer is copied it copies the object it points to using "new". It also deletes the object it points to when it is deleted. Very useful for use as private data member of a class: it handles the copy construction, assignment, and destruction.

Definition at line 13 of file DeepCopyPointer.h.


Constructor & Destructor Documentation

template<class T>
DeepCopyPointer< T >::DeepCopyPointer (  )  [inline]

Definition at line 16 of file DeepCopyPointer.h.

00016 : theData(0) {}

template<class T>
DeepCopyPointer< T >::DeepCopyPointer ( T *  t  )  [inline]

Definition at line 18 of file DeepCopyPointer.h.

00018 : theData(t) {}

template<class T>
DeepCopyPointer< T >::DeepCopyPointer ( const DeepCopyPointer< T > &  other  )  [inline]

Definition at line 20 of file DeepCopyPointer.h.

00020                                                  {
00021     if (other.theData) theData = new T( *other); else theData = 0;
00022   }

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

Definition at line 24 of file DeepCopyPointer.h.

00024 { delete theData;}


Member Function Documentation

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

Definition at line 45 of file DeepCopyPointer.h.

00045 { return *theData;}

template<class T>
T& DeepCopyPointer< T >::operator * (  )  [inline]

Definition at line 44 of file DeepCopyPointer.h.

00044 { return *theData;}

template<class T>
DeepCopyPointer< T >::operator bool (  )  const [inline]

to allow test like " if (p) {...}"

Definition at line 51 of file DeepCopyPointer.h.

00051 { return theData != 0;}

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

Definition at line 48 of file DeepCopyPointer.h.

00048 { return theData;}

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

Definition at line 47 of file DeepCopyPointer.h.

00047 { return theData;}

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

Definition at line 26 of file DeepCopyPointer.h.

00026                                                             {
00027     if ( theData != other.theData) {
00028       delete theData;
00029       if (other.theData) theData = new T( *other); else theData = 0;
00030     }
00031     return *this;
00032   }

template<class T>
bool DeepCopyPointer< T >::operator== ( const T *  otherP  )  const [inline]

to allow test like " if (p == &someT) {...}"

Definition at line 54 of file DeepCopyPointer.h.

00054 { return theData == otherP;}

template<class T>
void DeepCopyPointer< T >::replaceWith ( T *  otherP  )  [inline]

Assing a new bare pointer to this DeepCopyPointer, taking ownership of it.

The old content of this DeepCopyPointer is deleted

Definition at line 36 of file DeepCopyPointer.h.

Referenced by BasicSingleTrajectoryState::checkGlobalParameters().

00036                                {
00037     if ( theData != otherP ) {
00038         delete theData;
00039         theData = otherP;
00040     }
00041   }


Member Data Documentation

template<class T>
T* DeepCopyPointer< T >::theData [private]

Definition at line 57 of file DeepCopyPointer.h.

Referenced by DeepCopyPointer< KFStripUpdator >::DeepCopyPointer(), DeepCopyPointer< KFStripUpdator >::operator *(), DeepCopyPointer< KFStripUpdator >::operator bool(), DeepCopyPointer< KFStripUpdator >::operator->(), DeepCopyPointer< KFStripUpdator >::operator=(), DeepCopyPointer< KFStripUpdator >::operator==(), DeepCopyPointer< KFStripUpdator >::replaceWith(), and DeepCopyPointer< KFStripUpdator >::~DeepCopyPointer().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:18:22 2009 for CMSSW by  doxygen 1.5.4