19 #include <boost/algorithm/string.hpp>
25 return parserInstance;
28 GGSInputParser::GGSInputParser() {
31 GGSInputParser::~GGSInputParser() {
36 std::string mych[1000];
37 ReadInput(fileName, &argc, (std::string *) mych);
41 static const std::string routineName(
"GGSInputParser::ReadInput");
43 _configFileName = fileName;
45 std::ifstream inputFile(fileName.c_str());
46 if (!inputFile.is_open())
51 if (inputFile.fail()) {
52 COUT(ERROR) <<
"Error in reading configuration file. No parameter has been loaded." <<
ENDL;
55 std::string lineData, lineBuffer;
56 while (!(inputFile.eof())) {
57 getline(inputFile, lineBuffer);
58 std::stringstream streamBuffer(lineBuffer, std::ios_base::in);
59 getline(streamBuffer, lineData,
'#');
60 if (lineData.length() > 0) {
62 std::string::iterator startWord = lineData.begin(), endWord = lineData.begin();
63 while (*startWord ==
' ' && startWord != lineData.end())
66 while (*endWord !=
' ' && endWord != lineData.end())
70 std::string parName(startWord, endWord);
75 while (*startWord ==
' ' && startWord != lineData.end())
78 while (*endWord !=
' ' && endWord != lineData.end())
82 std::string parValue(startWord, endWord);
83 boost::trim(parValue);
86 if (strcmp(parName.c_str(),
"")) {
88 argv[pargc] = parName;
91 if (strcmp(parValue.c_str(),
"")) {
93 argv[pargc] = parValue;
96 _parameters.push_back(std::pair<std::string, std::string>(parName, parValue));
106 const std::string GGSInputParser::_nullValue(
"");
108 const std::string &GGSInputParser::GetParameter(std::string parameterName) {
110 std::vector<std::pair<std::string, std::string> >::iterator iter = _parameters.begin();
112 for (iter = _parameters.begin(); iter != _parameters.end(); iter++) {
113 if (iter->first == parameterName)
121 bool GGSInputParser::GetFlag(std::string flagName) {
123 std::string auxFlag = GetParameter(flagName);
124 boost::to_lower(auxFlag);
125 if (auxFlag == std::string(
"true"))
131 void GGSInputParser::Report() {
132 static const std::string routineName(
"GGSInputParser::Report");
133 COUT(INFO) <<
"Parameters read from " << _configFileName <<
ENDL;
135 std::vector<std::pair<std::string, std::string> >::iterator iter = _parameters.begin();
136 while (iter != _parameters.end()) {
137 CCOUT(INFO) <<
" - " << iter->first <<
": " << iter->second <<
ENDL;
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
#define CCOUT(level)
Smart log utility which prints no header at the beginning of the line.