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
bool operator==(const T *otherP) const
to allow test like " if (p == &someT) {...}"
DeepCopyPointer(DeepCopyPointer &&other)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const T & operator*() const
const T * operator->() const
DeepCopyPointer & operator=(DeepCopyPointer &&other)
void replaceWith(T *otherP)
long double T
DeepCopyPointer & operator=(const DeepCopyPointer &other)
DeepCopyPointer(const DeepCopyPointer &other)