milupHPC documentation
  • src
  • utils
config_parser.cpp
Go to the documentation of this file.
1#include "../../include/utils/config_parser.h"
2
3ConfigParser::ConfigParser() {
4 //do nothing
5}
6ConfigParser::ConfigParser(const std::string &file){
7 // Extract the file extension from the filename
8 std::string ext = boost::filesystem::extension(file);
9 if (ext == ".json") {
10 // parse json and write into 'tree'
11 boost::property_tree::read_json(file, tree);
12 } else if (ext == ".info"){
13 // parse info and write into 'tree'
14 boost::property_tree::read_info(file, tree);
15 } else {
16 //BOOST_THROW_EXCEPTION(std::logic_error("Unsupported file extension"));
17 std::string errMsg = ext + ": unsupported file extension (supported: .json, .info)";
18 BOOST_THROW_EXCEPTION(std::invalid_argument(errMsg));
19 }
20}
21
22ConfigParser::ConfigParser(const boost::property_tree::ptree &subtree) : tree { subtree } {}
23
24ConfigParser ConfigParser::getObj(const std::string &key){
25 return ConfigParser(tree.get_child(key));
26}
27
28std::list<ConfigParser> ConfigParser::getObjList(const std::string &key) {
29 std::list <ConfigParser> lst_;
30 BOOST_FOREACH(const boost::property_tree::ptree::value_type &val,tree.get_child(key))
31 {
32 if(val.second.empty()){
33 std::cerr << "List does not contain objects. Please use 'getList<T>(const std::string &key)'instead."
34 << " - Returning empty list." << std::endl;
35 } else {
36 // storing instances of ConfigParsers each containing a subtree instead
37 lst_.push_back(ConfigParser(val.second.get_child("")));
38 }
39 }
40 return lst_;
41}
ConfigParser
Config parser class for reading input parameter/settings.
Definition: config_parser.h:43
ConfigParser::getObj
ConfigParser getObj(const std::string &key)
Definition: config_parser.cpp:24
ConfigParser::tree
boost::property_tree::ptree tree
boost property tree instance
Definition: config_parser.h:99
ConfigParser::getObjList
std::list< ConfigParser > getObjList(const std::string &key)
Definition: config_parser.cpp:28
ConfigParser::ConfigParser
ConfigParser()
Definition: config_parser.cpp:3
ProfilerIds::Time::tree
const char *const tree
Definition: h5profiler.h:57

milupHPC - src/utils/config_parser.cpp Source File
Generated on Wed Aug 31 2022 12:16:53 by Doxygen 1.9.3