/*
Copyright (C) 2001-2010, Parrot Foundation.
$Id: packfilefixupentry.pmc 47722 2010-06-20 08:51:14Z bacek $

=head1 NAME

src/pmc/packfilefixupentry.pmc - PackfileFixupEntry PMC

=head1 DESCRIPTION

This class implements a PackfileFixupEntry object.  It is an element in the
PackfileFixupTable segment of the .pbc file.  See PDD13 for a design spec.

=head2 Methods

=over 4

=cut

*/

/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */

pmclass PackfileFixupEntry auto_attrs {
    ATTR INTVAL     type;
    ATTR STRING     *name;
    ATTR INTVAL     offset;


/*

=item C<void init()>

Initialize PackfileFixupEntry.

=cut

*/
    VTABLE void init() {
        Parrot_PackfileFixupEntry_attributes * attrs =
                PMC_data_typed(SELF, Parrot_PackfileFixupEntry_attributes*);

        attrs->name = Parrot_str_new_noinit(INTERP, enum_stringrep_one, 0);

        PObj_custom_mark_SET(SELF);
    }

    VTABLE void init_pmc(PMC *init) {
        Parrot_PackfileFixupEntry_attributes * attrs =
                PMC_data_typed(SELF, Parrot_PackfileFixupEntry_attributes*);
        STRING *name    = CONST_STRING_GEN(INTERP, "name");
        STRING *type    = CONST_STRING_GEN(INTERP, "type");
        STRING *offset  = CONST_STRING_GEN(INTERP, "offset");

        attrs->name = VTABLE_get_string(INTERP,
                        VTABLE_get_pmc_keyed_str(INTERP, init, name));
        attrs->type = VTABLE_get_integer(INTERP,
                        VTABLE_get_pmc_keyed_str(INTERP, init, type));
        attrs->offset = VTABLE_get_integer(INTERP,
                        VTABLE_get_pmc_keyed_str(INTERP, init, offset));

        PObj_custom_mark_SET(SELF);
    }

/*

=item C<void mark()>

Marks the object as live.

=cut

*/

    VTABLE void mark() {
        Parrot_PackfileFixupEntry_attributes * const attrs =
                PARROT_PACKFILEFIXUPENTRY(SELF);

        Parrot_gc_mark_STRING_alive(INTERP, attrs->name);
    }

/*

=item C<void set_pointer(void *pointer)>

Initialize from PackFile_FixupEntry pointer.

=cut

*/

    VTABLE void set_pointer(void * pointer) {
        Parrot_PackfileFixupEntry_attributes * const attrs =
                PARROT_PACKFILEFIXUPENTRY(SELF);
        PackFile_FixupEntry *entry = (PackFile_FixupEntry*)pointer;

        attrs->type     = entry->type;
        attrs->name     = Parrot_str_new_init(INTERP, entry->name,
                strlen(entry->name), PARROT_FIXED_8_ENCODING,
                PARROT_BINARY_CHARSET, 0);
        attrs->offset   = entry->offset;
    }

/*

=item C<void *get_pointer()>

Create PackFile_FixupEntry* from self.

=cut

*/
    VTABLE void *get_pointer() {
        Parrot_PackfileFixupEntry_attributes * const attrs =
                PARROT_PACKFILEFIXUPENTRY(SELF);
        PackFile_FixupEntry                  * const entry =
                mem_gc_allocate_zeroed_typed(INTERP, PackFile_FixupEntry);

        entry->type     = attrs->type;
        entry->name     = strdup(Parrot_str_cstring(INTERP, attrs->name));
        entry->offset   = attrs->offset;
        return entry;
    }


/*

=item C<STRING *get_string()>

Fetch the label field of the fixup entry.

=cut

*/
    VTABLE STRING *get_string() {
        return PARROT_PACKFILEFIXUPENTRY(SELF)->name;
    }

/*

=item C<void set_string_native(STRING *value)>

Set the label field of the fixup entry.

=cut

*/
    VTABLE void set_string_native(STRING *value) {
        SETATTR_PackfileFixupEntry_name(INTERP, SELF, value);
    }


/*

=item C<INTVAL get_integer()>

Fetch the offset field of the fixup entry.

=cut

*/
    VTABLE INTVAL get_integer() {
        return PARROT_PACKFILEFIXUPENTRY(SELF)->offset;
    }


/*

=item C<void set_integer_native(INTVAL offset)>

Set the offset field of the fixup entry.

=cut

*/
    VTABLE void set_integer_native(INTVAL offset) {
        SETATTR_PackfileFixupEntry_offset(INTERP, SELF, offset);
    }


/*

=item C<INTVAL get_type()>

Fetch the type field of the fixup entry.

=cut

*/
    METHOD get_type() {
        const INTVAL rv = PARROT_PACKFILEFIXUPENTRY(SELF)->type;
        RETURN(INTVAL rv);
    }


/*

=item C<void set_type(INTVAL type)>

Set the type field of the fixup entry.

=cut

*/
    METHOD set_type(INTVAL type) {
        SETATTR_PackfileFixupEntry_type(INTERP, SELF, type);
    }

}
/*

=back

=cut

*/

/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
