Logo ROOT  
Reference Guide
IOptions.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Fri Aug 15 2008
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2008 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11#ifndef ROOT_Math_IOptions
12#define ROOT_Math_IOptions
13
14
15#include "Math/Error.h"
16
17#include <iostream>
18#include <string>
19
20namespace ROOT {
21
22
23 namespace Math {
24
25//_______________________________________________________________________________
26/**
27 Generic interface for defining configuration options of a numerical algorithm
28
29 @ingroup NumAlgo
30*/
31class IOptions {
32
33public:
34
35 IOptions() /* : fExtraOptions(0) */ {}
36
37 virtual ~IOptions() {}// { if (fExtraOptions) delete fExtraOptions; }
38
39 // copy the options
40 virtual IOptions * Clone() const = 0;
41
42 /** generic methods for retrivieng options */
43
44 /// set option value
45 void SetValue(const char * name, double val) { SetRealValue(name,val);}
46 void SetValue(const char * name, int val) { SetIntValue(name,val);}
47 void SetValue(const char * name, const char * val) { SetNamedValue(name,val);}
48
49
50 double RValue(const char * name) const {
51 double val = 0;
52 bool ret = GetRealValue(name,val);
53 if (!ret ) MATH_ERROR_MSGVAL("IOptions::RValue"," return 0 - real option not found",name);
54 return val;
55 }
56
57 int IValue(const char * name) const {
58 int val = 0;
59 bool ret = GetIntValue(name,val);
60 if (!ret ) MATH_ERROR_MSGVAL("IOptions::IValue"," return 0 - integer option not found",name);
61 return val;
62 }
63
64 std::string NamedValue(const char * name) const {
65 std::string val;
66 bool ret = GetNamedValue(name,val);
67 if (!ret ) MATH_ERROR_MSGVAL("IOptions::NamedValue"," return empty string - named option not found",name);
68 return val;
69 }
70
71
72 // generic method to retrieve a type
73 template <typename T>
74 bool GetValue(const char * name, T & t) const {
75 bool ret = DoGetValue(name, t);
76 //if (!ret ) MATH_ERROR_MSG("IOptions::GetValue","option is not existing - returns 0");
77 return ret;
78 }
79
80
81 // methods to be re-implemented in the derived classes
82
83
84 virtual bool GetRealValue(const char *, double &) const { return false; }
85
86 virtual bool GetIntValue(const char *, int &) const { return false; }
87
88 virtual bool GetNamedValue(const char *, std::string &) const { return false; }
89
90 /// method wich need to be re-implemented by the derived classes
91 virtual void SetRealValue(const char * , double ) {MATH_ERROR_MSG("IOptions::SetRealValue","Invalid setter method called"); }
92
93 virtual void SetIntValue(const char * , int ) {MATH_ERROR_MSG("IOptions::SetIntValue","Invalid setter method called"); }
94
95 virtual void SetNamedValue(const char * , const char * ) {MATH_ERROR_MSG("IOptions::SetNamedValue","Invalid setter method called"); }
96
97
98 /// print options
99 virtual void Print(std::ostream & = std::cout ) const {MATH_INFO_MSG("IOptions::Print","it is not implemented");}
100
101
102private:
103
104 bool DoGetValue(const char *name, double &val) const { return GetRealValue(name,val); }
105
106 bool DoGetValue(const char *name, int &val) const { return GetIntValue(name,val); }
107
108 bool DoGetValue(const char *name, std::string &val) const { return GetNamedValue(name,val); }
109
110
111};
112
113
114 } // end namespace Math
115
116} // end namespace ROOT
117
118#endif
#define MATH_INFO_MSG(loc, str)
Pre-processor macro to report messages which can be configured to use ROOT error or simply an std::io...
Definition: Error.h:77
#define MATH_ERROR_MSGVAL(loc, txt, x)
Definition: Error.h:109
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:83
char name[80]
Definition: TGX11.cxx:110
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:31
virtual bool GetIntValue(const char *, int &) const
Definition: IOptions.h:86
virtual void SetNamedValue(const char *, const char *)
Definition: IOptions.h:95
void SetValue(const char *name, int val)
Definition: IOptions.h:46
virtual ~IOptions()
Definition: IOptions.h:37
double RValue(const char *name) const
Definition: IOptions.h:50
std::string NamedValue(const char *name) const
Definition: IOptions.h:64
virtual void SetRealValue(const char *, double)
method wich need to be re-implemented by the derived classes
Definition: IOptions.h:91
virtual void SetIntValue(const char *, int)
Definition: IOptions.h:93
virtual void Print(std::ostream &=std::cout) const
print options
Definition: IOptions.h:99
void SetValue(const char *name, double val)
generic methods for retrivieng options
Definition: IOptions.h:45
bool DoGetValue(const char *name, std::string &val) const
Definition: IOptions.h:108
int IValue(const char *name) const
Definition: IOptions.h:57
virtual IOptions * Clone() const =0
bool GetValue(const char *name, T &t) const
Definition: IOptions.h:74
virtual bool GetRealValue(const char *, double &) const
Definition: IOptions.h:84
void SetValue(const char *name, const char *val)
Definition: IOptions.h:47
bool DoGetValue(const char *name, double &val) const
Definition: IOptions.h:104
virtual bool GetNamedValue(const char *, std::string &) const
Definition: IOptions.h:88
bool DoGetValue(const char *name, int &val) const
Definition: IOptions.h:106
Namespace for new Math classes and functions.
double T(double x)
Definition: ChebyshevPol.h:34
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...