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 // $Id: CloningPtr.h,v 1.6 2011/11/16 22:34:34 wmtan Exp $
20 //
21 
22 // system include files
23 #include <algorithm>
24 #include <memory>
25 
26 // user include files
28 
29 // forward declarations
30 namespace edm {
31  template< class T, class P = ClonePolicy<T> >
32  class CloningPtr {
33 public:
34  CloningPtr(): ptr_(0) {}
35  CloningPtr(const T& iPtr) : ptr_(P::clone(iPtr)) {}
36  CloningPtr(std::auto_ptr<T> iPtr) : ptr_(iPtr.release()) {}
37  CloningPtr(const CloningPtr<T,P>& iPtr) : ptr_(P::clone(*(iPtr.ptr_))) {}
38 
40  CloningPtr<T,P> temp(iRHS);
41  swap(temp);
42  return *this;
43  }
44 
45  void swap(CloningPtr<T,P>& iPtr) {
46  std::swap(ptr_, iPtr.ptr_);
47  }
48 
49  ~CloningPtr() { delete ptr_;}
50 
51  // ---------- const member functions ---------------------
52  T& operator*() const { return *ptr_; }
53 
54  T* operator->() const { return ptr_; }
55 
56  T* get() const { return ptr_; }
57 
58 private:
59  T* ptr_;
60  };
61 
62  // Free swap function
63  template <class T, class P>
64  inline
65  void
67  {
68  a.swap(b);
69  }
70 }
71 #endif
CloningPtr(const CloningPtr< T, P > &iPtr)
Definition: CloningPtr.h:37
T & operator*() const
Definition: CloningPtr.h:52
CloningPtr< T, P > & operator=(const CloningPtr< T, P > &iRHS)
Definition: CloningPtr.h:39
#define P
CloningPtr(const T &iPtr)
Definition: CloningPtr.h:35
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
CloningPtr(std::auto_ptr< T > iPtr)
Definition: CloningPtr.h:36
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T * operator->() const
Definition: CloningPtr.h:54
double b
Definition: hdecay.h:120
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
double a
Definition: hdecay.h:121
long double T
void swap(CloningPtr< T, P > &iPtr)
Definition: CloningPtr.h:45