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