File indexing completed on 2024-11-16 09:54:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef ROOT_Minuit2_MnReferenceCounter
0011 #define ROOT_Minuit2_MnReferenceCounter
0012
0013 #include <cassert>
0014
0015 #include "StackAllocator.h"
0016
0017 namespace ROOT {
0018
0019 namespace Minuit2 {
0020
0021
0022
0023 class MnReferenceCounter {
0024
0025 public:
0026 MnReferenceCounter() : fReferences(0) {}
0027
0028 MnReferenceCounter(const MnReferenceCounter &other) : fReferences(other.fReferences) {}
0029
0030 MnReferenceCounter &operator=(const MnReferenceCounter &other)
0031 {
0032 fReferences = other.fReferences;
0033 return *this;
0034 }
0035
0036 ~MnReferenceCounter() { assert(fReferences == 0); }
0037
0038 void *operator new(size_t nbytes) { return StackAllocatorHolder::Get().Allocate(nbytes); }
0039
0040 void operator delete(void *p, size_t ) { StackAllocatorHolder::Get().Deallocate(p); }
0041
0042 unsigned int References() const { return fReferences; }
0043
0044 void AddReference() const { fReferences++; }
0045
0046 void RemoveReference() const { fReferences--; }
0047
0048 private:
0049 mutable unsigned int fReferences;
0050 };
0051
0052 }
0053
0054 }
0055
0056 #endif