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:
33  CloningPtr() : ptr_(nullptr) {}
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
ClonePolicy.h
edm::CloningPtr::CloningPtr
CloningPtr(const T &iPtr)
Definition: CloningPtr.h:34
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
edm::CloningPtr::get
T * get()
Definition: CloningPtr.h:53
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::CloningPtr
Definition: CloningPtr.h:31
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
b
double b
Definition: hdecay.h:118
a
double a
Definition: hdecay.h:119
edm::CloningPtr::operator*
T & operator*()
Definition: CloningPtr.h:49
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
edm::CloningPtr::operator=
CloningPtr< T, P > & operator=(const CloningPtr< T, P > &iRHS)
Definition: CloningPtr.h:38
edm::CloningPtr::~CloningPtr
~CloningPtr()
Definition: CloningPtr.h:46
T
long double T
Definition: Basic3DVectorLD.h:48
edm::CloningPtr::CloningPtr
CloningPtr()
Definition: CloningPtr.h:33
P
std::pair< OmniClusterRef, TrackingParticleRef > P
Definition: BDHadronTrackMonitoringAnalyzer.cc:202
edm::CloningPtr::ptr_
T * ptr_
Definition: CloningPtr.h:56
edm::CloningPtr::swap
void swap(CloningPtr< T, P > &iPtr)
Definition: CloningPtr.h:44
edm::CloningPtr::operator->
T * operator->()
Definition: CloningPtr.h:51
edm::CloningPtr::CloningPtr
CloningPtr(std::unique_ptr< T > iPtr)
Definition: CloningPtr.h:35
edm::CloningPtr::CloningPtr
CloningPtr(const CloningPtr< T, P > &iPtr)
Definition: CloningPtr.h:36