/*
Copyright (C) 2001-2009, Parrot Foundation.
$Id: hashiteratorkey.pmc 45219 2010-03-28 01:11:50Z petdance $

=head1 NAME

src/pmc/hashiteratorkey.pmc - accessor for single value during hash iteration.

=head1 DESCRIPTION

Single (key,value) pair.


=head1 Methods

=over 4

=cut

*/

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

pmclass HashIteratorKey no_ro auto_attrs {
    ATTR Hash        *parrot_hash; /* Underlying parrot's hash */
    ATTR HashBucket  *bucket;      /* Current bucket from HashItertor */

/*

=item C<get_pmc()>

Get "key".

=cut

*/
    VTABLE PMC* get_pmc() {
        Parrot_HashIteratorKey_attributes *attrs =
                PARROT_HASHITERATORKEY(SELF);

        /* TT #1080 & TT #1081 Wallpapering problem with NULL attributes */
        if (!attrs->parrot_hash || !attrs->bucket)
            return PMCNULL;

        return hash_key_to_pmc(INTERP, attrs->parrot_hash, attrs->bucket->key);
    }

    METHOD key() {
        PMC *ret = SELF.get_pmc();
        RETURN(PMC* ret);
    }

    METHOD value() {
        Parrot_HashIteratorKey_attributes *attrs =
                PARROT_HASHITERATORKEY(SELF);
        PMC *ret = hash_value_to_pmc(INTERP, attrs->parrot_hash, attrs->bucket->value);
        RETURN(PMC* ret);
    }


    VTABLE INTVAL get_integer() {
        return -1;
    }

    VTABLE STRING* get_string() {
        Parrot_HashIteratorKey_attributes *attrs =
                PARROT_HASHITERATORKEY(SELF);

        /* TT #1080 & TT #1081 Wallpapering problem with NULL attributes */
        if (!attrs->parrot_hash || !attrs->bucket)
            return CONST_STRING(INTERP, "");

        return hash_key_to_string(INTERP, attrs->parrot_hash, attrs->bucket->key);
    }

/*

=item C<set_pointer_keyed_int()>

Set pointers to Hash and HashBucket. Not really part of public API.

=cut

*/
    VTABLE void set_pointer_keyed_int(INTVAL key, void *value) {
        Parrot_HashIteratorKey_attributes *attrs =
                PARROT_HASHITERATORKEY(SELF);

        PARROT_ASSERT_MSG(value, "Can't set NULL pointer into HashIteratorKey");

        if (key == 0) {
            attrs->parrot_hash = (Hash*)value;
        }
        else if (key == 1) {
            attrs->bucket = (HashBucket*)value;
        }
    }

}

/*

=back

=cut

*/

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

