26 #ifndef NFD_CORE_CONFIG_FILE_HPP 27 #define NFD_CORE_CONFIG_FILE_HPP 31 #include <boost/property_tree/ptree.hpp> 51 typedef function<void(
const std::string& filename,
52 const std::string& sectionName,
61 class Error :
public std::runtime_error
66 :
std::runtime_error(what)
77 const std::string& sectionName,
83 const std::string& sectionName,
97 parseYesNo(
const ConfigSection::value_type& option,
const std::string& sectionName)
99 return parseYesNo(option.second, option.first, sectionName);
113 static_assert(std::is_arithmetic<T>::value,
"T must be an arithmetic type");
115 boost::optional<T> value = node.get_value_optional<T>();
119 BOOST_THROW_EXCEPTION(
Error(
"Invalid value \"" + node.get_value<std::string>() +
120 "\" for option \"" + key +
"\" in \"" + sectionName +
"\" section"));
123 template <
typename T>
125 parseNumber(
const ConfigSection::value_type& option,
const std::string& sectionName)
127 return parseNumber<T>(option.second, option.first, sectionName);
143 parse(
const std::string& filename,
bool isDryRun);
153 parse(
const std::string& input,
bool isDryRun,
const std::string& filename);
162 parse(std::istream& input,
bool isDryRun,
const std::string& filename);
175 process(
bool isDryRun,
const std::string& filename)
const;
179 std::map<std::string, ConfigSectionHandler> m_subscriptions;
185 #endif // NFD_CORE_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"
static bool parseYesNo(const ConfigSection::value_type &option, const std::string §ionName)
configuration file parsing utility
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
Error(const std::string &what)
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
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
boost::property_tree::ptree ConfigSection
a config file section
function< void(const ConfigSection §ion, bool isDryRun, const std::string &filename)> ConfigSectionHandler
callback to process 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)