In Files

  • syck/rubyext.c

Parent

Object::Syck::Node

Define YAML::Syck::Node class

Attributes

emitter[RW]
kind[R]
resolver[RW]
type_id[R]
value[R]

Public Instance Methods

initialize_copy(p1) click to toggle source

Cloning method for all node types

 
               VALUE
syck_node_init_copy(VALUE copy, VALUE orig)
{
    SyckNode *copy_n;
    SyckNode *orig_n;

    if ( copy == orig )
        return copy;

    if ( TYPE( orig ) != T_DATA )
    {
        rb_raise( rb_eTypeError, "wrong argument type" );
    }

    Data_Get_Struct( orig, SyckNode, orig_n );
    Data_Get_Struct( copy, SyckNode, copy_n );
    MEMCPY( copy_n, orig_n, SyckNode, 1 );
    return copy;
}
            
transform() click to toggle source

YAML::Syck::Node.transform

 
               VALUE
syck_node_transform(VALUE self)
{
    VALUE t;
    SyckNode *n = NULL;
    SyckNode *orig_n;
    Data_Get_Struct(self, SyckNode, orig_n);
    t = Data_Wrap_Struct( cNode, syck_node_mark, syck_free_node, 0 );

    switch (orig_n->kind)
    {
        case syck_map_kind:
            {
                int i;
                DATA_PTR(t) = n = syck_alloc_map();
                for ( i = 0; i < orig_n->data.pairs->idx; i++ )
                {
                    syck_map_add( n, rb_funcall( syck_map_read( orig_n, map_key, i ), s_transform, 0 ),
                                     rb_funcall( syck_map_read( orig_n, map_value, i ), s_transform, 0 ) );
                }
            }
        break;

        case syck_seq_kind:
            {
                int i;
                DATA_PTR(t) = n = syck_alloc_seq();
                for ( i = 0; i < orig_n->data.list->idx; i++ )
                {
                    syck_seq_add( n, rb_funcall( syck_seq_read( orig_n, i ), s_transform, 0 ) );
                }
            }
        break;

        case syck_str_kind:
            DATA_PTR(t) = n = syck_new_str2( orig_n->data.str->ptr, orig_n->data.str->len, orig_n->data.str->style );
        break;
    }

    if ( orig_n->type_id != NULL )
    {
        n->type_id = syck_strndup( orig_n->type_id, strlen( orig_n->type_id ) );
    }
    if ( orig_n->anchor != NULL )
    {
        n->anchor = syck_strndup( orig_n->anchor, strlen( orig_n->anchor ) );
    }
    n->id = t;
    return rb_funcall( oDefaultResolver, s_node_import, 1, t );
}
            
type_id=(p1) click to toggle source

YAML::Syck::Node#type_id=

 
               VALUE
syck_node_type_id_set(VALUE self, VALUE type_id)
{
    SyckNode *node;
    Data_Get_Struct( self, SyckNode, node );

    S_FREE( node->type_id );

    if ( !NIL_P( type_id ) ) {
        StringValue( type_id );
        node->type_id = syck_strndup( RSTRING_PTR(type_id), RSTRING_LEN(type_id) );
    }

    rb_iv_set( self, "@type_id", type_id );
    return type_id;
}