thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
ReferenceCounted.h
1 // -*- C++ -*-
2 //
3 // ReferenceCounted.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ThePEG_ReferenceCounted_H
10 #define ThePEG_ReferenceCounted_H
11 // This is the declaration of the ReferenceCounted class.
12 
13 
14 #include "RCPtr.fh"
15 #include "ThePEG/Persistency/PersistentIStream.fh"
16 
17 namespace ThePEG {
18 namespace Pointer {
19 
31 
33  friend class RCPtrBase;
34  friend class ThePEG::PersistentIStream;
35 
36 public:
37 
41  typedef unsigned int CounterType;
42 
43 protected:
44 
51  : uniqueId(++objectCounter),
52  theReferenceCounter(CounterType(1)) {}
53 
58  : uniqueId(++objectCounter),
59  theReferenceCounter(CounterType(1)) {}
60 
65  {
66  return *this;
67  }
68 
70 
71 public:
72 
76  CounterType referenceCount() const
77  {
78  return theReferenceCounter;
79  }
80 
81 private:
82 
87  {
89  }
90 
95  {
96  return !--theReferenceCounter;
97  }
98 
99 public:
100 
104  const unsigned long uniqueId;
105 
106 private:
107 
112  static unsigned long objectCounter;
113 
117  mutable CounterType theReferenceCounter;
118 
119 };
120 
121 
122 }
123 }
124 
125 #endif /* ThePEG_ReferenceCounted_H */
126 
PersistentIStream is used to read persistent objects from a stream where they were previously written...
bool decrementReferenceCount() const
Decrement with the reference count.
const unsigned long uniqueId
The unique ID.
ReferenceCounted()
Default constructor.
CounterType referenceCount() const
Return the reference count.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
ReferenceCounted & operator=(const ReferenceCounted &)
Assignment.
ReferenceCounted(const ReferenceCounted &)
Copy-constructor.
RCPtrBase is the base class of RCPtr and ConstRCPtr which are reference counted (smart) pointers...
Definition: RCPtr.h:30
unsigned int CounterType
The integer type used for counting.
ReferenceCounted must be the (virtual) base class of all classes which may be pointed to by the RCPtr...
CounterType theReferenceCounter
The reference count.
void incrementReferenceCount() const
Increment the reference count.
static unsigned long objectCounter
A counter for issuing unique IDs.