[Compbench-devel] CompBenchmarks++/libcompbenchmarks/Base Config.cpp, NONE, 1.1 Config.h, NONE, 1.1
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-01-24 19:37:59
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Base In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv826 Added Files: Config.cpp Config.h Log Message: First import. --- NEW FILE: Config.h --- /* ---------------------------------------------------------------------------- $Id: Config.h,v 1.1 2007/01/24 19:37:47 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMCONFIG #define H_CBMCONFIG 1 #include <Benchmark/Package.h> #include <Base/XML.h> namespace CBM { /** \brief Interface to configuration * Class proposing API to configuration parameters and run context. */ class Config { protected: XMLNode *root; XMLNode *benchmarks; XMLNode *bmNode(std::string _bid); public: /** Constructor */ Config(std::string _filename); virtual CBM::Package::Status getStatus(std::string _bid); virtual void setStatus(std::string _bid, CBM::Package::Status _status); virtual std::string str(void); /** Destructor */ virtual ~Config(); }; } #endif --- NEW FILE: Config.cpp --- /* ---------------------------------------------------------------------------- $Id: Config.cpp,v 1.1 2007/01/24 19:37:47 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <Base/Config.h> #include <Base/XMLReader.h> #include <config.h> using namespace CBM; Config::Config(std::string _filename) { CBM::XMLReader r; CBM::XMLAttribute *A; root=r.read(_filename); if (root->Name() != "libcompbenchmarks") { delete(root); } if (!root) { root=new CBM::XMLNode("libcompbenchmarks"); } if (!root->getAttribute("version")) { A=new CBM::XMLAttribute("version", VERSION); root->add(A); } benchmarks=root->getChild("benchmarks"); printf("init benchmarks=%x\n", (unsigned int) benchmarks); if (!benchmarks) { benchmarks=root->addNode("benchmarks"); } } CBM::XMLNode *Config::bmNode(std::string _bid) { int i; int n = benchmarks->childNumber(); CBM::XMLNode *N; CBM::XMLAttribute *A; std::string tmp; char c[32]; for(i=0;i<n;i++) { N=benchmarks->getChild(i); if (N->Name() != "benchmark") continue; A=N->getAttribute("id"); if ((!A) || (A->Value() != _bid)) continue; return(N); } N=new CBM::XMLNode("benchmark"); N->addAttribute("id", _bid); sprintf(c, "%d", (int) CBM::Package::Unknown); tmp=c; N->addAttribute("status", tmp); benchmarks->add(N); return(N); } CBM::Package::Status Config::getStatus(std::string _bid) { CBM::XMLNode *N; CBM::XMLAttribute *A; std::string tmp; N=bmNode(_bid); A=N->getAttribute("status"); if (A) { tmp=A->Value(); if (tmp!="") return((CBM::Package::Status) ((int) tmp[0]-(int) '0')); } return(CBM::Package::Unknown); } void Config::setStatus(std::string _bid, CBM::Package::Status _status) { CBM::XMLNode *N; CBM::XMLAttribute *A; std::string tmp; char c[32]; sprintf(c, "%d", (int) _status); tmp=c; N=bmNode(_bid); A=N->getAttribute("status"); A->setValue(tmp); } std::string Config::str(void) { return(root->str()); } Config::~Config() { } |