Logo ROOT  
Reference Guide
MnReferenceCounter.h
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 #ifndef ROOT_Minuit2_MnReferenceCounter
11 #define ROOT_Minuit2_MnReferenceCounter
12 
13 #include <cassert>
14 
15 #include "StackAllocator.h"
16 
17 namespace ROOT {
18 
19  namespace Minuit2 {
20 
21 
22 //extern StackAllocator gStackAllocator;
23 
24 class MnReferenceCounter {
25 
26 public:
27 
29 
31  fReferences(other.fReferences) {}
32 
34  fReferences = other.fReferences;
35  return *this;
36  }
37 
38  ~MnReferenceCounter() {assert(fReferences == 0);}
39 
40  void* operator new(size_t nbytes) {
41  return StackAllocatorHolder::Get().Allocate(nbytes);
42  }
43 
44  void operator delete(void* p, size_t /*nbytes */) {
46  }
47 
48  unsigned int References() const {return fReferences;}
49 
50  void AddReference() const {fReferences++;}
51 
52  void RemoveReference() const {fReferences--;}
53 
54 private:
55 
56  mutable unsigned int fReferences;
57 };
58 
59  } // namespace Minuit2
60 
61 } // namespace ROOT
62 
63 #endif // ROOT_Minuit2_MnReferenceCounter
ROOT::Minuit2::MnReferenceCounter::operator=
MnReferenceCounter & operator=(const MnReferenceCounter &other)
Definition: MnReferenceCounter.h:45
ROOT::Minuit2::StackAllocator::Deallocate
void Deallocate(void *p)
Definition: StackAllocator.h:112
ROOT::Minuit2::MnReferenceCounter::RemoveReference
void RemoveReference() const
Definition: MnReferenceCounter.h:64
ROOT::Minuit2::MnReferenceCounter::MnReferenceCounter
MnReferenceCounter()
Definition: MnReferenceCounter.h:40
StackAllocator.h
ROOT::Minuit2::StackAllocator::Allocate
void * Allocate(size_t nBytes)
Definition: StackAllocator.h:83
ROOT::Minuit2::MnReferenceCounter::fReferences
unsigned int fReferences
Definition: MnReferenceCounter.h:68
ROOT::Minuit2::StackAllocatorHolder::Get
static StackAllocator & Get()
Definition: StackAllocator.h:232
ROOT::Minuit2::MnReferenceCounter::AddReference
void AddReference() const
Definition: MnReferenceCounter.h:62
ROOT::Minuit2::MnReferenceCounter
Definition: MnReferenceCounter.h:32
ROOT::Minuit2::MnReferenceCounter::References
unsigned int References() const
Definition: MnReferenceCounter.h:60
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Minuit2::MnReferenceCounter::~MnReferenceCounter
~MnReferenceCounter()
Definition: MnReferenceCounter.h:50