CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
DeepCopyPointer< T > Class Template Reference

#include <DeepCopyPointer.h>

Public Member Functions

 DeepCopyPointer ()
 
 DeepCopyPointer (T *t)
 
 DeepCopyPointer (const DeepCopyPointer &other)
 
 operator bool () const
 to allow test like " if (p) {...}" More...
 
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) {...}" More...
 
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.

References DeepCopyPointer< T >::theData.

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

Definition at line 21 of file DeepCopyPointer.h.

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

Definition at line 23 of file DeepCopyPointer.h.

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

Definition at line 25 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

25  {
26  if (other.theData) theData = new T( *other); else theData = 0;
27  }
long double T

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.

References DeepCopyPointer< T >::theData.

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

Definition at line 70 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

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

Definition at line 71 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

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

Definition at line 73 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

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

Definition at line 74 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

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

Definition at line 29 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

29  {
30  if ( theData != other.theData) {
31  delete theData;
32  if (other.theData) theData = new T( *other); else theData = 0;
33  }
34  return *this;
35  }
long double T
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.

References DeepCopyPointer< T >::theData.

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

Definition at line 65 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

65  {
66  return theData;
67  }
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.

References DeepCopyPointer< T >::theData.

53  {
54  if ( theData != otherP ) {
55  delete theData;
56  theData = otherP;
57  }
58  }

Member Data Documentation

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