CMS 3D CMS Logo

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:
34  CloningPtr(const T& iPtr) : ptr_(P::clone(iPtr)) {}
35  CloningPtr(std::unique_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) { std::swap(ptr_, iPtr.ptr_); }
45 
46  ~CloningPtr() { delete ptr_; }
47 
48  // ---------- const member functions ---------------------
49  T& operator*() { return *ptr_; }
50 
51  T* operator->() { return ptr_; }
52 
53  T* get() { return ptr_; }
54 
55  private:
56  T* ptr_;
57  };
58 
59  // Free swap function
60  template <class T, class P>
62  a.swap(b);
63  }
64 } // namespace edm
65 #endif
CloningPtr(std::unique_ptr< T > iPtr)
Definition: CloningPtr.h:35
CloningPtr(const CloningPtr< T, P > &iPtr)
Definition: CloningPtr.h:36
#define nullptr
CloningPtr(const T &iPtr)
Definition: CloningPtr.h:34
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
double b
Definition: hdecay.h:118
std::pair< OmniClusterRef, TrackingParticleRef > P
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
CloningPtr< T, P > & operator=(const CloningPtr< T, P > &iRHS)
Definition: CloningPtr.h:38
HLT enums.
double a
Definition: hdecay.h:119
T * operator->()
Definition: CloningPtr.h:51
long double T
void swap(CloningPtr< T, P > &iPtr)
Definition: CloningPtr.h:44