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 #include "ChurnAllocator.h"
9 
20 template <class T>
21 class ProxyBase11 {
22 public:
23 
24  using pointer = std::shared_ptr<T>;
25 
26  // protected:
27 
29 
30  explicit ProxyBase11( T* p) : theData(p) {}
31  template<typename U>
32  ProxyBase11(std::shared_ptr<U> p) : theData(std::move(p)){}
33  template<typename U>
34  ProxyBase11& operator=(std::shared_ptr<U> p) { theData =std::move(p); return *this;}
35 
37  destroy();
38  }
39 
40  void swap(ProxyBase11& other) noexcept {
41  std::swap(theData,other.theData);
42  }
43 
45  ProxyBase11& operator=(ProxyBase11&& other) noexcept = default;
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 { check(); return *theData;}
52 
54  check();
55  if ( references() > 1) {
56  theData = theData->clone();
57  }
58  return *theData;
59  }
60 
61  T& sharedData() { check(); return *theData;}
62 
63  bool isValid() const { return bool(theData);}
64 
65  void check() const {
66 #ifdef TR_DEBUG
67  if unlikely(!theData)
68  throw TrajectoryStateException("Error: uninitialized ProxyBase11 used");
69 #endif
70  }
71 
72  void destroy() noexcept {}
73  int references() const {return theData.use_count();}
74 
75 private:
76  std::shared_ptr<T> theData;
77 };
78 
79 template <class T >
80 inline
82  lh.swap(rh);
83 }
84 
85 #endif // Tracker_ProxyBase11_H
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
ProxyBase11(std::shared_ptr< U > p)
Definition: ProxyBase11.h:32
void reset()
Definition: ProxyBase11.h:49
#define noexcept
std::shared_ptr< T > theData
Definition: ProxyBase11.h:76
bool int lh
Definition: SIMDVec.h:21
std::shared_ptr< T > pointer
Definition: ProxyBase11.h:24
ProxyBase11 & operator=(std::shared_ptr< U > p)
Definition: ProxyBase11.h:34
const T & data() const
Definition: ProxyBase11.h:51
#define unlikely(x)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
def move
Definition: eostools.py:510
ProxyBase11(T *p)
Definition: ProxyBase11.h:30
void swap(ProxyBase11 &other)
Definition: ProxyBase11.h:40
int references() const
Definition: ProxyBase11.h:73
T & unsharedData()
Definition: ProxyBase11.h:53
T & sharedData()
Definition: ProxyBase11.h:61
string const
Definition: compareJSON.py:14
void destroy()
Definition: ProxyBase11.h:72
bool isValid() const
Definition: ProxyBase11.h:63
long double T
void check() const
Definition: ProxyBase11.h:65