Logo ROOT   6.12/07
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 
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
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
MnReferenceCounter(const MnReferenceCounter &other)
void * Allocate(size_t nBytes)
MnReferenceCounter & operator=(const MnReferenceCounter &other)
static StackAllocator & Get()