Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
28  MnReferenceCounter() : fReferences(0) {}
29 
30  MnReferenceCounter(const MnReferenceCounter& other) :
31  fReferences(other.fReferences) {}
32 
33  MnReferenceCounter& operator=(const MnReferenceCounter& other) {
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 */) {
45  StackAllocatorHolder::Get().Deallocate(p);
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