/*
 *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
 *  CVS Info
 *     $Id: unmanagedstruct.pmc,v 1.11 2003/08/28 13:17:01 leo Exp $
 *  Overview:
 *     PMC class to hold structs that parrot's not responsible for
 *     disposing of.
 *
 *     Buffer can be accessed using keyed assignments to PMC.  Out of
 *     bounds access will very likely segfault.
 *
 *  Data Structure and Algorithms:
 *  History:
 *     Initial revision by sean 2002/08/04
 *  Notes:
 *  References:
 */

#include "parrot/parrot.h"
#include "parrot/method_util.h"
#include "parrot/pobj.h"

enum {
    PObj_UnManagedStruct_my_memory_FLAG = PObj_private0_FLAG
};

pmclass UnManagedStruct need_ext {

    INTVAL is_equal (PMC* value) {
	return (SELF->vtable == value->vtable
		&& PMC_data(SELF) == PMC_data(value));
    }

    INTVAL defined () {
	return PMC_data(SELF) != NULL;
    }

    /* May cause segfaults if value is out of bounds */
    INTVAL get_integer_keyed(PMC* key) {
	INTVAL ix;

	if (!key)
            return -1;
	ix = key_integer(INTERP, key);
	if (ix < 0)
            return -1;
	return  (unsigned char)((char *)PMC_data(SELF))[ix];

    }

    /* May cause segfaults if value is out of bounds */
    void set_integer_keyed (PMC* key, INTVAL value) {
	INTVAL ix;

	if (!key)
            return;
	ix = key_integer(INTERP, key);
	if (ix < 0)
            return;
	((char *)PMC_data(SELF))[ix]=(0xff & value);
	return;
    }

}
