#ifndef ROOT_Math_GenAlgoOptions
#define ROOT_Math_GenAlgoOptions
#ifndef ROOT_Math_IOptions
#include "Math/IOptions.h"
#endif
#include <map>
#include <iomanip>
namespace ROOT {
namespace Math {
class GenAlgoOptions : public IOptions {
public:
GenAlgoOptions() {}
virtual ~GenAlgoOptions() {}
virtual IOptions * Clone() const {
return new GenAlgoOptions(*this);
}
virtual bool GetRealValue(const char * name, double & val) const {
const double * pval = FindValue(name, fRealOpts);
if (!pval) return false;
val = *pval;
return true;
}
virtual bool GetIntValue(const char * name, int & val) const {
const int * pval = FindValue(name, fIntOpts);
if (!pval) return false;
val = *pval;
return true;
}
virtual bool GetNamedValue(const char * name, std::string & val) const {
const std::string * pval = FindValue(name, fNamOpts);
if (!pval) return false;
val = *pval;
return true;
}
virtual void SetRealValue(const char * name, double val) {
InsertValue(name, fRealOpts, val);
}
virtual void SetIntValue(const char * name , int val) {
InsertValue(name, fIntOpts, val);
}
virtual void SetNamedValue(const char * name, const char * val) {
InsertValue(name, fNamOpts, std::string(val));
}
virtual void Print(std::ostream & os = std::cout ) const {
Print(fNamOpts,os);
Print(fIntOpts,os);
Print(fRealOpts,os);
}
static IOptions * FindDefault(const char * algoname);
static IOptions & Default(const char * algoname);
static void PrintAllDefault(std::ostream & os = std::cout);
protected:
private:
template<class M>
static const typename M::mapped_type * FindValue(const std::string & name, const M & opts) {
typename M::const_iterator pos;
pos = opts.find(name);
if (pos == opts.end()) {
return 0;
}
return &((*pos).second);
}
template<class M>
static void InsertValue(const std::string &name, M & opts, const typename M::mapped_type & value) {
typename M::iterator pos;
pos = opts.find(name);
if (pos != opts.end()) {
pos->second = value;
}
else {
opts.insert(typename M::value_type(name, value) );
}
}
template<class M>
static void Print( const M & opts, std::ostream & os) {
for (typename M::const_iterator pos = opts.begin(); pos != opts.end(); ++pos)
os << std::setw(25) << pos->first << " : " << std::setw(15) << pos->second << std::endl;
}
std::map<std::string, double> fRealOpts;
std::map<std::string, int> fIntOpts;
std::map<std::string, std::string> fNamOpts;
};
}
}
#endif