CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ReferenceCounted.h
Go to the documentation of this file.
1 #ifndef SURFACE_REFERENCECOUNTED_H
2 #define SURFACE_REFERENCECOUNTED_H
3 // -*- C++ -*-
4 //
5 // Package: Surface
6 // Class : ReferenceCounted
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Fri Jul 15 09:17:20 EDT 2005
19 // $Id: ReferenceCounted.h,v 1.11 2010/12/16 13:59:22 innocent Exp $
20 //
21 
22 // system include files
23 #include "boost/intrusive_ptr.hpp"
24 
25 // user include files
26 
27 // forward declarations
28 
30 {
31 
32  public:
35 
37  return *this;
38  }
40 
41  // ---------- const member functions ---------------------
42 
43  void addReference() const { ++referenceCount_ ; }
44  void removeReference() const { if( 0 == --referenceCount_ ) {
45  delete const_cast<BasicReferenceCounted*>(this);
46  }
47  }
48 
49  unsigned int references() const {return referenceCount_;}
50 
51  // ---------- static member functions --------------------
52 
53  // ---------- member functions ---------------------------
54 
55  private:
56 
57  // ---------- member data --------------------------------
58  mutable unsigned int referenceCount_;
59 };
60 
61 template <class T> class ReferenceCountingPointer :
62  public boost::intrusive_ptr<T>
63 {
64  public:
65  ReferenceCountingPointer(T* iT) : boost::intrusive_ptr<T>(iT) {}
67 };
68 
69 template <class T> class ConstReferenceCountingPointer :
70  public boost::intrusive_ptr<const T>
71 {
72  public:
73  ConstReferenceCountingPointer(const T* iT) : boost::intrusive_ptr<const T>(iT) {}
76  boost::intrusive_ptr<const T>(&(*other)) {}
77 };
78 
79 inline void intrusive_ptr_add_ref( const BasicReferenceCounted* iRef ) {
80  iRef->addReference();
81 }
82 
83 inline void intrusive_ptr_release( const BasicReferenceCounted* iRef ) {
84  iRef->removeReference();
85 }
86 
87 
88 #define CMSSW_POOLALLOCATOR
89 
90 #ifdef CMSSW_POOLALLOCATOR
92 #else
93 template<typename T>
94 struct LocalCache {
95  std::auto_ptr<T> ptr;
96 };
97 
98 #endif
99 
101 #ifdef CMSSW_POOLALLOCATOR
102  : public BlockWipedPoolAllocated
103 #endif
104 {
105 
106 public:
107  static int s_alive;
108  static int s_referenced;
109 
111  s_alive++;
112  }
113 
115  s_alive++;
116  }
117 
119  return *this;
120  }
121 
123  s_alive--;
124  }
125 
126  // ---------- const member functions ---------------------
127 
128  void addReference() const { ++referenceCount_ ; s_referenced++; }
129  void removeReference() const {
130  s_referenced--;
131  if( 0 == --referenceCount_ ) {
132  delete const_cast<ReferenceCountedPoolAllocated*>(this);
133  }
134  }
135 
136  unsigned int references() const {return referenceCount_;}
137 
138  // ---------- static member functions --------------------
139 
140  // ---------- member functions ---------------------------
141 
142  private:
143 
144  // ---------- member data --------------------------------
145  mutable unsigned int referenceCount_;
146 };
147 
149  iRef->addReference();
150 }
151 
153  iRef->removeReference();
154 }
155 
156 // condition uses naive RefCount
158 
159 
160 // transient objects in algo and events are "poo allocated"
162 
163 // just to avoid changing all around
164 // typedef ReferenceCountedPoolAllocated ReferenceCounted;
166 
167 
168 
169 #endif /* SURFACE_REFERENCECOUNTED_H */
ReferenceCountedPoolAllocated ReferenceCountedInEvent
void intrusive_ptr_add_ref(const BasicReferenceCounted *iRef)
#define CMSSW_POOLALLOCATOR
BasicReferenceCounted(const BasicReferenceCounted &iRHS)
const BasicReferenceCounted & operator=(const BasicReferenceCounted &)
BasicReferenceCounted ReferenceCounted
BasicReferenceCounted ReferenceCountedInConditions
unsigned int references() const
ReferenceCountedPoolAllocated(const ReferenceCountedPoolAllocated &iRHS)
const ReferenceCountedPoolAllocated & operator=(const ReferenceCountedPoolAllocated &)
void removeReference() const
ConstReferenceCountingPointer(const ReferenceCountingPointer< T > &other)
string const
Definition: compareJSON.py:14
unsigned int references() const
void intrusive_ptr_release(const BasicReferenceCounted *iRef)
void addReference() const
unsigned int referenceCount_
virtual ~BasicReferenceCounted()
ConstReferenceCountingPointer(const T *iT)
long double T
std::auto_ptr< T > ptr