CMS 3D CMS Logo

DeepCopyPointerByClone.h
Go to the documentation of this file.
1 #ifndef DeepCopyPointerByClone_H
2 #define DeepCopyPointerByClone_H
3 
4 #include <algorithm>
5 #include <cassert>
6 
11 template <class T>
13 public:
16 
18 
20  if (other.theData)
21  theData = other->clone();
22  else
23  theData = nullptr;
24  }
25 
27  if (theData != other.theData) {
28  delete theData;
29  if (other.theData)
30  theData = other->clone();
31  else
32  theData = 0;
33  }
34  return *this;
35  }
36 
37  // straight from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2027.html
40  std::swap(theData, other.theData);
41  return *this;
42  }
43 
44  T& operator*() {
45  assert(theData);
46  return *theData;
47  }
48  const T& operator*() const {
49  assert(theData);
50  return *theData;
51  }
52 
54  assert(theData);
55  return theData;
56  }
57  const T* operator->() const {
58  assert(theData);
59  return theData;
60  }
61 
63  operator bool() const { return theData != 0; }
64 
66  bool operator==(const T* otherP) const { return theData == otherP; }
67 
68 private:
70 };
71 
72 #endif // DeepCopyPointerByClone_H
DeepCopyPointerByClone & operator=(DeepCopyPointerByClone &&other)
DeepCopyPointerByClone & operator=(const DeepCopyPointerByClone &other)
assert(be >=bs)
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
DeepCopyPointerByClone(const DeepCopyPointerByClone &other)
bool operator==(const T *otherP) const
to allow test like " if (p == &someT) {...}"
DeepCopyPointerByClone(DeepCopyPointerByClone &&other)
long double T