CMS 3D CMS Logo

ProxyBase.h
Go to the documentation of this file.
1 #ifndef Tracker_ProxyBase_H
2 #define Tracker_ProxyBase_H
3 
9 
19 template <class T, class Cloner >
20 class ProxyBase {
21 protected:
22 
24 
25  explicit ProxyBase( T* p) noexcept : theData(p) {if (theData) theData->addReference();}
26 
28  theData = other.theData;
29  if (theData) theData->addReference();
30  }
31 
33  destroy();
34  }
35 
37  if likely( theData != other.theData) {
38  destroy();
39  theData = other.theData;
40  if (theData) theData->addReference();
41  }
42  return *this;
43  }
44 
45 
47  std::swap(theData,other.theData);
48  }
49 
50 
52  theData = other.theData;
53  other.theData=0;
54  }
55 
57  if likely( theData != other.theData) {
58  destroy();
59  theData = other.theData;
60  other.theData=0;
61  }
62  return *this;
63  }
64 
65  const T& data() const { check(); return *theData;}
66 
68  check();
69  if ( references() > 1) {
70  theData->removeReference();
71  theData = Cloner().clone( *theData);
72  if (theData) theData->addReference();
73  }
74  return *theData;
75  }
76 
77  T& sharedData() { check(); return *theData;}
78 
79  bool isValid() const { return theData != 0;}
80 
81  void check() const {
82  if unlikely(theData == 0)
83  throw TrajectoryStateException("Error: uninitialized ProxyBase used");
84  }
85 
86  void destroy() noexcept { if likely(isValid()) theData->removeReference();}
87 
88  int references() const {return theData->references();}
89 
90 private:
92 };
93 
94 template <class T, class Cloner >
95 inline
97  lh.swap(rh);
98 }
99 
100 #endif // Tracker_ProxyBase_H
void destroy()
Definition: ProxyBase.h:86
ProxyBase()
Definition: ProxyBase.h:23
~ProxyBase()
Definition: ProxyBase.h:32
int references() const
Definition: ProxyBase.h:88
#define noexcept
bool int lh
Definition: SIMDVec.h:21
T & unsharedData()
Definition: ProxyBase.h:67
void swap(ProxyBase &other)
Definition: ProxyBase.h:46
#define unlikely(x)
#define likely(x)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void check() const
Definition: ProxyBase.h:81
ProxyBase & operator=(ProxyBase &&other)
Definition: ProxyBase.h:56
ProxyBase(T *p)
Definition: ProxyBase.h:25
const T & data() const
Definition: ProxyBase.h:65
bool isValid() const
Definition: ProxyBase.h:79
ProxyBase & operator=(const ProxyBase &other)
Definition: ProxyBase.h:36
ProxyBase(ProxyBase &&other)
Definition: ProxyBase.h:51
ProxyBase(const ProxyBase &other)
Definition: ProxyBase.h:27
long double T
T * theData
Definition: ProxyBase.h:91
T & sharedData()
Definition: ProxyBase.h:77