Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TFitResultPtr.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: David Gonzalez Maline 12/11/09
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TFitResultPtr.h"
13#include "TFitResult.h"
14#include "TError.h"
15
16/** \class TFitResultPtr
17Provides an indirection to the TFitResult class and with a semantics
18identical to a TFitResult pointer, i.e. it is like a smart pointer to a TFitResult.
19In addition it provides an automatic conversion to an integer. In this way it can be
20returned from the TH1::Fit method and the change in TH1::Fit be backward compatible.
21 */
22
24
25////////////////////////////////////////////////////////////////////////////////
26/// Constructor from a TFitResult pointer
27
28TFitResultPtr::TFitResultPtr(const std::shared_ptr<TFitResult> & p) :
29 fStatus(-1),
30 fPointer(p)
31{
32 if (fPointer) fStatus = fPointer->Status();
33}
34
35////////////////////////////////////////////////////////////////////////////////
36/// Constructor from a TFitResult pointer
37
39 fStatus(-1),
40 fPointer(std::shared_ptr<TFitResult>(p))
41{
42 if (fPointer) fStatus = fPointer->Status();
43}
44
46 fStatus(rhs.fStatus), fPointer(rhs.fPointer)
47{
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Destructor. Delete the contained TFitResult pointer if needed
52/// if ( fPointer != 0)
53/// delete fPointer;
54
56{
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Implement the de-reference operator to make the class acts as a pointer to a TFitResult
61/// assert in case the class does not contain a pointer to TFitResult
62
64{
65 if (!fPointer) {
66 Error("TFitResultPtr","TFitResult is empty - use the fit option S");
67 }
68 return *fPointer;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Implement the -> operator to make the class acts as a pointer to a TFitResult.
73/// assert in case the class does not contain a pointer to TFitResult
74
76{
77 if (!fPointer) {
78 Error("TFitResultPtr","TFitResult is empty - use the fit option S");
79 }
80 return fPointer.get();
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Return contained pointer
85
87 return fPointer.get();
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Assignment operator.
92/// if needed copy the TFitResult object and delete previous one if existing
93
95{
96 if ( &rhs == this) return *this; // self assignment
97 fStatus = rhs.fStatus;
98 fPointer = rhs.fPointer;
99 // if ( fPointer ) delete fPointer;
100 // fPointer = 0;
101 // if (rhs.fPointer != 0) fPointer = new TFitResult(*rhs);
102 return *this;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Print the TFitResultPtr by printing its TFitResult.
107
108std::string cling::printValue(const TFitResultPtr* val) {
109 if (TFitResult* fr = val->Get())
110 return printValue(fr);
111 return "<nullptr TFitResult>";
112}
#define ClassImp(name)
Definition Rtypes.h:377
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:197
winID h TVirtualViewer3D TVirtualGLPainter p
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
virtual ~TFitResultPtr()
Destructor.
TFitResult * Get() const
Return contained pointer.
std::shared_ptr< TFitResult > fPointer
! Smart Pointer to TFitResult class
int fStatus
fit status code
TFitResult & operator*() const
Implement the de-reference operator to make the class acts as a pointer to a TFitResult assert in cas...
TFitResult * operator->() const
Implement the -> operator to make the class acts as a pointer to a TFitResult.
TFitResultPtr & operator=(const TFitResultPtr &rhs)
Assignment operator.
TFitResultPtr(int status=-1)
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O.
Definition TFitResult.h:34