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 
23 template <class T>
24 class ProxyBase11 {
25 public:
26 
27  using pointer = std::shared_ptr<T>;
28 
29  // protected:
30 
32 
33  explicit ProxyBase11( T* p) : theData(p) {}
34  template<typename U>
35  ProxyBase11(std::shared_ptr<U> p) : theData(std::move(p)){}
36  template<typename U>
37  ProxyBase11& operator=(std::shared_ptr<U> p) { theData =std::move(p); return *this;}
38 
40  destroy();
41  }
42 
44  std::swap(theData,other.theData);
45  }
46 
49  ProxyBase11(ProxyBase11 const & other) = default;
50  ProxyBase11& operator=( const ProxyBase11& other) = default;
51 
52  void reset() { theData.reset();}
53 
54  const T& data() const { check(); return *theData;}
55 
57  check();
58  if ( references() > 1) {
59  theData = theData->clone();
60  }
61  return *theData;
62  }
63 
64  T& sharedData() { check(); return *theData;}
65 
66  bool isValid() const { return bool(theData);}
67 
68  void check() const {
69 #ifdef TR_DEBUG
70  if UNLIKELY(!theData) std::cout << "dead proxyBase11 " << references() << std::endl;
71 #endif
72  }
73 
74  void destroy() noexcept {}
75  int references() const {return theData.use_count();}
76 
77 private:
78  std::shared_ptr<T> theData;
79 };
80 
81 template <class T >
82 inline
84  lh.swap(rh);
85 }
86 
87 #endif // Tracker_ProxyBase11_H
ProxyBase11(std::shared_ptr< U > p)
Definition: ProxyBase11.h:35
void reset()
Definition: ProxyBase11.h:52
#define noexcept
std::shared_ptr< T > theData
Definition: ProxyBase11.h:78
bool int lh
Definition: SIMDVec.h:21
std::shared_ptr< T > pointer
Definition: ProxyBase11.h:27
ProxyBase11 & operator=(std::shared_ptr< U > p)
Definition: ProxyBase11.h:37
const T & data() const
Definition: ProxyBase11.h:54
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ProxyBase11(T *p)
Definition: ProxyBase11.h:33
void swap(ProxyBase11 &other) noexcept
Definition: ProxyBase11.h:43
int references() const
Definition: ProxyBase11.h:75
T & unsharedData()
Definition: ProxyBase11.h:56
T & sharedData()
Definition: ProxyBase11.h:64
~ProxyBase11() noexcept
Definition: ProxyBase11.h:39
void destroy() noexcept
Definition: ProxyBase11.h:74
bool isValid() const
Definition: ProxyBase11.h:66
long double T
void check() const
Definition: ProxyBase11.h:68
def move(src, dest)
Definition: eostools.py:511
#define UNLIKELY(x)