test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeepCopyPointer.h
Go to the documentation of this file.
1 #ifndef DeepCopyPointer_H
2 #define DeepCopyPointer_H
3 
4 
5 #include<algorithm>
6 
15 template <class T>
17 public:
18 
20 
22 
24 
26  if (other.theData) theData = new T( *other); else theData = 0;
27  }
28 
30  if ( theData != other.theData) {
31  delete theData;
32  if (other.theData) theData = new T( *other); else theData = 0;
33  }
34  return *this;
35  }
36 
37  // straight from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2027.html
39  other.theData=0;
40  }
42  std::swap(theData,other.theData);
43  return *this;
44  }
45 
46 
49  void replaceWith(T * otherP) {
50  if ( theData != otherP ) {
51  delete theData;
52  theData = otherP;
53  }
54  }
55 
56  // assume that the replacement object is of the very same class!
57  // at the moment all the work is done by the client i.e.
58  // call the distructor
59  // new in place
60  // with c++0X a templated method can encasulate it all here...
62  return theData;
63  }
64 
65 
66  T& operator*() { return *theData;}
67  const T& operator*() const { return *theData;}
68 
69  T* operator->() { return theData;}
70  const T* operator->() const { return theData;}
71 
73  operator bool() const { return theData != 0;}
74 
76  bool operator==( const T* otherP) const { return theData == otherP;}
77 
78 private:
80 };
81 
82 #endif // DeepCopyPointer_H
DeepCopyPointer(DeepCopyPointer &&other)
const T & operator*() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
DeepCopyPointer & operator=(DeepCopyPointer &&other)
const T * operator->() const
void replaceWith(T *otherP)
bool operator==(const T *otherP) const
to allow test like &quot; if (p == &amp;someT) {...}&quot;
long double T
DeepCopyPointer & operator=(const DeepCopyPointer &other)
DeepCopyPointer(const DeepCopyPointer &other)