ROOT  6.06/09
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 
21 namespace ROOT {
22 namespace Math {
23 
24 typedef std::map<std::string, ROOT::Math::GenAlgoOptions > OptionsMap;
25 
26 namespace GenAlgoOptUtil {
27 
28  // map with the generic options for all ROOT::Math numerical algorithm
29  static OptionsMap gAlgoOptions;
30 
31 
32  IOptions * DoFindDefault(std::string & algoname, OptionsMap & gOpts) {
33  // internal function to retrieve the
34  // default extra options for the given algorithm type
35  // return zero if not found
36  // store always name in upper case
37  std::transform(algoname.begin(), algoname.end(), algoname.begin(), (int(*)(int)) toupper );
38 
39  OptionsMap::iterator pos = gOpts.find(algoname);
40  if (pos != gOpts.end() ) {
41  return &(pos->second);
42  }
43  return 0;
44  }
45 }
46 
47  IOptions * GenAlgoOptions::FindDefault(const char * algo) {
48  // find default options - return 0 if not found
49  std::string algoname(algo);
50  OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions;
51  return GenAlgoOptUtil::DoFindDefault(algoname, gOpts);
52  }
53 
54  IOptions & GenAlgoOptions::Default(const char * algo) {
55  // create default extra options for the given algorithm type
56  std::string algoname(algo);
57  OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions;
58  IOptions * opt = GenAlgoOptUtil::DoFindDefault(algoname, gOpts);
59  if (opt == 0) {
60  // create new extra options for the given type
61  std::pair<OptionsMap::iterator,bool> ret = gOpts.insert( OptionsMap::value_type(algoname, ROOT::Math::GenAlgoOptions()) );
62  assert(ret.second);
63  opt = &((ret.first)->second);
64  }
65  return *opt;
66  }
67 
68  void GenAlgoOptions::PrintAllDefault(std::ostream & os) {
69  const OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions;
70  for ( OptionsMap::const_iterator pos = gOpts.begin();
71  pos != gOpts.end(); ++pos) {
72  os << "Default specific options for algorithm " << pos->first << " : " << std::endl;
73  (pos->second).Print(os);
74  }
75  }
76 
77  } // end namespace Math
78 
79 } // end namespace ROOT
80 
std::map< std::string, ROOT::Math::GenAlgoOptions > OptionsMap
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
#define assert(cond)
Definition: unittest.h:542
virtual void Print(std::ostream &os=std::cout) const
print options
static OptionsMap gAlgoOptions
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
IOptions * DoFindDefault(std::string &algoname, OptionsMap &gOpts)
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
Namespace for new Math classes and functions.
static IOptions & Default(const char *algoname)
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:32
static IOptions * FindDefault(const char *algoname)