本文整理汇总了C++中Section::add_default_key方法的典型用法代码示例。如果您正苦于以下问题:C++ Section::add_default_key方法的具体用法?C++ Section::add_default_key怎么用?C++ Section::add_default_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Section
的用法示例。
在下文中一共展示了Section::add_default_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create_template_section
void Section::create_template_section(Section & section) const
{
for(Section::const_iterator i = this->begin(); i != this->end(); ++i)
{
const Object & ps_key = i->first;
const Object & ps_val = i->second;
const Section * ps_sub_section = dynamic_cast<const Section *>(&ps_val.get_object());
if(ps_sub_section != 0)
{
Section subsection;
ps_sub_section->create_template_section(subsection);
//std::cout << "adding section " << ps_key << " = " << subsection << std::endl;
section[ps_key] = subsection;
}
else
{
KeyValidator key_validator = _make_KeyValidator(ps_val);
bool key_validator_has_default = key_validator.has_default();
if(key_validator_has_default)
{
//std::cout << "adding default key " << ps_key << " = " << key_validator.get_default() << std::endl;
section.add_default_key(ps_key, key_validator.get_default());
section.add_key(ps_key, key_validator.get_default());
}
else
{
//std::cout << "adding undefined key " << ps_key << " = " << UNDEFINED << std::endl;
section.add_key(ps_key, UNDEFINED);
}
}
}
//std::cout << "-> " << section << std::endl;
}
示例2: _validate
void Section::_validate(Section & section, Section & result)
{
if(!this->has_key("__base_dir__"))
{
this->add_key("__base_dir__", configment::unrepr_key_validator("string(default=\"\")"));
this->_lst.remove("__base_dir__");
this->_lst.push_front("__base_dir__");
}
if(!this->has_key("__validate__"))
{
this->add_key("__validate__", configment::unrepr_key_validator("boolean(default=True)"));
this->_lst.remove("__validate__");
this->_lst.push_front("__validate__");
}
Str many_section_name("__many__");
typedef std::vector<Object> VEC_T;
VEC_T sub_sections;
bool has_many_section = false;
section._default_values.clear();
for(Section::const_iterator i = this->cbegin(); i != this->cend(); ++i)
{
const Object & ps_key = i->first;
const Object & ps_val = i->second;
const Section * ps_sub_section = dynamic_cast<const Section *>(&ps_val.get_object());
if(ps_sub_section != 0)
{
// this is a section
sub_sections.push_back(ps_key);
if(ps_key.operator ==(many_section_name))
{
has_many_section = true;
}
else
{
try
{
Object & pt_val = section.at(ps_key);
if(! pt_val.is<Section>())
{
_add_key_validation_error(result, ps_key, "it is a key, but it should a Section");
}
}
catch(KeyError)
{
// inserting section
section[ps_key] = Section();
}
}
}
else
{
//std::cout << "DBG: KEY_VALIDATOR: ps_key= " << ps_key << ", ps_val=" << ps_val << std::endl;
KeyValidator key_validator = _make_KeyValidator(ps_val);
//std::cout << "DBG: VAL: looking for key " << ps_key << std::endl;
bool key_validator_has_default = key_validator.has_default();
if(key_validator_has_default)
{
// inserting default value
//std::cout << "DBG: VAL: inserting default: " << ps_key.repr() << "=" << key_validator.get_default() << std::endl;
//...section[ps_key] = key_validator.get_default();
section.add_default_key(ps_key, key_validator.get_default());
}
try
{
Object & pt_val = section.at(ps_key);
if(pt_val.is<Section>())
{
_add_key_validation_error(result, ps_key, "is is a Section, but it should be a key");
}
else
{
str_type key = ps_key;
ValidationResult vr;
key_validator.validate(pt_val, vr);
if(vr)
{
std::ostringstream os;
os << vr;
_add_key_validation_error(result, key, os.str());
}
}
}
catch(KeyError)
{
if(key_validator_has_default)
{
section.add_key(ps_key, key_validator.get_default(), true);
}
else
{
//std::cout << "DBG: VAL: don't have a default for " << ps_key.repr() << std::endl;
//std::ostringstream os;
//os << parents << "::" << ps_key << " does not have a (default) value";
//vr.add_error(os.str());
_add_key_validation_error(result, ps_key, "does not have a (default) value");
}
}
}
}
//.........这里部分代码省略.........