/* The public interface declaration */

/**
 * A copy constructor for any YAML event.
 * 
 * An application is responsible for freeing any buffers associated with the
 * produced event object using the yaml_event_delete() function.
 *
 * @param[in]    in    The event object to be copied.
 * @param[out]   out   An empty event object.
 * 
 * @returns @c 1 if the function succeeded, @c 0 on error.
 */

YAML_DECLARE(int)
yaml_event_initialize(yaml_event_t *out, yaml_event_t *in);


/* The source file code, I believe it would belong in api.c */

YAML_DECLARE(int)
yaml_event_initialize(yaml_event_t *out, yaml_event_t *in) {
    switch((*in).type) {
        case YAML_STREAM_START_EVENT:
            if(!yaml_stream_start_event_initialize(&(*out),
                (*in).data.stream_start.encoding))
                goto error;
            break;
        case YAML_STREAM_END_EVENT:
            if(!yaml_stream_end_event_initialize(&(*out)))
                goto error;
            break;
        case YAML_DOCUMENT_START_EVENT:
            if(!yaml_document_start_event_initialize(&(*out),
                (*in).data.document_start.version_directive,
                (*in).data.document_start.tag_directives.start,
                (*in).data.document_start.tag_directives.end,
                (*in).data.document_start.implicit)) 
                goto error;
            break;
        case YAML_DOCUMENT_END_EVENT:
            if(!yaml_document_end_event_initialize(&(*out),
                (*in).data.document_end.implicit)) 
                goto error;
            break;
        case YAML_ALIAS_EVENT:
            if(!yaml_alias_event_initialize(&(*out), 
                (*in).data.alias.anchor)) 
                goto error;
            break;
        case YAML_SCALAR_EVENT:
            if(!yaml_scalar_event_initialize(&(*out),
                (*in).data.scalar.anchor, (*in).data.scalar.tag,
                (*in).data.scalar.value, (*in).data.scalar.length,
                (*in).data.scalar.plain_implicit,
                (*in).data.scalar.quoted_implicit,
                (*in).data.scalar.style)) 
                goto error;
            break;
        case YAML_SEQUENCE_START_EVENT:
            if(!yaml_sequence_start_event_initialize(&(*out),
                (*in).data.sequence_start.anchor,
                (*in).data.sequence_start.tag,
                (*in).data.sequence_start.implicit,
                (*in).data.sequence_start.style))
                goto error;
            break;
        case YAML_SEQUENCE_END_EVENT:
            if(!yaml_sequence_end_event_initialize(&(*out))) 
                goto error;
            break;
        case YAML_MAPPING_START_EVENT:
            if(!yaml_mapping_start_event_initialize(&(*out),
                (*in).data.mapping_start.anchor,
                (*in).data.mapping_start.tag,
                (*in).data.mapping_start.implicit,
                (*in).data.mapping_start.style))
                goto error;
            break;
        case YAML_MAPPING_END_EVENT:
            if(!yaml_mapping_end_event_initialize(&(*out))) 
                goto error;
            break;
        default: goto error; break;
    }
    return 1;

error:
    return 0;
}
