CMS 3D CMS Logo

Public Member Functions | Private Attributes

DeepCopyPointer< T > Class Template Reference

#include <DeepCopyPointer.h>

List of all members.

Public Member Functions

 DeepCopyPointer ()
 DeepCopyPointer (const DeepCopyPointer &other)
 DeepCopyPointer (T *t)
 operator bool () const
 to allow test like " if (p) {...}"
Toperator* ()
const Toperator* () const
Toperator-> ()
const Toperator-> () const
DeepCopyPointeroperator= (const DeepCopyPointer &other)
bool operator== (const T *otherP) const
 to allow test like " if (p == &someT) {...}"
TreplaceInplace ()
void replaceWith (T *otherP)
 ~DeepCopyPointer ()

Private Attributes

TtheData

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 16 of file DeepCopyPointer.h.


Constructor & Destructor Documentation

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

Definition at line 19 of file DeepCopyPointer.h.

{ delete theData;}
template<class T>
DeepCopyPointer< T >::DeepCopyPointer ( ) [inline]

Definition at line 21 of file DeepCopyPointer.h.

: theData(0) {}
template<class T>
DeepCopyPointer< T >::DeepCopyPointer ( T t) [inline]

Definition at line 23 of file DeepCopyPointer.h.

: theData(t) {}
template<class T>
DeepCopyPointer< T >::DeepCopyPointer ( const DeepCopyPointer< T > &  other) [inline]

Definition at line 25 of file DeepCopyPointer.h.

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

Member Function Documentation

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

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

Definition at line 77 of file DeepCopyPointer.h.

{ return theData != 0;}
template<class T>
T& DeepCopyPointer< T >::operator* ( ) [inline]

Definition at line 70 of file DeepCopyPointer.h.

{ return *theData;}
template<class T>
const T& DeepCopyPointer< T >::operator* ( ) const [inline]

Definition at line 71 of file DeepCopyPointer.h.

{ return *theData;}
template<class T>
const T* DeepCopyPointer< T >::operator-> ( ) const [inline]

Definition at line 74 of file DeepCopyPointer.h.

{ return theData;}
template<class T>
T* DeepCopyPointer< T >::operator-> ( ) [inline]

Definition at line 73 of file DeepCopyPointer.h.

{ return theData;}
template<class T>
DeepCopyPointer& DeepCopyPointer< T >::operator= ( const DeepCopyPointer< T > &  other) [inline]

Definition at line 29 of file DeepCopyPointer.h.

                                                            {
    if ( theData != other.theData) {
      delete theData;
      if (other.theData) theData = new T( *other); else theData = 0;
    }
    return *this;
  }
template<class T>
bool DeepCopyPointer< T >::operator== ( const T otherP) const [inline]

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

Definition at line 80 of file DeepCopyPointer.h.

{ return theData == otherP;}
template<class T>
T* DeepCopyPointer< T >::replaceInplace ( ) [inline]

Definition at line 65 of file DeepCopyPointer.h.

                      {
    return theData;
  }
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 53 of file DeepCopyPointer.h.

Referenced by BasicTrajectoryState::checkGlobalParameters().

                               {
    if ( theData != otherP ) {
        delete theData;
        theData = otherP;
    }
  }

Member Data Documentation

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