CMS 3D CMS Logo

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)
 
 DeepCopyPointer (DeepCopyPointer &&other)
 
 operator bool () const
 to allow test like " if (p) {...}" More...
 
Toperator* ()
 
const Toperator* () const
 
Toperator-> ()
 
const Toperator-> () const
 
DeepCopyPointeroperator= (const DeepCopyPointer &other)
 
DeepCopyPointeroperator= (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 15 of file DeepCopyPointer.h.

Constructor & Destructor Documentation

◆ ~DeepCopyPointer()

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

Definition at line 17 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

17 { delete theData; }

◆ DeepCopyPointer() [1/4]

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

Definition at line 19 of file DeepCopyPointer.h.

19 : theData(0) {}

◆ DeepCopyPointer() [2/4]

template<class T >
DeepCopyPointer< T >::DeepCopyPointer ( T t)
inline

Definition at line 21 of file DeepCopyPointer.h.

◆ DeepCopyPointer() [3/4]

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

Definition at line 23 of file DeepCopyPointer.h.

References trackingPlots::other, and DeepCopyPointer< T >::theData.

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

◆ DeepCopyPointer() [4/4]

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

Definition at line 42 of file DeepCopyPointer.h.

References trackingPlots::other.

42 : theData(other.theData) { other.theData = 0; }

Member Function Documentation

◆ operator bool()

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

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

Definition at line 71 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

71 { return theData != 0; }

◆ operator*() [1/2]

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

Definition at line 64 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

64 { return *theData; }

◆ operator*() [2/2]

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

Definition at line 65 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

65 { return *theData; }

◆ operator->() [1/2]

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

Definition at line 67 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

67 { return theData; }

◆ operator->() [2/2]

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

Definition at line 68 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

68 { return theData; }

◆ operator=() [1/2]

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

Definition at line 30 of file DeepCopyPointer.h.

References trackingPlots::other, and DeepCopyPointer< T >::theData.

30  {
31  if (theData != other.theData) {
32  delete theData;
33  if (other.theData)
34  theData = new T(*other);
35  else
36  theData = 0;
37  }
38  return *this;
39  }
long double T

◆ operator=() [2/2]

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

Definition at line 43 of file DeepCopyPointer.h.

References trackingPlots::other, std::swap(), and DeepCopyPointer< T >::theData.

43  {
44  std::swap(theData, other.theData);
45  return *this;
46  }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)

◆ operator==()

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

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

Definition at line 74 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

74 { return theData == otherP; }

◆ replaceInplace()

template<class T >
T* DeepCopyPointer< T >::replaceInplace ( )
inline

Definition at line 62 of file DeepCopyPointer.h.

References DeepCopyPointer< T >::theData.

62 { return theData; }

◆ replaceWith()

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

References DeepCopyPointer< T >::theData.

50  {
51  if (theData != otherP) {
52  delete theData;
53  theData = otherP;
54  }
55  }

Member Data Documentation

◆ theData

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