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 
6 
16 template <class T, class Cloner >
17 class ProxyBase {
18 public:
19 
20  ProxyBase() : theData(0) {}
21 
22  ProxyBase( T* p) : theData(p) {if (theData) theData->addReference();}
23 
24  ProxyBase( const ProxyBase& other) {
25  theData = other.theData;
26  if (theData) theData->addReference();
27  }
28 
29  virtual ~ProxyBase() {
30  destroy();
31  }
32 
33  ProxyBase& operator=( const ProxyBase& other) {
34  if ( theData != other.theData) {
35  destroy();
36  theData = other.theData;
37  if (theData) theData->addReference();
38  }
39  return *this;
40  }
41 
42 
43  void swap(ProxyBase& other) {
44  std::swap(theData,other.theData);
45  }
46 
47 
48 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
49  ProxyBase(ProxyBase&& other) {
50  theData = other.theData;
51  other.theData=0;
52  }
53 
54  ProxyBase& operator=(ProxyBase&& other) {
55  if ( theData != other.theData) {
56  destroy();
57  theData = other.theData;
58  other.theData=0;
59  }
60  return *this;
61  }
62 #endif
63 
64  const T& data() const { check(); return *theData;}
65 
67  check();
68  if ( references() > 1) {
69  theData->removeReference();
70  theData = Cloner().clone( *theData);
71  if (theData) theData->addReference();
72  }
73  return *theData;
74  }
75 
76  T& sharedData() { check(); return *theData;}
77 
78  bool isValid() const { return theData != 0;}
79 
80  void check() const {
81  if (theData == 0)
82  throw TrajectoryStateException("Error: uninitialized ProxyBase used");
83  }
84 
85  void destroy() { if (isValid()) theData->removeReference();}
86 
87  int references() const {return theData->references();}
88 
89 private:
91 };
92 
93 template <class T, class Cloner >
94 inline
96  lh.swap(rh);
97 }
98 
99 #endif // Tracker_ProxyBase_H
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:74
void destroy()
Definition: ProxyBase.h:85
ProxyBase()
Definition: ProxyBase.h:20
int references() const
Definition: ProxyBase.h:87
virtual ~ProxyBase()
Definition: ProxyBase.h:29
bool int lh
Definition: SSEVec.h:37
T & unsharedData()
Definition: ProxyBase.h:66
void swap(ProxyBase &other)
Definition: ProxyBase.h:43
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void check() const
Definition: ProxyBase.h:80
ProxyBase(T *p)
Definition: ProxyBase.h:22
const T & data() const
Definition: ProxyBase.h:64
bool isValid() const
Definition: ProxyBase.h:78
ProxyBase & operator=(const ProxyBase &other)
Definition: ProxyBase.h:33
ProxyBase(const ProxyBase &other)
Definition: ProxyBase.h:24
long double T
T * theData
Definition: ProxyBase.h:90
T & sharedData()
Definition: ProxyBase.h:76