CMS 3D CMS Logo

DeepCopyPointer.h
Go to the documentation of this file.
1 #ifndef DeepCopyPointer_H
2 #define DeepCopyPointer_H
3 
4 #include <algorithm>
5 
14 template <class T>
16 public:
17  ~DeepCopyPointer() { delete theData; }
18 
20 
22 
24  if (other.theData)
25  theData = new T(*other);
26  else
27  theData = 0;
28  }
29 
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  }
40 
41  // straight from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2027.html
44  std::swap(theData, other.theData);
45  return *this;
46  }
47 
50  void replaceWith(T* otherP) {
51  if (theData != otherP) {
52  delete theData;
53  theData = otherP;
54  }
55  }
56 
57  // assume that the replacement object is of the very same class!
58  // at the moment all the work is done by the client i.e.
59  // call the distructor
60  // new in place
61  // with c++0X a templated method can encasulate it all here...
62  T* replaceInplace() { return theData; }
63 
64  T& operator*() { return *theData; }
65  const T& operator*() const { return *theData; }
66 
67  T* operator->() { return theData; }
68  const T* operator->() const { return theData; }
69 
71  operator bool() const { return theData != 0; }
72 
74  bool operator==(const T* otherP) const { return theData == otherP; }
75 
76 private:
78 };
79 
80 #endif // DeepCopyPointer_H
electrons_cff.bool
bool
Definition: electrons_cff.py:372
DeepCopyPointer::operator*
const T & operator*() const
Definition: DeepCopyPointer.h:65
DeepCopyPointer::replaceWith
void replaceWith(T *otherP)
Definition: DeepCopyPointer.h:50
DeepCopyPointer::DeepCopyPointer
DeepCopyPointer(T *t)
Definition: DeepCopyPointer.h:21
DeepCopyPointer::replaceInplace
T * replaceInplace()
Definition: DeepCopyPointer.h:62
DeepCopyPointer::operator=
DeepCopyPointer & operator=(const DeepCopyPointer &other)
Definition: DeepCopyPointer.h:30
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
DeepCopyPointer::DeepCopyPointer
DeepCopyPointer(DeepCopyPointer &&other)
Definition: DeepCopyPointer.h:42
trackingPlots.other
other
Definition: trackingPlots.py:1465
DeepCopyPointer
Definition: DeepCopyPointer.h:15
OrderedSet.t
t
Definition: OrderedSet.py:90
DeepCopyPointer::operator->
T * operator->()
Definition: DeepCopyPointer.h:67
DeepCopyPointer::operator->
const T * operator->() const
Definition: DeepCopyPointer.h:68
DeepCopyPointer::operator=
DeepCopyPointer & operator=(DeepCopyPointer &&other)
Definition: DeepCopyPointer.h:43
DeepCopyPointer::theData
T * theData
Definition: DeepCopyPointer.h:77
DeepCopyPointer::DeepCopyPointer
DeepCopyPointer(const DeepCopyPointer &other)
Definition: DeepCopyPointer.h:23
T
long double T
Definition: Basic3DVectorLD.h:48
DeepCopyPointer::operator==
bool operator==(const T *otherP) const
to allow test like " if (p == &someT) {...}"
Definition: DeepCopyPointer.h:74
DeepCopyPointer::~DeepCopyPointer
~DeepCopyPointer()
Definition: DeepCopyPointer.h:17
DeepCopyPointer::DeepCopyPointer
DeepCopyPointer()
Definition: DeepCopyPointer.h:19
DeepCopyPointer::operator*
T & operator*()
Definition: DeepCopyPointer.h:64