CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
27  ProxyBase( const ProxyBase& other) noexcept {
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 
46  void swap(ProxyBase& other) noexcept {
47  std::swap(theData,other.theData);
48  }
49 
50 
51 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
52  ProxyBase(ProxyBase&& other) noexcept {
53  theData = other.theData;
54  other.theData=0;
55  }
56 
58  if likely( theData != other.theData) {
59  destroy();
60  theData = other.theData;
61  other.theData=0;
62  }
63  return *this;
64  }
65 #endif
66 
67  const T& data() const { check(); return *theData;}
68 
70  check();
71  if ( references() > 1) {
72  theData->removeReference();
73  theData = Cloner().clone( *theData);
74  if (theData) theData->addReference();
75  }
76  return *theData;
77  }
78 
79  T& sharedData() { check(); return *theData;}
80 
81  bool isValid() const { return theData != 0;}
82 
83  void check() const {
84  if unlikely(theData == 0)
85  throw TrajectoryStateException("Error: uninitialized ProxyBase used");
86  }
87 
88  void destroy() noexcept { if likely(isValid()) theData->removeReference();}
89 
90  int references() const {return theData->references();}
91 
92 private:
94 };
95 
96 template <class T, class Cloner >
97 inline
99  lh.swap(rh);
100 }
101 
102 #endif // Tracker_ProxyBase_H
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
void destroy()
Definition: ProxyBase.h:88
ProxyBase()
Definition: ProxyBase.h:23
~ProxyBase()
Definition: ProxyBase.h:32
int references() const
Definition: ProxyBase.h:90
#define noexcept
bool int lh
Definition: SIMDVec.h:21
T & unsharedData()
Definition: ProxyBase.h:69
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:83
ProxyBase(T *p)
Definition: ProxyBase.h:25
const T & data() const
Definition: ProxyBase.h:67
bool isValid() const
Definition: ProxyBase.h:81
ProxyBase & operator=(const ProxyBase &other)
Definition: ProxyBase.h:36
ProxyBase(const ProxyBase &other)
Definition: ProxyBase.h:27
long double T
T * theData
Definition: ProxyBase.h:93
T & sharedData()
Definition: ProxyBase.h:79