本文整理汇总了C++中ConfigSection::end方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigSection::end方法的具体用法?C++ ConfigSection::end怎么用?C++ ConfigSection::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigSection
的用法示例。
在下文中一共展示了ConfigSection::end方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Error
static void
onConfig(const ConfigSection& configSection,
bool isDryRun,
const std::string& filename)
{
// general
// {
// ; user "ndn-user"
// ; group "ndn-user"
// }
std::string user;
std::string group;
for (ConfigSection::const_iterator i = configSection.begin();
i != configSection.end();
++i)
{
if (i->first == "user")
{
try
{
user = i->second.get_value<std::string>("user");
if (user.empty())
{
throw ConfigFile::Error("Invalid value for \"user\""
" in \"general\" section");
}
}
catch (const boost::property_tree::ptree_error& error)
{
throw ConfigFile::Error("Invalid value for \"user\""
" in \"general\" section");
}
}
else if (i->first == "group")
{
try
{
group = i->second.get_value<std::string>("group");
if (group.empty())
{
throw ConfigFile::Error("Invalid value for \"group\""
" in \"general\" section");
}
}
catch (const boost::property_tree::ptree_error& error)
{
throw ConfigFile::Error("Invalid value for \"group\""
" in \"general\" section");
}
}
}
NFD_LOG_TRACE("using user \"" << user << "\" group \"" << group << "\"");
PrivilegeHelper::initialize(user, group);
}
示例2: Error
static shared_ptr<Filter>
create(const ConfigSection& configSection)
{
ConfigSection::const_iterator propertyIt = configSection.begin();
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
throw Error("Expect <filter.type>!");
std::string type = propertyIt->second.data();
if (boost::iequals(type, "name"))
return createNameFilter(configSection);
else
throw Error("Unsupported filter.type: " + type);
}
示例3: createKeyLocatorNameChecker
static shared_ptr<KeyLocatorChecker>
create(const ConfigSection& configSection, const std::string& filename)
{
ConfigSection::const_iterator propertyIt = configSection.begin();
// Get checker.key-locator.type
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.type>!"));
std::string type = propertyIt->second.data();
if (boost::iequals(type, "name"))
return createKeyLocatorNameChecker(configSection, filename);
else
BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator.type: " + type));
}
示例4: if
static shared_ptr<KeyLocatorChecker>
createKeyLocatorNameChecker(const ConfigSection& configSection,
const std::string& filename)
{
ConfigSection::const_iterator propertyIt = configSection.begin();
propertyIt++;
if (propertyIt == configSection.end())
BOOST_THROW_EXCEPTION(Error("Expect more checker.key-locator properties"));
if (boost::iequals(propertyIt->first, "name"))
{
Name name;
try
{
name = Name(propertyIt->second.data());
}
catch (Name::Error& e)
{
BOOST_THROW_EXCEPTION(Error("Invalid checker.key-locator.name: " +
propertyIt->second.data()));
}
propertyIt++;
if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "relation"))
BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.relation>!"));
std::string relationString = propertyIt->second.data();
propertyIt++;
KeyLocatorChecker::Relation relation;
if (boost::iequals(relationString, "equal"))
relation = KeyLocatorChecker::RELATION_EQUAL;
else if (boost::iequals(relationString, "is-prefix-of"))
relation = KeyLocatorChecker::RELATION_IS_PREFIX_OF;
else if (boost::iequals(relationString, "is-strict-prefix-of"))
relation = KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF;
else
BOOST_THROW_EXCEPTION(Error("Unsupported relation: " + relationString));
if (propertyIt != configSection.end())
BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator!"));
return shared_ptr<RelationKeyLocatorNameChecker>
(new RelationKeyLocatorNameChecker(name, relation));
}
else if (boost::iequals(propertyIt->first, "regex"))
{
std::string regexString = propertyIt->second.data();
propertyIt++;
if (propertyIt != configSection.end())
BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator!"));
try
{
return shared_ptr<RegexKeyLocatorNameChecker>
(new RegexKeyLocatorNameChecker(regexString));
}
catch (Regex::Error& e)
{
BOOST_THROW_EXCEPTION(Error("Invalid checker.key-locator.regex: " + regexString));
}
}
else if (boost::iequals(propertyIt->first, "hyper-relation"))
{
const ConfigSection& hSection = propertyIt->second;
ConfigSection::const_iterator hPropertyIt = hSection.begin();
// Get k-regex
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "k-regex"))
BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.k-regex>!"));
std::string kRegex = hPropertyIt->second.data();
hPropertyIt++;
// Get k-expand
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "k-expand"))
BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.k-expand>!"));
std::string kExpand = hPropertyIt->second.data();
hPropertyIt++;
// Get h-relation
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "h-relation"))
BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.h-relation>!"));
std::string hRelation = hPropertyIt->second.data();
hPropertyIt++;
// Get p-regex
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "p-regex"))
BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.p-regex>!"));
std::string pRegex = hPropertyIt->second.data();
hPropertyIt++;
// Get p-expand
if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "p-expand"))
//.........这里部分代码省略.........
示例5: Error
void
CommandValidator::onConfig(const ConfigSection& section,
bool isDryRun,
const std::string& filename)
{
using namespace boost::filesystem;
const ConfigSection EMPTY_SECTION;
m_validator.reset();
if (section.begin() == section.end())
{
throw ConfigFile::Error("No authorize sections found");
}
std::stringstream dryRunErrors;
ConfigSection::const_iterator authIt;
for (authIt = section.begin(); authIt != section.end(); authIt++)
{
std::string certfile;
try
{
certfile = authIt->second.get<std::string>("certfile");
}
catch (const std::runtime_error& e)
{
std::string msg = "No certfile specified";
if (!isDryRun)
{
throw ConfigFile::Error(msg);
}
aggregateErrors(dryRunErrors, msg);
continue;
}
shared_ptr<ndn::IdentityCertificate> id;
if (certfile != "any")
{
path certfilePath = absolute(certfile, path(filename).parent_path());
NFD_LOG_DEBUG("generated certfile path: " << certfilePath.native());
std::ifstream in;
in.open(certfilePath.c_str());
if (!in.is_open())
{
std::string msg = "Unable to open certificate file " + certfilePath.native();
if (!isDryRun)
{
throw ConfigFile::Error(msg);
}
aggregateErrors(dryRunErrors, msg);
continue;
}
try
{
id = ndn::io::load<ndn::IdentityCertificate>(in);
}
catch (const std::runtime_error& error)
{
// do nothing
}
if (!static_cast<bool>(id)) {
std::string msg = "Malformed certificate file " + certfilePath.native();
if (!isDryRun)
{
throw ConfigFile::Error(msg);
}
aggregateErrors(dryRunErrors, msg);
continue;
}
in.close();
}
std::string keyNameForLogging;
if (static_cast<bool>(id))
keyNameForLogging = id->getPublicKeyName().toUri();
else
{
keyNameForLogging = "wildcard";
NFD_LOG_WARN("Wildcard identity is intended for demo purpose only and " <<
"SHOULD NOT be used in production environment");
}
const ConfigSection* privileges = 0;
try
{
privileges = &authIt->second.get_child("privileges");
}
catch (const std::runtime_error& error)
{
std::string msg = "No privileges section found for certificate file " +
certfile + " (" + keyNameForLogging + ")";
if (!isDryRun)
{
throw ConfigFile::Error(msg);
}
//.........这里部分代码省略.........