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
23
24////////////////////////////////////////////////////////////////////////////////
25/// Constructor from a TFitResult pointer
26
27TFitResultPtr::TFitResultPtr(const std::shared_ptr<TFitResult> & p) :
28 fStatus(-1),
29 fPointer(p)
30{
31 if (fPointer) fStatus = fPointer->Status();
32}
33
34////////////////////////////////////////////////////////////////////////////////
35/// Constructor from a TFitResult pointer
36
38 fStatus(-1),
39 fPointer(std::shared_ptr<TFitResult>(p))
40{
41 if (fPointer) fStatus = fPointer->Status();
42}
43
45 fStatus(rhs.fStatus), fPointer(rhs.fPointer)
46{
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Destructor. Delete the contained TFitResult pointer if needed
51/// if ( fPointer != 0)
52/// delete fPointer;
53
57
58////////////////////////////////////////////////////////////////////////////////
59/// Implement the de-reference operator to make the class acts as a pointer to a TFitResult
60/// assert in case the class does not contain a pointer to TFitResult
61
63{
64 if (!fPointer) {
65 Error("TFitResultPtr","TFitResult is empty - use the fit option S");
66 }
67 return *fPointer;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Implement the -> operator to make the class acts as a pointer to a TFitResult.
72/// assert in case the class does not contain a pointer to TFitResult
73
75{
76 if (!fPointer) {
77 Error("TFitResultPtr","TFitResult is empty - use the fit option S");
78 }
79 return fPointer.get();
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Return contained pointer
84
86 return fPointer.get();
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Assignment operator.
91/// if needed copy the TFitResult object and delete previous one if existing
92
94{
95 if ( &rhs == this) return *this; // self assignment
96 fStatus = rhs.fStatus;
97 fPointer = rhs.fPointer;
98 // if ( fPointer ) delete fPointer;
99 // fPointer = 0;
100 // if (rhs.fPointer != 0) fPointer = new TFitResult(*rhs);
101 return *this;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Print the TFitResultPtr by printing its TFitResult.
106
107std::string cling::printValue(const TFitResultPtr* val) {
108 if (TFitResult* fr = val->Get())
109 return printValue(fr);
110 return "<nullptr TFitResult>";
111}
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
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