本文整理汇总了C++中section::get_name方法的典型用法代码示例。如果您正苦于以下问题:C++ section::get_name方法的具体用法?C++ section::get_name怎么用?C++ section::get_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类section
的用法示例。
在下文中一共展示了section::get_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validate_section
void section_schema::validate_section(section §, schema_mode mode) const
{
/*
* Here should be done:
* - check if section has proper options (compare by names) - depends on mode
* - for options with given schema call validate on that option
* - for missing options from schema (relaxed mode) add string options with
* default value
*/
// firstly go through option schemas
for (auto &opt : options_) {
bool contains = sect.contains(opt->get_name());
if (contains) {
// even if option is not mandatory, we execute validation of option (both modes)
opt->validate_option(sect[opt->get_name()]);
} else if (opt->is_mandatory()) {
// mandatory option is not present in given section (both modes)
throw validation_exception(
"Mandatory option '" + opt->get_name() + "' is missing in section '" + sect.get_name() + "'");
} else {
// option is not mandatory and not in given section
// => add option with default value
sect.add_option(opt->get_name(), opt->get_default_value());
// validate added option, so type of the value could be changed to nonstring type
opt->validate_option(sect[opt->get_name()]);
}
}
// secondly go through options
for (auto &opt : sect) {
bool contains = this->contains(opt.get_name());
// if section_schema contains option everything is fine, we handled this above
if (contains) {
continue;
}
// we have strict mode and option which is not in section_schema
if (mode == schema_mode::strict) {
throw validation_exception("Option '" + opt.get_name() + "' not specified in schema");
}
}
}