当前位置: 首页>>代码示例>>C++>>正文


C++ Section::at方法代码示例

本文整理汇总了C++中Section::at方法的典型用法代码示例。如果您正苦于以下问题:C++ Section::at方法的具体用法?C++ Section::at怎么用?C++ Section::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Section的用法示例。


在下文中一共展示了Section::at方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: visit_Section

 bool visit_Section(Section & s)
 {
     str_type base_dir = this->_base_dir;
     if(s.has_key("__base_dir__"))
     {
         str_type section_base_dir = s.at("__base_dir__");
         if(section_base_dir.size() > 0)
         {
             base_dir = section_base_dir;
         }
     }
     str_type norm_base_dir = this->_normpath(base_dir);
     //std::cout << "s<" << s << "> " << base_dir << " : " << this->_base_dir << std::endl;
     if(base_dir.size() > 0 && norm_base_dir != this->_base_dir)
     {
         ResetBaseDirVisitor reset_base_dir_visitor(base_dir, this->_reset);
         s.accept(reset_base_dir_visitor);
         return false;
     }
     return true;
 }
开发者ID:simone-campagna,项目名称:Configment,代码行数:21,代码来源:section.cpp

示例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");
                }
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:simone-campagna,项目名称:Configment,代码行数:101,代码来源:section.cpp


注:本文中的Section::at方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。