GenAlgoOptions.cxx

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: GenAlgoOptions.cxx 36796 2010-11-19 17:33:27Z moneta $ 
00002 // Author: L. Moneta Nov 2010
00003 /**********************************************************************
00004  *                                                                    *
00005  * Copyright (c) 2010  LCG ROOT Math Team, CERN/PH-SFT                *
00006  *                                                                    *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 // implementation file for static methods of GenAlgoOptions
00011 // this file contains also the pointer to the static map<algorithm name, options> 
00012 
00013 #include "Math/GenAlgoOptions.h"
00014 #include <cassert>
00015 
00016 // for toupper
00017 #include <algorithm>
00018 #include <functional>
00019 #include <ctype.h>   // need to use c version of tolower defined here
00020 
00021 namespace ROOT { 
00022 namespace Math { 
00023 
00024 typedef std::map<std::string, ROOT::Math::GenAlgoOptions > OptionsMap; 
00025 
00026 namespace GenAlgoOptUtil {
00027 
00028    // map with the generic options for all ROOT::Math numerical algorithm 
00029    static OptionsMap gAlgoOptions; 
00030  
00031 
00032    IOptions * DoFindDefault(std::string & algoname, OptionsMap & gOpts) { 
00033       // internal function to retrieve the 
00034       // default extra options for the given algorithm type 
00035       // return zero if not found
00036       // store always name in upper case
00037       std::transform(algoname.begin(), algoname.end(), algoname.begin(), (int(*)(int)) toupper ); 
00038       
00039       OptionsMap::iterator pos = gOpts.find(algoname); 
00040       if (pos !=  gOpts.end() ) { 
00041          return &(pos->second); 
00042       }
00043       return 0; 
00044    }
00045 }
00046    
00047    IOptions * GenAlgoOptions::FindDefault(const char * algo) { 
00048       // find default options - return 0 if not found
00049       std::string algoname(algo);
00050       OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions; 
00051       return GenAlgoOptUtil::DoFindDefault(algoname, gOpts); 
00052    }
00053 
00054    IOptions & GenAlgoOptions::Default(const char * algo) { 
00055       // create default extra options for the given algorithm type 
00056       std::string algoname(algo);
00057       OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions; 
00058       IOptions * opt = GenAlgoOptUtil::DoFindDefault(algoname, gOpts); 
00059       if (opt == 0) { 
00060          // create new extra options for the given type
00061          std::pair<OptionsMap::iterator,bool> ret = gOpts.insert( OptionsMap::value_type(algoname, ROOT::Math::GenAlgoOptions()) );
00062          assert(ret.second);
00063          opt = &((ret.first)->second);
00064       }
00065       return *opt;
00066    }
00067 
00068    void PrintAllDefault(std::ostream & os) { 
00069       const OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions; 
00070       for (  OptionsMap::const_iterator pos = gOpts.begin(); 
00071           pos != gOpts.end(); ++pos) { 
00072             os << "Default specific options for algorithm "  << pos->first << " : " << std::endl;
00073             (pos->second).Print(os);         
00074       }
00075    }
00076 
00077    } // end namespace Math
00078 
00079 } // end namespace ROOT
00080 

Generated on Tue Jul 5 14:34:23 2011 for ROOT_528-00b_version by  doxygen 1.5.1