Logo ROOT   6.08/07
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.
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
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
double T(double x)
Definition: ChebyshevPol.h:34
MnRefCountedPointer(const MnRefCountedPointer< T > &other)
TPaveText * pt
MnRefCountedPointer & operator=(T *ptr)
bool operator<(const T *otherP) const
bool operator==(const T *otherP) const
MnRefCountedPointer & operator=(const MnRefCountedPointer< T > &other)