test
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 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 {
31 
32  public:
37 
39  return *this;
40  }
41 
43 
44  // ---------- const member functions ---------------------
45 
46  void addReference() const { referenceCount_++; }
47  void removeReference() const { if(1 == referenceCount_--) {
48  delete const_cast<BasicReferenceCounted*>(this);
49  }
50  }
51 
52  unsigned int references() const {return referenceCount_;}
53  // ---------- static member functions --------------------
54 
55  // ---------- member functions ---------------------------
56 
57  private:
58 
59  // ---------- member data --------------------------------
60  mutable std::atomic<unsigned int> referenceCount_;
61 };
62 
63 template <class T> class ReferenceCountingPointer :
64  public boost::intrusive_ptr<T>
65 {
66  public:
67  ReferenceCountingPointer(T* iT) : boost::intrusive_ptr<T>(iT) {}
69 };
70 
71 template <class T> class ConstReferenceCountingPointer :
72  public boost::intrusive_ptr<const T>
73 {
74  public:
75  ConstReferenceCountingPointer(const T* iT) : boost::intrusive_ptr<const T>(iT) {}
78  boost::intrusive_ptr<const T>(&(*other)) {}
79 };
80 
81 inline void intrusive_ptr_add_ref( const BasicReferenceCounted* iRef ) {
82  iRef->addReference();
83 }
84 
85 inline void intrusive_ptr_release( const BasicReferenceCounted* iRef ) {
86  iRef->removeReference();
87 }
88 
89 // condition uses naive RefCount
91 
92 
94 
96 
97 #endif
void intrusive_ptr_add_ref(const BasicReferenceCounted *iRef)
BasicReferenceCounted & operator=(const BasicReferenceCounted &)
BasicReferenceCounted(const BasicReferenceCounted &)
BasicReferenceCounted ReferenceCounted
BasicReferenceCounted ReferenceCountedInConditions
void removeReference() const
std::atomic< unsigned int > referenceCount_
ConstReferenceCountingPointer(const ReferenceCountingPointer< T > &other)
BasicReferenceCounted ReferenceCountedInEvent
string const
Definition: compareJSON.py:14
unsigned int references() const
void intrusive_ptr_release(const BasicReferenceCounted *iRef)
void addReference() const
BasicReferenceCounted & operator=(BasicReferenceCounted &&)=default
virtual ~BasicReferenceCounted()
ConstReferenceCountingPointer(const T *iT)
long double T