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 template <class T>
21 
22 public:
23  // Default constructor needed for use inside array, vector, etc.
25 
27 
29  {
30  AddReference();
31  }
32 
34  {
35  /*
36  if(References() == 0) {
37  if(fPtr) delete fPtr;
38  if(fCounter) delete fCounter;
39  }
40  else RemoveReference();
41  */
42  if (References() != 0)
44  }
45 
46  bool IsValid() const { return fPtr != 0; }
47 
49  {
50  if (this != &other && fPtr != other.fPtr) {
52  fPtr = other.fPtr;
53  fCounter = other.fCounter;
54  AddReference();
55  }
56  return *this;
57  }
58 
60  {
61  if (fPtr != ptr) {
62  fPtr = ptr;
64  }
65  return *this;
66  }
67 
68  T *Get() const { return fPtr; }
69 
70  T *operator->() const
71  {
72  DoCheck();
73  return fPtr;
74  }
75 
76  T &operator*() const
77  {
78  DoCheck();
79  return *fPtr;
80  }
81 
82  bool operator==(const T *otherP) const { return fPtr == otherP; }
83 
84  bool operator<(const T *otherP) const { return fPtr < otherP; }
85 
86  unsigned int References() const { return fCounter->References(); }
87 
88  void AddReference() const { fCounter->AddReference(); }
89 
91  {
93  if (References() == 0) {
94  delete fPtr;
95  fPtr = 0;
96  delete fCounter;
97  fCounter = 0;
98  }
99  }
100 
101 private:
102  T *fPtr;
104 
105 private:
106  void DoCheck() const { assert(IsValid()); }
107 };
108 
109 } // namespace Minuit2
110 
111 } // namespace ROOT
112 
113 #endif // ROOT_Minuit2_MnRefCountedPointer
ROOT::Minuit2::MnRefCountedPointer::MnRefCountedPointer
MnRefCountedPointer(const MnRefCountedPointer< T > &other)
Definition: MnRefCountedPointer.h:28
ROOT::Minuit2::MnRefCountedPointer::RemoveReference
void RemoveReference()
Definition: MnRefCountedPointer.h:90
ROOT::Minuit2::MnRefCountedPointer::DoCheck
void DoCheck() const
Definition: MnRefCountedPointer.h:106
ROOT::Minuit2::MnRefCountedPointer::IsValid
bool IsValid() const
Definition: MnRefCountedPointer.h:46
ROOT::Minuit2::MnReferenceCounter::RemoveReference
void RemoveReference() const
Definition: MnReferenceCounter.h:46
ROOT::Minuit2::MnRefCountedPointer::References
unsigned int References() const
Definition: MnRefCountedPointer.h:86
ROOT::Minuit2::MnRefCountedPointer::operator*
T & operator*() const
Definition: MnRefCountedPointer.h:76
ROOT::Minuit2::MnRefCountedPointer::~MnRefCountedPointer
~MnRefCountedPointer()
Definition: MnRefCountedPointer.h:33
ROOT::Minuit2::MnRefCountedPointer::operator<
bool operator<(const T *otherP) const
Definition: MnRefCountedPointer.h:84
ROOT::Minuit2::MnRefCountedPointer::fPtr
T * fPtr
Definition: MnRefCountedPointer.h:102
ROOT::Minuit2::MnRefCountedPointer::fCounter
MnReferenceCounter * fCounter
Definition: MnRefCountedPointer.h:103
ROOT::Minuit2::MnRefCountedPointer::operator=
MnRefCountedPointer & operator=(T *ptr)
Definition: MnRefCountedPointer.h:59
MnReferenceCounter.h
ROOT::Minuit2::MnRefCountedPointer
Definition: MnRefCountedPointer.h:20
ROOT::Minuit2::MnRefCountedPointer::operator=
MnRefCountedPointer & operator=(const MnRefCountedPointer< T > &other)
Definition: MnRefCountedPointer.h:48
ROOT::Minuit2::MnRefCountedPointer::MnRefCountedPointer
MnRefCountedPointer(T *pt)
Definition: MnRefCountedPointer.h:26
ROOT::Minuit2::MnRefCountedPointer::operator->
T * operator->() const
Definition: MnRefCountedPointer.h:70
ROOT::Minuit2::MnReferenceCounter::AddReference
void AddReference() const
Definition: MnReferenceCounter.h:44
ROOT::Minuit2::MnRefCountedPointer::MnRefCountedPointer
MnRefCountedPointer()
Definition: MnRefCountedPointer.h:24
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
ROOT::Minuit2::MnReferenceCounter
Definition: MnReferenceCounter.h:23
ROOT::Minuit2::MnRefCountedPointer::AddReference
void AddReference() const
Definition: MnRefCountedPointer.h:88
ROOT::Minuit2::MnRefCountedPointer::Get
T * Get() const
Definition: MnRefCountedPointer.h:68
ROOT::Minuit2::MnReferenceCounter::References
unsigned int References() const
Definition: MnReferenceCounter.h:42
pt
TPaveText * pt
Definition: entrylist_figure1.C:7
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::MnRefCountedPointer::operator==
bool operator==(const T *otherP) const
Definition: MnRefCountedPointer.h:82