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 
20 namespace 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 */
31 class IOptions {
32 
33 public:
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 
102 private:
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
ROOT::Math::IOptions::GetValue
bool GetValue(const char *name, T &t) const
Definition: IOptions.h:89
ROOT::Math::IOptions::SetRealValue
virtual void SetRealValue(const char *, double)
method wich need to be re-implemented by the derived classes
Definition: IOptions.h:106
ROOT::Math::IOptions::SetNamedValue
virtual void SetNamedValue(const char *, const char *)
Definition: IOptions.h:110
MATH_ERROR_MSG
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:83
ROOT::Math::IOptions::IValue
int IValue(const char *name) const
Definition: IOptions.h:72
Error.h
ROOT::Math::IOptions::GetRealValue
virtual bool GetRealValue(const char *, double &) const
Definition: IOptions.h:99
MATH_ERROR_MSGVAL
#define MATH_ERROR_MSGVAL(loc, txt, x)
Definition: Error.h:109
ROOT::Math::IOptions::NamedValue
std::string NamedValue(const char *name) const
Definition: IOptions.h:79
ROOT::Math::IOptions::~IOptions
virtual ~IOptions()
Definition: IOptions.h:52
ROOT::Math::IOptions::Clone
virtual IOptions * Clone() const =0
ROOT::Math::IOptions::IOptions
IOptions()
Definition: IOptions.h:50
MATH_INFO_MSG
#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
ROOT::Math::IOptions::GetNamedValue
virtual bool GetNamedValue(const char *, std::string &) const
Definition: IOptions.h:103
ROOT::Math::IOptions::RValue
double RValue(const char *name) const
Definition: IOptions.h:65
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::IOptions::Print
virtual void Print(std::ostream &=std::cout) const
print options
Definition: IOptions.h:114
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:52
ROOT::Math::IOptions::DoGetValue
bool DoGetValue(const char *name, double &val) const
Definition: IOptions.h:119
ROOT::Math::IOptions::GetIntValue
virtual bool GetIntValue(const char *, int &) const
Definition: IOptions.h:101
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Math::IOptions::SetValue
void SetValue(const char *name, double val)
generic methods for retrivieng options
Definition: IOptions.h:60
ROOT::Math::IOptions::SetIntValue
virtual void SetIntValue(const char *, int)
Definition: IOptions.h:108
Math