CMS 3D CMS Logo

ReferenceCounted.h
Go to the documentation of this file.
1 #ifndef DataFormats_GeometrySurface_ReferenceCounted_h
2 #define DataFormats_GeometrySurface_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 //
20 
21 // system include files
22 #include "boost/intrusive_ptr.hpp"
23 #include <atomic>
24 
25 // user include files
26 
27 // forward declarations
28 
30 public:
35 
37 
39 
40  // ---------- const member functions ---------------------
41 
42  void addReference() const { referenceCount_++; }
43  void removeReference() const {
44  if (1 == referenceCount_--) {
45  delete const_cast<BasicReferenceCounted*>(this);
46  }
47  }
48 
49  unsigned int references() const { return referenceCount_; }
50  // ---------- static member functions --------------------
51 
52  // ---------- member functions ---------------------------
53 
54 private:
55  // ---------- member data --------------------------------
56  mutable std::atomic<unsigned int> referenceCount_;
57 };
58 
59 template <class T>
60 class ReferenceCountingPointer : public boost::intrusive_ptr<T> {
61 public:
62  ReferenceCountingPointer(T* iT) : boost::intrusive_ptr<T>(iT) {}
64 };
65 
66 template <class T>
67 class ConstReferenceCountingPointer : public boost::intrusive_ptr<const T> {
68 public:
69  ConstReferenceCountingPointer(const T* iT) : boost::intrusive_ptr<const T>(iT) {}
72 };
73 
74 inline void intrusive_ptr_add_ref(const BasicReferenceCounted* iRef) { iRef->addReference(); }
75 
76 inline void intrusive_ptr_release(const BasicReferenceCounted* iRef) { iRef->removeReference(); }
77 
78 // condition uses naive RefCount
80 
82 
84 
85 #endif
BasicReferenceCounted
Definition: ReferenceCounted.h:29
ReferenceCountingPointer::ReferenceCountingPointer
ReferenceCountingPointer()
Definition: ReferenceCounted.h:63
ReferenceCounted
BasicReferenceCounted ReferenceCounted
Definition: ReferenceCounted.h:83
BasicReferenceCounted::references
unsigned int references() const
Definition: ReferenceCounted.h:49
ConstReferenceCountingPointer::ConstReferenceCountingPointer
ConstReferenceCountingPointer(const T *iT)
Definition: ReferenceCounted.h:69
ConstReferenceCountingPointer
Definition: ReferenceCounted.h:67
ReferenceCountedInConditions
BasicReferenceCounted ReferenceCountedInConditions
Definition: ReferenceCounted.h:79
ReferenceCountingPointer::ReferenceCountingPointer
ReferenceCountingPointer(T *iT)
Definition: ReferenceCounted.h:62
ReferenceCountingPointer
Definition: ReferenceCounted.h:60
BasicReferenceCounted::BasicReferenceCounted
BasicReferenceCounted(BasicReferenceCounted &&)
Definition: ReferenceCounted.h:33
boost
Definition: CLHEP.h:16
watchdog.const
const
Definition: watchdog.py:83
BasicReferenceCounted::operator=
BasicReferenceCounted & operator=(const BasicReferenceCounted &)
Definition: ReferenceCounted.h:36
BasicReferenceCounted::BasicReferenceCounted
BasicReferenceCounted()
Definition: ReferenceCounted.h:31
trackingPlots.other
other
Definition: trackingPlots.py:1467
BasicReferenceCounted::addReference
void addReference() const
Definition: ReferenceCounted.h:42
BasicReferenceCounted::referenceCount_
std::atomic< unsigned int > referenceCount_
Definition: ReferenceCounted.h:56
BasicReferenceCounted::removeReference
void removeReference() const
Definition: ReferenceCounted.h:43
intrusive_ptr_add_ref
void intrusive_ptr_add_ref(const BasicReferenceCounted *iRef)
Definition: ReferenceCounted.h:74
T
long double T
Definition: Basic3DVectorLD.h:48
BasicReferenceCounted::~BasicReferenceCounted
virtual ~BasicReferenceCounted()
Definition: ReferenceCounted.h:38
ConstReferenceCountingPointer::ConstReferenceCountingPointer
ConstReferenceCountingPointer(const ReferenceCountingPointer< T > &other)
Definition: ReferenceCounted.h:71
intrusive_ptr_release
void intrusive_ptr_release(const BasicReferenceCounted *iRef)
Definition: ReferenceCounted.h:76
ReferenceCountedInEvent
BasicReferenceCounted ReferenceCountedInEvent
Definition: ReferenceCounted.h:81
ConstReferenceCountingPointer::ConstReferenceCountingPointer
ConstReferenceCountingPointer()
Definition: ReferenceCounted.h:70
BasicReferenceCounted::BasicReferenceCounted
BasicReferenceCounted(const BasicReferenceCounted &)
Definition: ReferenceCounted.h:32
BasicReferenceCounted::operator=
BasicReferenceCounted & operator=(BasicReferenceCounted &&)
Definition: ReferenceCounted.h:34