Logo ROOT   6.08/07
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 #ifndef ROOT_Math_Error
16 #include "Math/Error.h"
17 #endif
18 
19 #include <iostream>
20 
21 namespace ROOT {
22 
23 
24  namespace Math {
25 
26 //_______________________________________________________________________________
27 /**
28  Generic interface for defining configuration options of a numerical algorithm
29 
30  @ingroup NumAlgo
31 */
32 class IOptions {
33 
34 public:
35 
36  IOptions() /* : fExtraOptions(0) */ {}
37 
38  virtual ~IOptions() {}// { if (fExtraOptions) delete fExtraOptions; }
39 
40  // copy the options
41  virtual IOptions * Clone() const = 0;
42 
43  /** generic methods for retrivieng options */
44 
45  /// set option value
46  void SetValue(const char * name, double val) { SetRealValue(name,val);}
47  void SetValue(const char * name, int val) { SetIntValue(name,val);}
48  void SetValue(const char * name, const char * val) { SetNamedValue(name,val);}
49 
50 
51  double RValue(const char * name) const {
52  double val = 0;
53  bool ret = GetRealValue(name,val);
54  if (!ret ) MATH_ERROR_MSGVAL("IOptions::RValue"," return 0 - real option not found",name);
55  return val;
56  }
57 
58  int IValue(const char * name) const {
59  int val = 0;
60  bool ret = GetIntValue(name,val);
61  if (!ret ) MATH_ERROR_MSGVAL("IOptions::IValue"," return 0 - integer option not found",name);
62  return val;
63  }
64 
65  std::string NamedValue(const char * name) const {
66  std::string val;
67  bool ret = GetNamedValue(name,val);
68  if (!ret ) MATH_ERROR_MSGVAL("IOptions::NamedValue"," return empty string - named option not found",name);
69  return val;
70  }
71 
72 
73  // generic method to retrieve a type
74  template <typename T>
75  bool GetValue(const char * name, T & t) const {
76  bool ret = DoGetValue(name, t);
77  //if (!ret ) MATH_ERROR_MSG("IOptions::GetValue","option is not existing - returns 0");
78  return ret;
79  }
80 
81 
82  // methods to be re-implemented in the derived classes
83 
84 
85  virtual bool GetRealValue(const char *, double &) const { return false; }
86 
87  virtual bool GetIntValue(const char *, int &) const { return false; }
88 
89  virtual bool GetNamedValue(const char *, std::string &) const { return false; }
90 
91  /// method wich need to be re-implemented by the derived classes
92  virtual void SetRealValue(const char * , double ) {MATH_ERROR_MSG("IOptions::SetRealValue","Invalid setter method called"); }
93 
94  virtual void SetIntValue(const char * , int ) {MATH_ERROR_MSG("IOptions::SetIntValue","Invalid setter method called"); }
95 
96  virtual void SetNamedValue(const char * , const char * ) {MATH_ERROR_MSG("IOptions::SetNamedValue","Invalid setter method called"); }
97 
98 
99  /// print options
100  virtual void Print(std::ostream & = std::cout ) const {MATH_INFO_MSG("IOptions::Print","it is not implemented");}
101 
102 
103 private:
104 
105  bool DoGetValue(const char *name, double &val) const { return GetRealValue(name,val); }
106 
107  bool DoGetValue(const char *name, int &val) const { return GetIntValue(name,val); }
108 
109  bool DoGetValue(const char *name, std::string &val) const { return GetNamedValue(name,val); }
110 
111 
112 };
113 
114 
115  } // end namespace Math
116 
117 } // end namespace ROOT
118 
119 #endif
double RValue(const char *name) const
Definition: IOptions.h:51
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
bool DoGetValue(const char *name, double &val) const
Definition: IOptions.h:105
virtual void Print(std::ostream &=std::cout) const
print options
Definition: IOptions.h:100
double T(double x)
Definition: ChebyshevPol.h:34
bool DoGetValue(const char *name, std::string &val) const
Definition: IOptions.h:109
bool GetValue(const char *name, T &t) const
Definition: IOptions.h:75
virtual bool GetRealValue(const char *, double &) const
Definition: IOptions.h:85
#define MATH_ERROR_MSGVAL(loc, str, x)
Definition: Error.h:69
virtual void SetNamedValue(const char *, const char *)
Definition: IOptions.h:96
virtual void SetRealValue(const char *, double)
method wich need to be re-implemented by the derived classes
Definition: IOptions.h:92
void SetValue(const char *name, int val)
Definition: IOptions.h:47
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:50
std::string NamedValue(const char *name) const
Definition: IOptions.h:65
bool DoGetValue(const char *name, int &val) const
Definition: IOptions.h:107
#define MATH_INFO_MSG(loc, str)
Definition: Error.h:44
virtual bool GetIntValue(const char *, int &) const
Definition: IOptions.h:87
virtual IOptions * Clone() const =0
void SetValue(const char *name, double val)
generic methods for retrivieng options
Definition: IOptions.h:46
virtual void SetIntValue(const char *, int)
Definition: IOptions.h:94
virtual ~IOptions()
Definition: IOptions.h:38
Namespace for new Math classes and functions.
virtual bool GetNamedValue(const char *, std::string &) const
Definition: IOptions.h:89
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:32
int IValue(const char *name) const
Definition: IOptions.h:58
void SetValue(const char *name, const char *val)
Definition: IOptions.h:48
char name[80]
Definition: TGX11.cxx:109