26 #ifndef NFD_CORE_CONFIG_FILE_HPP 27 #define NFD_CORE_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
65 : std::runtime_error(what)
76 const std::string& sectionName,
82 const std::string& sectionName,
96 parseYesNo(
const ConfigSection::value_type& option,
const std::string& sectionName)
98 return parseYesNo(option.second, option.first, sectionName);
112 static_assert(std::is_arithmetic<T>::value,
"T must be an arithmetic type");
114 boost::optional<T> value = node.get_value_optional<T>();
118 BOOST_THROW_EXCEPTION(
Error(
"Invalid value \"" + node.get_value<std::string>() +
119 "\" for option \"" + key +
"\" in \"" + sectionName +
"\" section"));
122 template <
typename T>
124 parseNumber(
const ConfigSection::value_type& option,
const std::string& sectionName)
126 return parseNumber<T>(option.second, option.first, sectionName);
142 parse(
const std::string& filename,
bool isDryRun);
152 parse(
const std::string& input,
bool isDryRun,
const std::string& filename);
161 parse(std::istream& input,
bool isDryRun,
const std::string& filename);
174 process(
bool isDryRun,
const std::string& filename)
const;
178 std::map<std::string, ConfigSectionHandler> m_subscriptions;
184 #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
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
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
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)