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