13 #include <boost/algorithm/string.hpp>
23 return parserInstance;
26 GGSInputParser::GGSInputParser() {}
28 GGSInputParser::~GGSInputParser() {}
32 std::string mych[1000];
33 ReadInput(fileName, &argc, (std::string *)mych);
37 static const std::string routineName(
"GGSInputParser::ReadInput");
39 _configFileName = fileName;
41 std::ifstream inputFile(fileName.c_str());
42 if (!inputFile.is_open())
47 if (inputFile.fail()) {
48 COUT(ERROR) <<
"Error in reading configuration file. No parameter has been loaded." <<
ENDL;
50 std::string lineData, lineBuffer;
51 while (!(inputFile.eof())) {
52 getline(inputFile, lineBuffer);
53 std::stringstream streamBuffer(lineBuffer, std::ios_base::in);
54 getline(streamBuffer, lineData,
'#');
55 if (lineData.length() > 0) {
57 std::string::iterator startWord = lineData.begin(), endWord = lineData.begin();
58 while (*startWord ==
' ' && startWord != lineData.end())
61 while (*endWord !=
' ' && endWord != lineData.end())
65 std::string parName(startWord, endWord);
70 while (*startWord ==
' ' && startWord != lineData.end())
73 while (*endWord !=
' ' && endWord != lineData.end())
77 std::string parValue(startWord, endWord);
78 boost::trim(parValue);
81 if (strcmp(parName.c_str(),
"")) {
83 argv[pargc] = parName;
86 if (strcmp(parValue.c_str(),
"")) {
88 argv[pargc] = parValue;
91 _parameters.push_back(std::pair<std::string, std::string>(parName, parValue));
99 const std::string GGSInputParser::_nullValue(
"");
101 const std::string &GGSInputParser::GetParameter(std::string parameterName) {
103 std::vector<std::pair<std::string, std::string>>::iterator iter = _parameters.begin();
105 for (iter = _parameters.begin(); iter != _parameters.end(); iter++) {
106 if (iter->first == parameterName)
113 bool GGSInputParser::GetFlag(std::string flagName) {
115 std::string auxFlag = GetParameter(flagName);
116 boost::to_lower(auxFlag);
117 if (auxFlag == std::string(
"true"))
123 void GGSInputParser::Report() {
124 static const std::string routineName(
"GGSInputParser::Report");
125 COUT(INFO) <<
"Parameters read from " << _configFileName <<
ENDL;
127 std::vector<std::pair<std::string, std::string>>::iterator iter = _parameters.begin();
128 while (iter != _parameters.end()) {
129 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.