28 #include <boost/property_tree/info_parser.hpp> 36 : m_unknownSectionCallback(unknownSectionCallback)
42 const std::string& sectionName,
46 NDN_THROW(
Error(
"Error processing configuration file " + filename +
47 ": no module subscribed for section '" + sectionName +
"'"));
52 const std::string& sectionName,
61 const std::string& sectionName)
63 auto value = node.get_value<std::string>();
68 else if (
value ==
"no") {
73 key +
"' in section '" + sectionName +
"'"));
80 m_subscriptions[sectionName] = subscriber;
86 std::ifstream inputFile(filename);
87 if (!inputFile.good() || !inputFile.is_open()) {
90 parse(inputFile, isDryRun, filename);
97 std::istringstream inputStream(input);
98 parse(inputStream, isDryRun, filename);
105 boost::property_tree::read_info(input, m_global);
107 catch (
const boost::property_tree::info_parser_error& error) {
108 NDN_THROW(
Error(
"Failed to parse configuration file " + filename +
109 ": " + error.message() +
" on line " +
to_string(error.line())));
112 process(isDryRun, filename);
119 process(isDryRun, filename);
123 ConfigFile::process(
bool isDryRun,
const std::string& filename)
const 125 BOOST_ASSERT(!filename.empty());
127 for (
const auto& i : m_global) {
130 subscriber(i.second, isDryRun, filename);
132 catch (
const std::out_of_range&) {
133 m_unknownSectionCallback(filename, i.first, i.second, isDryRun);
static bool parseYesNo(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a config option that can be either "yes" or "no"
std::string to_string(const T &val)
std::function< void(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)> UnknownConfigSectionHandler
callback to process a config file section without a ConfigSectionHandler
static void throwErrorOnUnknownSection(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)
Copyright (c) 2011-2015 Regents of the University of California.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
std::function< void(const ConfigSection §ion, bool isDryRun, const std::string &filename)> ConfigSectionHandler
callback to process a config file section
boost::property_tree::ptree ConfigSection
a config file section
ConfigFile(UnknownConfigSectionHandler unknownSectionCallback=throwErrorOnUnknownSection)
static void ignoreUnknownSection(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)
void parse(const std::string &filename, bool isDryRun)