CMS 3D CMS Logo

ProxyBase11.h
Go to the documentation of this file.
1 #ifndef Tracker_ProxyBase11_H
2 #define Tracker_ProxyBase11_H
3 
6 
7 #ifdef TR_DEBUG
8 #include <iostream>
9 #endif
10 
11 #include "ChurnAllocator.h"
12 
22 template <class T>
23 class ProxyBase11 {
24 public:
25  using pointer = std::shared_ptr<T>;
26 
27  // protected:
28 
30 
31  explicit ProxyBase11(T* p) : theData(p) {}
32  template <typename U>
33  ProxyBase11(std::shared_ptr<U> p) : theData(std::move(p)) {}
34  template <typename U>
35  ProxyBase11& operator=(std::shared_ptr<U> p) {
36  theData = std::move(p);
37  return *this;
38  }
39 
41 
43 
46  ProxyBase11(ProxyBase11 const& other) = default;
47  ProxyBase11& operator=(const ProxyBase11& other) = default;
48 
49  void reset() { theData.reset(); }
50 
51  const T& data() const {
52  check();
53  return *theData;
54  }
55 
57  check();
58  if (references() > 1) {
59  theData = theData->clone();
60  }
61  return *theData;
62  }
63 
65  check();
66  return *theData;
67  }
68 
69  bool isValid() const { return bool(theData); }
70 
71  void check() const {
72 #ifdef TR_DEBUG
73  if
74  UNLIKELY(!theData) std::cout << "dead proxyBase11 " << references() << std::endl;
75 #endif
76  }
77 
78  void destroy() noexcept {}
79  int references() const { return theData.use_count(); }
80 
81 private:
82  std::shared_ptr<T> theData;
83 };
84 
85 template <class T>
87  lh.swap(rh);
88 }
89 
90 #endif // Tracker_ProxyBase11_H
ProxyBase11(std::shared_ptr< U > p)
Definition: ProxyBase11.h:33
void reset()
Definition: ProxyBase11.h:49
std::shared_ptr< T > theData
Definition: ProxyBase11.h:82
bool int lh
Definition: SIMDVec.h:20
std::shared_ptr< T > pointer
Definition: ProxyBase11.h:25
ProxyBase11 & operator=(std::shared_ptr< U > p)
Definition: ProxyBase11.h:35
const T & data() const
Definition: ProxyBase11.h:51
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ProxyBase11(T *p)
Definition: ProxyBase11.h:31
void swap(ProxyBase11 &other) noexcept
Definition: ProxyBase11.h:42
int references() const
Definition: ProxyBase11.h:79
T & unsharedData()
Definition: ProxyBase11.h:56
#define noexcept
T & sharedData()
Definition: ProxyBase11.h:64
~ProxyBase11() noexcept
Definition: ProxyBase11.h:40
void destroy() noexcept
Definition: ProxyBase11.h:78
#define UNLIKELY(x)
Definition: Likely.h:21
bool isValid() const
Definition: ProxyBase11.h:69
long double T
void check() const
Definition: ProxyBase11.h:71
def move(src, dest)
Definition: eostools.py:511