Пример #1
0
YamlMapping* YamlMapping::openMapping(const std::string& key, bool doOverwrite)
{
    if(!isValid()){
        throwNotMappingException();
    }

    YamlMapping* mapping = 0;
    const string uKey(toUtf8(key));
    iterator p = values.find(uKey);
    if(p != values.end()){
        YamlNode* node = p->second.get();
        if(node->type() != YAML_MAPPING){
            values.erase(p);
        } else {
            mapping = static_cast<YamlMapping*>(node);
            if(doOverwrite){
                mapping->clear();
            }
            mapping->indexInMapping = indexCounter++;
        }
    }

    if(!mapping){
        mapping = new YamlMapping();
        mapping->doubleFormat_ = doubleFormat_;
        insertSub(uKey, mapping);
    }

    return mapping;
}
Пример #2
0
YamlSequence* YamlMapping::openSequence(const std::string& key, bool doOverwrite)
{
    if(!isValid()){
        throwNotMappingException();
    }

    YamlSequence* sequence = 0;
    const string uKey(toUtf8(key));
    iterator p = values.find(uKey);
    if(p != values.end()){
        YamlNode* node = p->second.get();
        if(node->type() != YAML_SEQUENCE){
            values.erase(p);
        } else {
            sequence = static_cast<YamlSequence*>(node);
            if(doOverwrite){
                sequence->clear();
            }
            sequence->indexInMapping = indexCounter++;
        }
    }

    if(!sequence){
        sequence = new YamlSequence();
        sequence->doubleFormat_ = doubleFormat_;
        insertSub(uKey, sequence);
    }

    return sequence;
}
Пример #3
0
YamlSequence* YamlMapping::findSequence(const std::string& key) const
{
    if(!isValid()){
        throwNotMappingException();
    }
    const_iterator p = values.find(toUtf8(key));
    if(p != values.end()){
        YamlNode* node = p->second.get();
        if(node->type() == YAML_SEQUENCE){
            return static_cast<YamlSequence*>(node);
        }
    }
    return invalidSequence.get();
}
Пример #4
0
/**
   This is for internal use. Text are not converted to UTF-8.
*/
void YamlMapping::writeSub(const std::string &key, const char* text, size_t length, YamlStringStyle stringStyle)
{
    const string uKey(toUtf8(key));
    iterator p = values.find(uKey);
    if(p == values.end()){
        insertSub(uKey, new YamlScalar(text, length, stringStyle));
    } else {
        YamlNode* node = p->second.get();
        if(node->type() == YAML_SCALAR){
            YamlScalar* scalar = static_cast<YamlScalar*>(node);
            scalar->stringValue = string(text, length);
            scalar->stringStyle = stringStyle;
            scalar->indexInMapping = indexCounter++;
        } else {
            throwNotScalrException();
        }
    }
}