49 ifstream fin(parameter_file.c_str());
checkIO(fin, parameter_file);
53 while (getline(fin, line)) {
56 line = line.substr(0, line.find(
"\r"));
57 line = line.substr(0, line.find(
"\n"));
58 line = line.substr(0, line.find(
"#"));
61 string::size_type eqpos = line.find(
'=');
63 if (eqpos!=string::npos) {
64 string key = line.substr(0, eqpos);
65 string val = line.substr(eqpos+1, string::npos);
68 if (val.find(
'{') == string::npos) m_parameters[m_trim(key)] = m_trim(val);
70 vector<string> vval = m_trim_vect(val);
71 m_vectors[m_trim(key)] = vval;
78 fin.clear(); fin.close();
87 return inStr.substr(inStr.find_first_not_of(
' '), inStr.find_last_not_of(
' ')+1);
98 str = str.substr(str.find_first_not_of(
'{'), str.find_last_not_of(
'}'));
99 while (str.find(str.front()) != string::npos) {
101 if (str.find(
',') != string::npos) {
102 val = m_trim(str.substr(str.find(str.front()), str.find_first_of(
',')));
103 str.erase(str.find(str.front()), str.find_first_of(
',')+1);
106 val = m_trim(str.substr(str.find(str.front()), string::npos));
107 str.erase(str.find(str.front()), string::npos);
109 vect.emplace_back(val);
The class ReadParameters.
std::string m_trim(const std::string inStr)
Remove white spaces treading and leading each std::string (private function)
ReadParameters()=default
Default empty constructor.
std::vector< std::string > m_trim_vect(const std::string inStr)
Stores values contained in between curly brackets in a vector of std::string (private function)
The global namespace of the CosmoBolognaLib
void checkIO(const std::ifstream &fin, const std::string file="NULL")
check if an input file can be opened