Commit | Line | Data |
43165725 |
1 | #include "mouse.h"\r |
2 | \r |
3 | #define CHECK_INSTANCE(instance) STMT_START{ \ |
4 | if(!(SvROK(instance) && SvTYPE(SvRV(instance)) == SVt_PVHV)){ \ |
5 | croak("Invalid object for instance managers"); \ |
6 | } \ |
7 | } STMT_END |
8 | |
9 | SV* |
10 | mouse_instance_create(pTHX_ HV* const stash) { |
11 | assert(stash); |
12 | return sv_bless( newRV_noinc((SV*)newHV()), stash ); |
13 | } |
14 | |
15 | SV* |
16 | mouse_instance_clone(pTHX_ SV* const instance) { |
17 | HV* proto; |
18 | assert(instance); |
19 | |
20 | CHECK_INSTANCE(instance); |
21 | proto = newHVhv((HV*)SvRV(instance)); |
22 | return sv_bless( newRV_noinc((SV*)proto), SvSTASH(SvRV(instance)) ); |
23 | } |
24 | |
25 | bool |
26 | mouse_instance_has_slot(pTHX_ SV* const instance, SV* const slot) { |
27 | assert(instance); |
28 | assert(slot); |
29 | CHECK_INSTANCE(instance); |
30 | return hv_exists_ent((HV*)SvRV(instance), slot, 0U); |
31 | } |
32 | |
33 | SV* |
34 | mouse_instance_get_slot(pTHX_ SV* const instance, SV* const slot) { |
35 | HE* he; |
36 | assert(instance); |
37 | assert(slot); |
38 | CHECK_INSTANCE(instance); |
39 | he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U); |
40 | return he ? HeVAL(he) : NULL; |
41 | } |
42 | |
43 | SV* |
44 | mouse_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) { |
45 | HE* he; |
46 | SV* sv; |
47 | assert(instance); |
48 | assert(slot); |
49 | assert(value); |
50 | CHECK_INSTANCE(instance); |
51 | he = hv_fetch_ent((HV*)SvRV(instance), slot, TRUE, 0U); |
52 | sv = HeVAL(he); |
53 | sv_setsv_mg(sv, value); |
54 | return sv; |
55 | } |
56 | |
57 | SV* |
58 | mouse_instance_delete_slot(pTHX_ SV* const instance, SV* const slot) { |
59 | assert(instance); |
60 | assert(slot); |
61 | CHECK_INSTANCE(instance); |
62 | return hv_delete_ent((HV*)SvRV(instance), slot, 0, 0U); |
63 | } |
64 | |
65 | void |
66 | mouse_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) { |
67 | HE* he; |
68 | assert(instance); |
69 | assert(slot); |
70 | CHECK_INSTANCE(instance); |
71 | he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U); |
72 | if(he){ |
73 | sv_rvweaken(HeVAL(he)); |
74 | } |
75 | } |
76 | \r |