Logo ROOT  
Reference Guide
MnRefCountedPointer.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_MnRefCountedPointer
11 #define ROOT_Minuit2_MnRefCountedPointer
12 
13 #include "MnReferenceCounter.h"
14 
15 namespace ROOT {
16 
17  namespace Minuit2 {
18 
19 
20 template<class T> class MnRefCountedPointer {
21 
22 public:
23 
24  // Default constructor needed for use inside array, vector, etc.
25  MnRefCountedPointer() : fPtr(0), fCounter(0) {}
26 
29 
31  fPtr(other.fPtr), fCounter(other.fCounter) {AddReference();}
32 
34  /*
35  if(References() == 0) {
36  if(fPtr) delete fPtr;
37  if(fCounter) delete fCounter;
38  }
39  else RemoveReference();
40  */
41  if(References() != 0) RemoveReference();
42  }
43 
44  bool IsValid() const {return fPtr != 0;}
45 
47  if(this != &other && fPtr != other.fPtr) {
49  fPtr = other.fPtr;
50  fCounter = other.fCounter;
51  AddReference();
52  }
53  return *this;
54  }
55 
57  if(fPtr != ptr) {
58  fPtr = ptr;
60  }
61  return *this;
62  }
63 
64  T* Get() const {return fPtr;}
65 
66  T* operator->() const {DoCheck(); return fPtr;}
67 
68  T& operator*() const {DoCheck(); return *fPtr;}
69 
70  bool operator==(const T* otherP) const {return fPtr == otherP;}
71 
72  bool operator<(const T* otherP) const {return fPtr < otherP;}
73 
74  unsigned int References() const {return fCounter->References();}
75 
76  void AddReference() const {fCounter->AddReference();}
77 
78  void RemoveReference() {
80  if(References() == 0) {
81  delete fPtr; fPtr=0;
82  delete fCounter; fCounter=0;
83  }
84  }
85 
86 private:
87 
88  T* fPtr;
90 
91 private:
92 
93  void DoCheck() const {assert(IsValid());}
94 };
95 
96  } // namespace Minuit2
97 
98 } // namespace ROOT
99 
100 #endif // ROOT_Minuit2_MnRefCountedPointer
ROOT::Minuit2::MnRefCountedPointer::RemoveReference
void RemoveReference()
Definition: MnRefCountedPointer.h:90
ROOT::Minuit2::MnRefCountedPointer::DoCheck
void DoCheck() const
Definition: MnRefCountedPointer.h:105
ROOT::Minuit2::MnRefCountedPointer::IsValid
bool IsValid() const
Definition: MnRefCountedPointer.h:56
ROOT::Minuit2::MnReferenceCounter::RemoveReference
void RemoveReference() const
Definition: MnReferenceCounter.h:64
ROOT::Minuit2::MnRefCountedPointer::References
unsigned int References() const
Definition: MnRefCountedPointer.h:86
ROOT::Minuit2::MnRefCountedPointer::operator*
T & operator*() const
Definition: MnRefCountedPointer.h:80
ROOT::Minuit2::MnRefCountedPointer::~MnRefCountedPointer
~MnRefCountedPointer()
Definition: MnRefCountedPointer.h:45
ROOT::Minuit2::MnRefCountedPointer::operator<
bool operator<(const T *otherP) const
Definition: MnRefCountedPointer.h:84
ROOT::Minuit2::MnRefCountedPointer::fPtr
T * fPtr
Definition: MnRefCountedPointer.h:100
ROOT::Minuit2::MnRefCountedPointer::fCounter
MnReferenceCounter * fCounter
Definition: MnRefCountedPointer.h:101
MnReferenceCounter.h
ROOT::Minuit2::MnRefCountedPointer
Definition: MnRefCountedPointer.h:28
ROOT::Minuit2::MnRefCountedPointer::operator=
MnRefCountedPointer & operator=(const MnRefCountedPointer< T > &other)
Definition: MnRefCountedPointer.h:58
ROOT::Minuit2::MnRefCountedPointer::operator->
T * operator->() const
Definition: MnRefCountedPointer.h:78
ROOT::Minuit2::MnReferenceCounter::AddReference
void AddReference() const
Definition: MnReferenceCounter.h:62
ROOT::Minuit2::MnRefCountedPointer::MnRefCountedPointer
MnRefCountedPointer()
Definition: MnRefCountedPointer.h:37
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:52
ROOT::Minuit2::MnReferenceCounter
Definition: MnReferenceCounter.h:32
ROOT::Minuit2::MnRefCountedPointer::AddReference
void AddReference() const
Definition: MnRefCountedPointer.h:88
ROOT::Minuit2::MnRefCountedPointer::Get
T * Get() const
Definition: MnRefCountedPointer.h:76
ROOT::Minuit2::MnReferenceCounter::References
unsigned int References() const
Definition: MnReferenceCounter.h:60
pt
TPaveText * pt
Definition: entrylist_figure1.C:7
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Minuit2::MnRefCountedPointer::operator==
bool operator==(const T *otherP) const
Definition: MnRefCountedPointer.h:82