CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProxyBase11.h
Go to the documentation of this file.
1 #ifndef Tracker_ProxyBase11_H
2 #define Tracker_ProxyBase11_H
3 
7 
8 #ifndef CMS_NOCXX11
9 #include "ChurnAllocator.h"
10 #endif
11 
22 template <class T>
23 class ProxyBase11 {
24 public:
25 
26 #ifdef CMS_NOCXX11
27  typedef T * pointer;
28 #else
29  using pointer = std::shared_ptr<T>;
30 #endif
31 
32  // protected:
33 
35 
36  explicit ProxyBase11( T* p) : theData(p) {}
37 #ifndef CMS_NOCXX11
38  template<typename U>
39  ProxyBase11(std::shared_ptr<U> p) : theData(std::move(p)){}
40  template<typename U>
41  ProxyBase11& operator=(std::shared_ptr<U> p) { theData =std::move(p); return *this;}
42 #endif
43 
45  destroy();
46  }
47 
48  void swap(ProxyBase11& other) noexcept {
49  std::swap(theData,other.theData);
50  }
51 
52 #ifdef CMS_NOCXX11
53  ProxyBase11& operator=( const ProxyBase11& other) {
54  return *this;
55  }
56  ProxyBase11( const ProxyBase11& other) {}
57 #else
59  ProxyBase11& operator=(ProxyBase11&& other) noexcept = default;
60  ProxyBase11(ProxyBase11 const & other) = default;
61  ProxyBase11& operator=( const ProxyBase11& other) = default;
62 #endif
63 
64  void reset() { theData.reset();}
65 
66  const T& data() const { check(); return *theData;}
67 
69  check();
70  if ( references() > 1) {
71  theData = theData->clone();
72  }
73  return *theData;
74  }
75 
76  T& sharedData() { check(); return *theData;}
77 
78  bool isValid() const { return bool(theData);}
79 
80  void check() const {
81 #ifdef TR_DEBUG
82  if unlikely(!theData)
83  throw TrajectoryStateException("Error: uninitialized ProxyBase11 used");
84 #endif
85  }
86 
87  void destroy() noexcept {}
88 #ifndef CMS_NOCXX11
89  int references() const {return theData.use_count();}
90 #else
91  int references() const { return 0;}
92 #endif
93 
94 private:
95 #ifdef CMS_NOCXX11
97 #else
98  std::shared_ptr<T> theData;
99 #endif
100 };
101 
102 template <class T >
103 inline
105  lh.swap(rh);
106 }
107 
108 #endif // Tracker_ProxyBase11_H
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
void reset()
Definition: ProxyBase11.h:64
#define noexcept
bool int lh
Definition: SIMDVec.h:21
const T & data() const
Definition: ProxyBase11.h:66
#define unlikely(x)
ProxyBase11(const ProxyBase11 &other)
Definition: ProxyBase11.h:56
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ProxyBase11(T *p)
Definition: ProxyBase11.h:36
void swap(ProxyBase11 &other)
Definition: ProxyBase11.h:48
int references() const
Definition: ProxyBase11.h:91
T & unsharedData()
Definition: ProxyBase11.h:68
T & sharedData()
Definition: ProxyBase11.h:76
string const
Definition: compareJSON.py:14
void destroy()
Definition: ProxyBase11.h:87
bool isValid() const
Definition: ProxyBase11.h:78
long double T
void check() const
Definition: ProxyBase11.h:80
ProxyBase11 & operator=(const ProxyBase11 &other)
Definition: ProxyBase11.h:53