Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-16 09:54:45

0001 // @(#)root/minuit2:$Id$
0002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
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 // extern StackAllocator gStackAllocator;
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 /*nbytes */) { 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 } // namespace Minuit2
0053 
0054 } // namespace ROOT
0055 
0056 #endif // ROOT_Minuit2_MnReferenceCounter