CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 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) {}
71  ConstReferenceCountingPointer(const ReferenceCountingPointer<T>& other) : boost::intrusive_ptr<const T>(&(*other)) {}
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
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
unsigned int references() const
void intrusive_ptr_release(const BasicReferenceCounted *iRef)
void addReference() const
BasicReferenceCounted(BasicReferenceCounted &&)
virtual ~BasicReferenceCounted()
BasicReferenceCounted & operator=(BasicReferenceCounted &&)
ConstReferenceCountingPointer(const T *iT)
long double T