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 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
38  // straight from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2027.html
39 
40  DeepCopyPointer( DeepCopyPointer&& other) : theData(other.theData) {
41  other.theData=0;
42  }
43 
45  std::swap(theData,other.theData);
46  return *this;
47  }
48 #endif
49 
50 
53  void replaceWith(T * otherP) {
54  if ( theData != otherP ) {
55  delete theData;
56  theData = otherP;
57  }
58  }
59 
60  // assume that the replacement object is of the very same class!
61  // at the moment all the work is done by the client i.e.
62  // call the distructor
63  // new in place
64  // with c++0X a templated method can encasulate it all here...
66  return theData;
67  }
68 
69 
70  T& operator*() { return *theData;}
71  const T& operator*() const { return *theData;}
72 
73  T* operator->() { return theData;}
74  const T* operator->() const { return theData;}
75 
77  operator bool() const { return theData != 0;}
78 
80  bool operator==( const T* otherP) const { return theData == otherP;}
81 
82 private:
84 };
85 
86 #endif // DeepCopyPointer_H
const T & operator*() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
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)