Logo ROOT   6.18/05
Reference Guide
GenAlgoOptions.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Nov 2010
3/**********************************************************************
4 * *
5 * Copyright (c) 2010 LCG ROOT Math Team, CERN/PH-SFT *
6 * *
7 * *
8 **********************************************************************/
9
10// implementation file for static methods of GenAlgoOptions
11// this file contains also the pointer to the static std::map<algorithm name, options>
12
13#include "Math/GenAlgoOptions.h"
14#include <cassert>
15
16// for toupper
17#include <algorithm>
18#include <functional>
19#include <ctype.h> // need to use c version of tolower defined here
20#include <string>
21
22namespace ROOT {
23namespace Math {
24
25typedef std::map<std::string, ROOT::Math::GenAlgoOptions > OptionsMap;
26
27namespace GenAlgoOptUtil {
28
29 // map with the generic options for all ROOT::Math numerical algorithm
31
32
33 IOptions * DoFindDefault(std::string & algoname, OptionsMap & gOpts) {
34 // internal function to retrieve the
35 // default extra options for the given algorithm type
36 // return zero if not found
37 // store always name in upper case
38 std::transform(algoname.begin(), algoname.end(), algoname.begin(), (int(*)(int)) toupper );
39
40 OptionsMap::iterator pos = gOpts.find(algoname);
41 if (pos != gOpts.end() ) {
42 return &(pos->second);
43 }
44 return 0;
45 }
46}
47
49 // find default options - return 0 if not found
50 std::string algoname(algo);
52 return GenAlgoOptUtil::DoFindDefault(algoname, gOpts);
53 }
54
55 IOptions & GenAlgoOptions::Default(const char * algo) {
56 // create default extra options for the given algorithm type
57 std::string algoname(algo);
59 IOptions * opt = GenAlgoOptUtil::DoFindDefault(algoname, gOpts);
60 if (opt == 0) {
61 // create new extra options for the given type
62 std::pair<OptionsMap::iterator,bool> ret = gOpts.insert( OptionsMap::value_type(algoname, ROOT::Math::GenAlgoOptions()) );
63 assert(ret.second);
64 opt = &((ret.first)->second);
65 }
66 return *opt;
67 }
68
69 void GenAlgoOptions::PrintAllDefault(std::ostream & os) {
71 for ( OptionsMap::const_iterator pos = gOpts.begin();
72 pos != gOpts.end(); ++pos) {
73 os << "Default specific options for algorithm " << pos->first << " : " << std::endl;
74 (pos->second).Print(os);
75 }
76 }
77
78 } // end namespace Math
79
80} // end namespace ROOT
81
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
virtual void Print(std::ostream &os=std::cout) const
print options
static IOptions & Default(const char *algoname)
static IOptions * FindDefault(const char *algoname)
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:30
Namespace for new Math classes and functions.
static OptionsMap gAlgoOptions
IOptions * DoFindDefault(std::string &algoname, OptionsMap &gOpts)
std::map< std::string, ROOT::Math::GenAlgoOptions > OptionsMap
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
static constexpr double second