22 SetName(
"UserSettings");
25 std::ifstream settings(settingsFile);
27 if(!settings.is_open()) {
28 std::cerr <<
"Failed to open user settings file '" << settingsFile <<
"'!" << std::endl;
33 while(std::getline(settings, line)) {
35 if(line.length() < 3) {
continue; }
36 if(line[0] ==
'#') {
continue; }
37 if(line[0] ==
'/' && line[1] ==
'/') {
continue; }
38 auto colon = line.find(
':');
39 if(colon == std::string::npos) {
continue; }
41 auto name = line.substr(0, colon);
42 auto value = line.substr(colon + 1);
47 if(value.find(
',') != std::string::npos) {
48 std::istringstream valueStream(value);
49 while(std::getline(valueStream, line,
',')) {
67 auto intVal = std::stoi(value, &pos);
68 if(pos == value.length()) {
76 }
catch(std::invalid_argument& e) {
83 auto doubleVal = std::stod(value, &pos);
84 if(pos == value.length()) {
92 }
catch(std::invalid_argument& e) {
97 std::string copy = value;
98 std::transform(copy.begin(), copy.end(), copy.begin(), ::tolower);
100 std::istringstream str(copy);
101 str >> std::boolalpha >> boolVal;
104 fBool[name] = boolVal;
122 return fBool.at(parameter);
123 }
catch(std::out_of_range& e) {
125 std::cout <<
"Failed to find \"" << parameter <<
"\" in boolean map" << std::endl;
135 return fInt.at(parameter);
136 }
catch(std::out_of_range& e) {
138 std::cout <<
"Failed to find \"" << parameter <<
"\" in integer map" << std::endl;
149 }
catch(std::out_of_range& e) {
151 std::cout <<
"Failed to find \"" << parameter <<
"\" in double map" << std::endl;
162 }
catch(std::out_of_range& e) {
164 std::cout <<
"Failed to find \"" << parameter <<
"\" in string map" << std::endl;
175 }
catch(std::out_of_range& e) {
177 std::cout <<
"Failed to find \"" << parameter <<
"\" in boolean vector map" << std::endl;
188 }
catch(std::out_of_range& e) {
190 std::cout <<
"Failed to find \"" << parameter <<
"\" in integer vector map" << std::endl;
201 }
catch(std::out_of_range& e) {
203 std::cout <<
"Failed to find \"" << parameter <<
"\" in double vector map" << std::endl;
214 }
catch(std::out_of_range& e) {
216 std::cout <<
"Failed to find \"" << parameter <<
"\" in string vector map" << std::endl;
225 std::cout <<
"Settings read from";
226 for(
const auto& file :
fSettingsFiles) { std::cout <<
" " << file; }
227 std::cout <<
":" << std::endl;
228 if(!
fBool.empty()) { std::cout <<
"---------- booleans ----------" << std::endl; }
229 for(
const auto& val :
fBool) {
230 std::cout << std::boolalpha << val.first <<
": " << val.second << std::endl;
232 if(!
fInt.empty()) { std::cout <<
"---------- integers ----------" << std::endl; }
233 for(
const auto& val :
fInt) {
234 std::cout << val.first <<
": " << val.second << std::endl;
236 if(!
fDouble.empty()) { std::cout <<
"---------- doubles ----------" << std::endl; }
237 for(
const auto& val :
fDouble) {
238 std::cout << val.first <<
": " << val.second << std::endl;
240 if(!
fString.empty()) { std::cout <<
"---------- strings ----------" << std::endl; }
241 for(
const auto& val :
fString) {
242 std::cout << val.first <<
": " << val.second << std::endl;
244 if(!
fBoolVector.empty()) { std::cout <<
"---------- boolean vectors ----------" << std::endl; }
246 std::cout << std::boolalpha << val.first <<
": ";
247 for(
const auto& item : val.second) {
248 std::cout << item <<
" ";
250 std::cout << std::endl;
252 if(!
fIntVector.empty()) { std::cout <<
"---------- integer vectors ----------" << std::endl; }
254 std::cout << val.first <<
": ";
255 for(
const auto& item : val.second) {
256 std::cout << item <<
" ";
258 std::cout << std::endl;
260 if(!
fDoubleVector.empty()) { std::cout <<
"---------- double vectors ----------" << std::endl; }
262 std::cout << val.first <<
": ";
263 for(
const auto& item : val.second) {
264 std::cout << item <<
" ";
266 std::cout << std::endl;
268 if(!
fStringVector.empty()) { std::cout <<
"---------- string vectors ----------" << std::endl; }
270 std::cout << val.first <<
": ";
271 for(
const auto& item : val.second) {
272 std::cout << item <<
" ";
274 std::cout << std::endl;
void trim(std::string &line, const std::string &trimChars=" \f\n\r\t\v")
void Print(Option_t *opt="") const override
std::map< std::string, double > fDouble
std::map< std::string, std::vector< bool > > fBoolVector
std::vector< double > GetDoubleVector(const std::string ¶meter, bool quiet=false) const
std::string GetString(const std::string ¶meter, bool quiet=false) const
std::vector< std::string > GetStringVector(const std::string ¶meter, bool quiet=false) const
std::map< std::string, int > fInt
bool GetBool(const std::string ¶meter, bool quiet=false) const
std::vector< bool > GetBoolVector(const std::string ¶meter, bool quiet=false) const
std::vector< int > GetIntVector(const std::string ¶meter, bool quiet=false) const
std::map< std::string, std::vector< std::string > > fStringVector
std::map< std::string, bool > fBool
std::vector< std::string > fSettingsFiles
std::map< std::string, std::vector< int > > fIntVector
std::map< std::string, std::vector< double > > fDoubleVector
int GetInt(const std::string ¶meter, bool quiet=false) const
std::map< std::string, std::string > fString
double GetDouble(const std::string ¶meter, bool quiet=false) const
bool ReadSettings(const std::string &settingsFile)
void ParseValue(const std::string &name, const std::string &value, bool vector)