Skip to content
This repository
branch: jit_prototype
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 118 lines (78 sloc) 2.441 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
/*
Copyright (C) 2001-2011, Parrot Foundation.

=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 Parrot_hash_key_to_pmc(INTERP, attrs->parrot_hash, attrs->bucket->key);
    }

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

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


    VTABLE INTVAL get_integer() {
        return -1;
    }

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

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

        return Parrot_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 cinoptions='\:2=2' :
 */

Something went wrong with that request. Please try again.