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);
108 static_assert(std::is_arithmetic<T>::value,
"T must be an arithmetic type");
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 +
"'"));
120 template <
typename T>
122 parseNumber(
const ConfigSection::value_type& option,
const std::string& sectionName)
124 return parseNumber<T>(option.second, option.first, sectionName);
140 parse(
const std::string& filename,
bool isDryRun);
150 parse(
const std::string& input,
bool isDryRun,
const std::string& filename);
159 parse(std::istream& input,
bool isDryRun,
const std::string& filename);
172 process(
bool isDryRun,
const std::string& filename)
const;
176 std::map<std::string, ConfigSectionHandler> m_subscriptions;
182 #endif // NFD_DAEMON_COMMON_CONFIG_FILE_HPP void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
configuration file parsing utility
static T parseNumber(const ConfigSection::value_type &option, const std::string §ionName)
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"
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
ConfigFile(UnknownConfigSectionHandler unknownSectionCallback=throwErrorOnUnknownSection)
static T parseNumber(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a numeric (integral or floating point) config option
boost::property_tree::ptree ConfigSection
a config file section
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void parse(const std::string &filename, bool isDryRun)
std::function< void(const ConfigSection §ion, bool isDryRun, const std::string &filename)> ConfigSectionHandler
callback to process a config file section
static bool parseYesNo(const ConfigSection::value_type &option, const std::string §ionName)
static void throwErrorOnUnknownSection(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)
static void ignoreUnknownSection(const std::string &filename, const std::string §ionName, const ConfigSection §ion, bool isDryRun)