コード例 #1
0
void ColladaBodyLoaderImpl::throwException(const string& message)
{
    *os << message << endl;
    ValueNode::SyntaxException error;
    error.setMessage(message);
    throw error;
}
コード例 #2
0
ファイル: YAMLReader.cpp プロジェクト: s-nakaoka/choreonoid
void YAMLReaderImpl::onScalar(yaml_event_t& event)
{
    if(debugTrace){
        cout << "YAMLReaderImpl::onScalar()" << endl;
    }

    yaml_char_t* value = event.data.scalar.value;
    size_t length = event.data.scalar.length;

    if(nodeStack.empty()){
        ValueNode::SyntaxException ex;
        ex.setMessage(_("Scalar value cannot be put on the top-level text position"));
        const yaml_mark_t& start_mark = event.start_mark;
        ex.setPosition(start_mark.line, start_mark.column);
        throw ex;
    }

    NodeInfo& info = nodeStack.top();
    ValueNodePtr& parent = info.node;

    ScalarNode* scalar = 0;
     
    if(parent->isMapping()){
        if(info.key.empty()){
            info.key = string((char*)value, length);
            if(info.key.empty()){
                ValueNode::SyntaxException ex;
                ex.setMessage(_("empty key"));
                const yaml_mark_t& start_mark = event.start_mark;
                ex.setPosition(start_mark.line, start_mark.column);
                throw ex;
            }
        } else {
            scalar = createScalar(event);
        }
    } else if(parent->isListing()){
        scalar = createScalar(event);
    }
    if(scalar){
        addNode(scalar, event);
        if(event.data.scalar.anchor){
            setAnchor(scalar, event.data.scalar.anchor, event.start_mark);
        }
    }
}
コード例 #3
0
ファイル: YAMLReader.cpp プロジェクト: s-nakaoka/choreonoid
void YAMLReaderImpl::addNode(ValueNode* node, yaml_event_t& event)
{
    NodeInfo& info = nodeStack.top();
    ValueNode* parent = info.node;

    if(parent->isListing()){
        Listing* listing = static_cast<Listing*>(parent);
        listing->append(node);

    } else if(parent->isMapping()){

        Mapping* mapping = static_cast<Mapping*>(parent);

        if(info.key == "<<"){
            if(node->isMapping()){
                mapping->insert(static_cast<Mapping*>(node));
            } else if(node->isListing()){
                Listing* listing = static_cast<Listing*>(node);
                for(auto& element : *listing){
                    if(element->isMapping()){
                        mapping->insert(static_cast<Mapping*>(element.get()));
                    } else {
                        ValueNode::SyntaxException ex;
                        ex.setMessage(_("An element to merge by the \"<<\" key must be a mapping"));
                        const yaml_mark_t& start_mark = event.start_mark;
                        ex.setPosition(start_mark.line, start_mark.column);
                        throw ex;
                    }
                }
            } else {
                ValueNode::SyntaxException ex;
                ex.setMessage(_("A value to merge by the \"<<\" key must be mapping or listing"));
                const yaml_mark_t& start_mark = event.start_mark;
                ex.setPosition(start_mark.line, start_mark.column);
                throw ex;
            }
        }
        
        mapping->insert(info.key, node);
        info.key.clear();
    }
}