CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CloningPtr.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_CloningPtr_h
2 #define DataFormats_Common_CloningPtr_h
3 // -*- C++ -*-
4 //
5 // Package: Common
6 // Class : CloningPtr
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Mon Apr 3 16:43:29 EDT 2006
19 //
20 
21 // system include files
22 #include <algorithm>
23 #include <memory>
24 
25 // user include files
27 
28 // forward declarations
29 namespace edm {
30  template< class T, class P = ClonePolicy<T> >
31  class CloningPtr {
32 public:
33  CloningPtr(): ptr_(0) {}
34  CloningPtr(const T& iPtr) : ptr_(P::clone(iPtr)) {}
35  CloningPtr(std::auto_ptr<T> iPtr) : ptr_(iPtr.release()) {}
36  CloningPtr(const CloningPtr<T,P>& iPtr) : ptr_(P::clone(*(iPtr.ptr_))) {}
37 
39  CloningPtr<T,P> temp(iRHS);
40  swap(temp);
41  return *this;
42  }
43 
44  void swap(CloningPtr<T,P>& iPtr) {
45  std::swap(ptr_, iPtr.ptr_);
46  }
47 
48  ~CloningPtr() { delete ptr_;}
49 
50  // ---------- const member functions ---------------------
51  T& operator*() const { return *ptr_; }
52 
53  T* operator->() const { return ptr_; }
54 
55  T* get() const { return ptr_; }
56 
57 private:
58  T* ptr_;
59  };
60 
61  // Free swap function
62  template <class T, class P>
63  inline
64  void
66  {
67  a.swap(b);
68  }
69 }
70 #endif
CloningPtr(const CloningPtr< T, P > &iPtr)
Definition: CloningPtr.h:36
T & operator*() const
Definition: CloningPtr.h:51
CloningPtr< T, P > & operator=(const CloningPtr< T, P > &iRHS)
Definition: CloningPtr.h:38
#define P
CloningPtr(const T &iPtr)
Definition: CloningPtr.h:34
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
CloningPtr(std::auto_ptr< T > iPtr)
Definition: CloningPtr.h:35
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T * operator->() const
Definition: CloningPtr.h:53
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
tuple clone
Definition: statics.py:58
long double T
void swap(CloningPtr< T, P > &iPtr)
Definition: CloningPtr.h:44