#include "Configuration.hpp" #include #include #include #include using namespace config; namespace config { struct ConfigurationImpl { boost::property_tree::ptree ptree; }; template TYPE get(boost::property_tree::ptree tree, const std::string &property) { try { return tree.get(property); } catch (boost::property_tree::ptree_bad_path) { throw ConfigException((boost::format("Configuration option '%s' (type: %s) not found.") % property % typeid(TYPE).name()).str()); } } } config::Configuration::Configuration(const std::string fileName) : impl(new ConfigurationImpl()) { boost::property_tree::read_ini(fileName, impl->ptree); } config::Configuration::Configuration(std::vector const fileNames) : impl(new ConfigurationImpl()) { for (auto &name : fileNames) { boost::property_tree::read_ini(name, impl->ptree); } } config::Configuration::~Configuration() { delete impl; } int config::Configuration::getInt(const std::string &property) { return get(impl->ptree, property); } bool config::Configuration::getBool(const std::string &property) { return get(impl->ptree, property); } std::string config::Configuration::getString(const std::string &property) { return get(impl->ptree, property); } // TODO: return set std::unordered_map config::Configuration::getChildren(const std::string &property) { std::unordered_map pins; BOOST_FOREACH(boost::property_tree::ptree::value_type &v, impl->ptree.get_child(property)) { //pins[v.first.data()] = get(impl->ptree, property + "." + v.second.data()); pins[v.first.data()] = v.second.data(); } return pins; }