26 #ifndef NFD_DAEMON_COMMON_CONFIG_FILE_HPP 27 #define NFD_DAEMON_COMMON_CONFIG_FILE_HPP 31 #include <boost/property_tree/ptree.hpp> 46 const std::string& filename)>;
51 const std::string& sectionName,
60 class Error :
public std::runtime_error
63 using std::runtime_error::runtime_error;
72 const std::string& sectionName,
78 const std::string& sectionName,
92 parseYesNo(
const ConfigSection::value_type& option,
const std::string& sectionName)
94 return parseYesNo(option.second, option.first, sectionName);
110 boost::optional<T>
value = node.get_value_optional<T>();
113 (std::is_signed<T>() || node.get_value<std::string>().find(
"-") == std::string::npos)) {
116 NDN_THROW(
Error(
"Invalid value '" + node.get_value<std::string>() +
117 "' for option '" + key +
"' in section '" + sectionName +
"'"));
122 parseNumber(
const ConfigSection::value_type& option,
const std::string& sectionName)
124 return parseNumber<T>(option.second, option.first, sectionName);
133 checkRange(T
value, T min, T max,
const std::string& key,
const std::string& sectionName)
137 if (value < min || value > max) {
139 "' in section '" + sectionName +
"': out of acceptable range [" +
157 parse(
const std::string& filename,
bool isDryRun);
167 parse(
const std::string& input,
bool isDryRun,
const std::string& filename);
176 parse(std::istream& input,
bool isDryRun,
const std::string& filename);
189 process(
bool isDryRun,
const std::string& filename)
const;
193 std::map<std::string, ConfigSectionHandler> m_subscriptions;
199 #endif // NFD_DAEMON_COMMON_CONFIG_FILE_HPP 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)
static bool parseYesNo(const ConfigSection::value_type &option, const std::string §ionName)
static void checkRange(T value, T min, T max, const std::string &key, const std::string §ionName)
check that a value is within the inclusive range [min, max]
configuration file parsing utility
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
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
static T parseNumber(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a numeric (integral or floating point) config option
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)
static T parseNumber(const ConfigSection::value_type &option, const std::string §ionName)