3 #define CHECK_INSTANCE(instance) STMT_START{ \
4 if(!(SvROK(instance) && SvTYPE(SvRV(instance)) == SVt_PVHV)){ \
5 croak("Invalid object for instance managers"); \
10 mouse_instance_create(pTHX_ HV* const stash) {
12 return sv_bless( newRV_noinc((SV*)newHV()), stash );
16 mouse_instance_clone(pTHX_ SV* const instance) {
20 CHECK_INSTANCE(instance);
21 proto = newHVhv((HV*)SvRV(instance));
22 return sv_bless( newRV_noinc((SV*)proto), SvSTASH(SvRV(instance)) );
26 mouse_instance_has_slot(pTHX_ SV* const instance, SV* const slot) {
29 CHECK_INSTANCE(instance);
30 return hv_exists_ent((HV*)SvRV(instance), slot, 0U);
34 mouse_instance_get_slot(pTHX_ SV* const instance, SV* const slot) {
38 CHECK_INSTANCE(instance);
39 he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U);
40 return he ? HeVAL(he) : NULL;
44 mouse_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) {
50 CHECK_INSTANCE(instance);
51 he = hv_fetch_ent((HV*)SvRV(instance), slot, TRUE, 0U);
53 sv_setsv_mg(sv, value);
58 mouse_instance_delete_slot(pTHX_ SV* const instance, SV* const slot) {
61 CHECK_INSTANCE(instance);
62 return hv_delete_ent((HV*)SvRV(instance), slot, 0, 0U);
66 mouse_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) {
70 CHECK_INSTANCE(instance);
71 he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U);
73 sv_rvweaken(HeVAL(he));