本文整理汇总了C++中ConfigSection::get_child_optional方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigSection::get_child_optional方法的具体用法?C++ ConfigSection::get_child_optional怎么用?C++ ConfigSection::get_child_optional使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigSection
的用法示例。
在下文中一共展示了ConfigSection::get_child_optional方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
shared_ptr<ndn::Transport>
Nrd::getLocalNfdTransport()
{
ConfigSection config;
if (!m_configFile.empty()) {
// Any format errors should have been caught already
// If error is thrown at this point, it is development error
boost::property_tree::read_info(m_configFile, config);
}
else
config = m_configSection;
if (config.get_child_optional("face_system.unix")) {
// unix socket enabled
auto&& socketPath = config.get<std::string>("face_system.unix.path", "/var/run/nfd.sock");
// default socketPath should be the same as in FaceManager::processSectionUnix
return make_shared<ndn::UnixTransport>(socketPath);
}
else if (config.get_child_optional("face_system.tcp") &&
config.get<std::string>("face_system.tcp.listen", "yes") == "yes") {
// tcp is enabled
auto&& port = config.get<std::string>("face_system.tcp.port", "6363");
// default port should be the same as in FaceManager::processSectionTcp
return make_shared<ndn::TcpTransport>("localhost", port);
}
else {
throw Error("No transport is available to communicate with NFD");
}
}
示例2: parseLogLevel
static void
onConfig(const ConfigSection& section, bool isDryRun, const std::string&)
{
// log
// {
// ; default_level specifies the logging level for modules
// ; that are not explicitly named. All debugging levels
// ; listed above the selected value are enabled.
//
// default_level INFO
//
// ; You may also override the default for specific modules:
//
// FibManager DEBUG
// Forwarder WARN
// }
auto defaultLevel = ndn::util::LogLevel::INFO;
auto item = section.get_child_optional("default_level");
if (item) {
defaultLevel = parseLogLevel(*item, "default_level");
}
if (!isDryRun) {
// default_level applies only to NFD loggers
ndn::util::Logging::setLevel("nfd.*", defaultLevel);
}
for (const auto& i : section) {
if (i.first == "default_level") {
// do nothing
}
else {
auto level = parseLogLevel(i.second, i.first);
if (!isDryRun) {
if (i.first.find('.') == std::string::npos)
// backward compat: assume unqualified logger names refer to NFD loggers
ndn::util::Logging::setLevel("nfd." + i.first, level);
else
ndn::util::Logging::setLevel(i.first, level);
}
}
}
}