milupHPC documentation
  • include
  • utils
config_parser.h
Go to the documentation of this file.
1
16#ifndef CONFIGPARSER_H
17#define CONFIGPARSER_H
18
19#include <iostream>
20#include <string>
21#include <list>
22#include <boost/filesystem.hpp>
23#include <boost/property_tree/ptree.hpp>
24#include <boost/property_tree/json_parser.hpp>
25#include <boost/property_tree/info_parser.hpp>
26#include <boost/exception/exception.hpp>
27#include <boost/current_function.hpp>
28#include <boost/throw_exception.hpp>
29#include <boost/foreach.hpp>
30
31//#define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x)
32
43class ConfigParser {
44public:
45
49 ConfigParser();
50
56 ConfigParser(const std::string &file);
57
63 std::list<ConfigParser> getObjList(const std::string &key);
64
70 ConfigParser getObj(const std::string &key);
71
78 template <typename T>
79 T getVal(const std::string &key);
80
87 template <typename T>
88 std::list<T> getList(const std::string &key);
89
90private:
91 // Enable instantiation by ptree to make a recursive usage possible
96 ConfigParser(const boost::property_tree::ptree &subtree);
97
99 boost::property_tree::ptree tree;
100};
101
108template <typename T>
109T ConfigParser::getVal(const std::string &key) {
110 return tree.get<T>(key);
111}
112
119template <typename T>
120std::list<T> ConfigParser::getList(const std::string &key) {
121 std::list <T> lst_;
122 BOOST_FOREACH(const boost::property_tree::ptree::value_type &val,tree.get_child(key))
123 {
124 if (val.second.empty()) { // normal list, just fill it with type T
125 lst_.push_back(val.second.get_value<T>());
126 } else {
127 std::cerr << "List does not contain single values. Please use 'getObjList(const std::string &key)'instead."
128 << " - Returning empty list." << std::endl;
129 }
130 }
131 return lst_;
132}
133
134#endif //CONFIGPARSER_H
ConfigParser
Config parser class for reading input parameter/settings.
Definition: config_parser.h:43
ConfigParser::getVal
T getVal(const std::string &key)
Definition: config_parser.h:109
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
ConfigParser::getList
std::list< T > getList(const std::string &key)
Definition: config_parser.h:120

milupHPC - include/utils/config_parser.h Source File
Generated on Wed Aug 31 2022 12:16:52 by Doxygen 1.9.3