File Coverage

t/typemap/object/backref.xsi
Criterion Covered Total %
statement 21 30 70.0
branch 15 42 35.7
condition n/a
subroutine n/a
pod n/a
total 36 72 50.0


line stmt bran cond sub pod time code
1             MODE: INLINE
2              
3             struct BRUnit : panda::Refcnt {
4             int id;
5              
6             BRUnit (int id) : id(id) {}
7              
8             virtual BRUnit* clone () {
9             //printf("br unit clone\n");
10             return new BRUnit(id);
11             }
12              
13             virtual ~BRUnit () {
14             //printf("~BRUnit\n");
15             dcnt.c++;
16             }
17             };
18              
19             struct BRUnitEnabled : BRUnit, Backref {
20             using BRUnit::BRUnit;
21              
22             BRUnit* clone () override {
23             //printf("BRUnitEnabled::clone()\n");
24             return new BRUnitEnabled(this->id);
25             }
26              
27             ~BRUnitEnabled () { Backref::dtor(); }
28             };
29              
30             struct BRStorage {
31             BRStorage () : unit(NULL) {}
32              
33             const panda::iptr& get_unit () const { return unit; }
34              
35             void set_unit (BRUnit* val) { unit = val; }
36             void set_unit_with_id (int id) { unit = new BRUnit(id); }
37             void set_unit_with_id2 (int id) { unit = new BRUnitEnabled(id); }
38              
39             virtual ~BRStorage () {
40             //printf("~BRStorage\n");
41             dcnt.c++;
42             }
43              
44             virtual BRStorage* clone () {
45             //printf("BRStorage::clone()\n");
46             BRStorage* ret = new BRStorage();
47             ret->set_unit(unit->clone());
48             return ret;
49             }
50             private:
51             panda::iptr unit;
52             };
53              
54             namespace xs {
55             template <> struct Typemap : TypemapObject {
56             static std::string package () { return "MyTest::BRUnit"; }
57             static BRUnit* dup (BRUnit* obj) { return obj->clone(); }
58             };
59            
60             template <> struct Typemap : TypemapObject {
61             static std::string package () { return "MyTest::BRStorage"; }
62             static BRStorage* dup (BRStorage* obj) { return obj->clone(); }
63             };
64             }
65              
66              
67             MODULE = MyTest::Typemap::Object PACKAGE = MyTest::BRUnit
68             PROTOTYPES: DISABLE
69              
70 4           BRUnit* BRUnit::new (int id)
71 2 50          
72 2 50         BRUnit* new_enabled (SV* CLASS, int id) {
    50          
73 14           PROTO = CLASS;
74 7 50         RETVAL = new BRUnitEnabled(id);
75 7 50         }
    50          
76              
77 1           void BRUnit::retain ()
78              
79             uint64_t BRUnit::br_addr () {
80 0 0         auto xsbr = panda::dyn_cast(THIS);
81 0 0         if (!xsbr) throw "no xsbr";
82 0           RETVAL = (uint64_t)xsbr->svobj;
83             }
84              
85             int BRUnit::rcnt_c () {
86 0           RETVAL = THIS->refcnt();
87             }
88              
89             int BRUnit::rcnt_sv () {
90 0 0         auto xsbr = panda::dyn_cast(THIS);
91 0 0         if (!xsbr) throw "no xsbr";
92             //printf("xsbr=%llu\n", xsbr);
93 0           RETVAL = SvREFCNT(xsbr->svobj);
94             }
95              
96             int BRUnit::id (SV* newval = NULL) {
97 10 50         if (newval) THIS->id = SvIV(newval);
    0          
    0          
98 10           RETVAL = THIS->id;
99             }
100              
101             void BRUnit::DESTROY () {
102             //printf("BRUnit::DESTROY id=%d\n", THIS->id);
103 11           dcnt.perl++;
104 11 50         }
105              
106              
107             MODULE = MyTest::Typemap::Object PACKAGE = MyTest::BRStorage
108             PROTOTYPES: DISABLE
109              
110 8           BRStorage* BRStorage::new ()
111 4 50          
112 4 50         BRUnit* BRStorage::unit (BRUnit* unit = NULL) {
    50          
113 30           if (items > 1) {
114 21 100         THIS->set_unit(unit);
115 12 50         XSRETURN_UNDEF;
116 12           }
117             RETVAL = THIS->get_unit();
118 9           }
119              
120             void BRStorage::set_unit_with_id (int id) : ALIAS(set_unit_with_id2=1) {
121 0 0         if (ix == 1) THIS->set_unit_with_id2(id);
122 0           else THIS->set_unit_with_id(id);
123             }
124              
125             void BRStorage::DESTROY () {
126             //printf("BRStorage::DESTROY\n");
127 4           dcnt.perl++;
128 4 50         }
129