Logo ROOT   6.14/05
Reference Guide
GenAlgoOptions.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Nov 2010
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2010 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 #ifndef ROOT_Math_GenAlgoOptions
12 #define ROOT_Math_GenAlgoOptions
13 
14 
15 #include "Math/IOptions.h"
16 
17 #include <map>
18 #include <iomanip>
19 
20 namespace ROOT {
21  namespace Math {
22 
23 //_______________________________________________________________________________
24 /**
25  class implementing generic options for a numerical algorithm
26  Just store the options in a map of string-value pairs
27 
28  @ingroup NumAlgo
29 */
30 class GenAlgoOptions : public IOptions {
31 
32 public:
33 
34  GenAlgoOptions() /* : fExtraOptions(0) */ {}
35 
36  virtual ~GenAlgoOptions() {}// { if (fExtraOptions) delete fExtraOptions; }
37 
38  // use default copy constructor and assignment operator
39 
40  /** generic methods for retrivieng options */
41 
42 
43  // methods implementing the IOptions interface
44 
45  virtual IOptions * Clone() const {
46  return new GenAlgoOptions(*this);
47  }
48 
49  // t.b.d need probably to implement in a .cxx file for CINT
50 
51 
52  virtual bool GetRealValue(const char * name, double & val) const {
53  const double * pval = FindValue(name, fRealOpts);
54  if (!pval) return false;
55  val = *pval;
56  return true;
57  }
58 
59  virtual bool GetIntValue(const char * name, int & val) const {
60  const int * pval = FindValue(name, fIntOpts);
61  if (!pval) return false;
62  val = *pval;
63  return true;
64  }
65 
66  virtual bool GetNamedValue(const char * name, std::string & val) const {
67  const std::string * pval = FindValue(name, fNamOpts);
68  if (!pval) return false;
69  val = *pval;
70  return true;
71  }
72 
73  /// method wich need to be re-implemented by the derived classes
74  virtual void SetRealValue(const char * name, double val) {
75  InsertValue(name, fRealOpts, val);
76  }
77 
78  virtual void SetIntValue(const char * name , int val) {
79  InsertValue(name, fIntOpts, val);
80  }
81 
82  virtual void SetNamedValue(const char * name, const char * val) {
83  InsertValue(name, fNamOpts, std::string(val));
84  }
85 
86 
87  /// print options
88  virtual void Print(std::ostream & os = std::cout ) const {
89  Print(fNamOpts,os);
90  Print(fIntOpts,os);
91  Print(fRealOpts,os);
92  }
93 
94 
95  // static methods to retrieve the default options
96 
97  // find the option given a name
98  // return 0 if the option is not found
99  static IOptions * FindDefault(const char * algoname);
100 
101  // retrieve options given the name
102  // if option is not found create a new GenAlgoOption for the given name
103  static IOptions & Default(const char * algoname);
104 
105  /// print all the default options
106  static void PrintAllDefault(std::ostream & os = std::cout);
107 
108 
109 protected:
110 
111 
112 
113 private:
114 
115  template<class M>
116  static const typename M::mapped_type * FindValue(const std::string & name, const M & opts) {
117  typename M::const_iterator pos;
118  pos = opts.find(name);
119  if (pos == opts.end()) {
120  return 0;
121  }
122  return &((*pos).second);
123  }
124 
125  template<class M>
126  static void InsertValue(const std::string &name, M & opts, const typename M::mapped_type & value) {
127  typename M::iterator pos;
128  pos = opts.find(name);
129  if (pos != opts.end()) {
130  pos->second = value;
131  }
132  else {
133  opts.insert(typename M::value_type(name, value) );
134  }
135  }
136 
137  template<class M>
138  static void Print( const M & opts, std::ostream & os) {
139  //const std::ios_base::fmtflags prevFmt = os.flags();
140  for (typename M::const_iterator pos = opts.begin(); pos != opts.end(); ++pos)
141  os << std::setw(25) << pos->first << " : " << std::setw(15) << pos->second << std::endl;
142  }
143 
144 
145  std::map<std::string, double> fRealOpts; // map of the real options
146  std::map<std::string, int> fIntOpts; // map of the integer options
147  std::map<std::string, std::string> fNamOpts; // map of the named options
148 
149 };
150 
151 
152 
153  } // end namespace Math
154 
155 } // end namespace ROOT
156 
157 #endif
std::map< std::string, std::string > fNamOpts
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
static const M::mapped_type * FindValue(const std::string &name, const M &opts)
virtual void SetNamedValue(const char *name, const char *val)
virtual bool GetIntValue(const char *name, int &val) const
virtual void Print(std::ostream &os=std::cout) const
print options
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
virtual void SetRealValue(const char *name, double val)
method wich need to be re-implemented by the derived classes
virtual IOptions * Clone() const
generic methods for retrivieng options
std::map< std::string, double > fRealOpts
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
static void Print(const M &opts, std::ostream &os)
static void InsertValue(const std::string &name, M &opts, const typename M::mapped_type &value)
Namespace for new Math classes and functions.
static IOptions & Default(const char *algoname)
virtual bool GetRealValue(const char *name, double &val) const
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:30
static IOptions * FindDefault(const char *algoname)
std::map< std::string, int > fIntOpts
virtual bool GetNamedValue(const char *name, std::string &val) const
virtual void SetIntValue(const char *name, int val)
char name[80]
Definition: TGX11.cxx:109