| 1 |
|
| MODE: INLINE |
| 2 |
|
| |
| 3 |
|
| #include <vector> |
| 4 |
|
| |
| 5 |
|
| struct Point { |
| 6 |
|
| double x; |
| 7 |
|
| double y; |
| 8 |
|
| }; |
| 9 |
|
| |
| 10 |
|
| struct ShapeA { |
| 11 |
|
| size_t point_count() const { return points.size(); } |
| 12 |
|
| Point& get_point(size_t idx) { return points.at(idx); } |
| 13 |
|
| void add_point(const Point& pt) { points.push_back(pt); } |
| 14 |
|
| private: |
| 15 |
|
| std::vector<Point> points; |
| 16 |
|
| }; |
| 17 |
|
| |
| 18 |
|
| struct XSShapeA : public ShapeA { |
| 19 |
|
| void add_label(SV* maybe_label = nullptr) { |
| 20 |
|
| Sv label = maybe_label ? Sv{maybe_label} : Sv::undef; |
| 21 |
|
| labels.push_back(Ref::create(maybe_label)); |
| 22 |
|
| } |
| 23 |
|
| Ref& get_ref(size_t idx) { return labels.at(idx); } |
| 24 |
|
| private: |
| 25 |
|
| std::vector<Ref> labels; |
| 26 |
|
| }; |
| 27 |
|
| |
| 28 |
|
| |
| 29 |
|
| namespace xs { |
| 30 |
|
| template <> |
| 31 |
|
| struct Typemap<Point*> : TypemapObject<Point*, Point*, ObjectTypePtr, ObjectStorageMG> { |
| 32 |
|
| static std::string package () { return "MyTest::Cookbook::Point"; } |
| 33 |
|
| }; |
| 34 |
|
| |
| 35 |
|
| template <typename D> |
| 36 |
|
| struct Typemap<ShapeA*, D> : TypemapObject<ShapeA*, D, ObjectTypePtr, ObjectStorageMG> { |
| 37 |
|
| static std::string package () { return "MyTest::Cookbook::ShapeA"; } |
| 38 |
|
| }; |
| 39 |
|
| |
| 40 |
|
| template <> |
| 41 |
|
| struct Typemap<XSShapeA*> : Typemap<ShapeA*, XSShapeA*> { |
| 42 |
|
| static std::string package () { return "MyTest::Cookbook::ShapeB"; } |
| 43 |
|
| }; |
| 44 |
|
| |
| 45 |
|
| } |
| 46 |
|
| |
| 47 |
|
| static xs::Sv::payload_marker_t payload_marker_09; |
| 48 |
|
| |
| 49 |
|
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::Point |
| 50 |
|
| PROTOTYPES: DISABLE |
| 51 |
|
| |
| 52 |
|
| double Point::x(SV* new_val = nullptr) : ALIAS(y = 1) { |
| 53 |
0 |
| double* val = nullptr; |
| 54 |
0 |
▶ | switch(ix) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch(ix) { |
0 |
0 |
0 |
|
| 55 |
0 |
| case 1: val = &THIS->y; break; |
| 56 |
0 |
| default: val = &THIS->x; break; |
| 57 |
|
| } |
| 58 |
0 |
▶ | if (new_val) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (new_val) { |
0 |
0 |
0 |
|
| 59 |
0 |
| *val = SvNV(new_val); |
| 60 |
|
| } |
| 61 |
0 |
▶ | RETVAL = *val; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = *val; |
0 |
0 |
0 |
|
| 62 |
|
| } |
| 63 |
|
| |
| 64 |
|
| Point* Point::new(double x = 0, double y = 0) { |
| 65 |
0 |
| RETVAL = new Point{x, y}; |
| 66 |
0 |
▶ | } |
Branch: 1 branch
| Branch | True | False | Total |
| } |
0 |
0 |
0 |
|
| 67 |
0 |
▶ | |
Branch: 2 branches
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
0 |
0 |
0 |
|
| 68 |
|
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::ShapeA |
| 69 |
|
| PROTOTYPES: DISABLE |
| 70 |
|
| |
| 71 |
0 |
| size_t ShapeA::point_count() |
| 72 |
|
| |
| 73 |
|
| void ShapeA::get_point(size_t idx) { |
| 74 |
0 |
▶ | Object self{ST(0)}; |
Branch: 1 branch
| Branch | True | False | Total |
| Object self{ST(0)}; |
0 |
0 |
0 |
|
| 75 |
0 |
▶ | Array payload(self.payload(&payload_marker_09).obj); |
Branch: 1 branch
| Branch | True | False | Total |
| Array payload(self.payload(&payload_marker_09).obj); |
0 |
0 |
0 |
|
| 76 |
|
| |
| 77 |
0 |
▶ | auto& pt = THIS->get_point(idx); |
Branch: 1 branch
| Branch | True | False | Total |
| auto& pt = THIS->get_point(idx); |
0 |
0 |
0 |
|
| 78 |
0 |
▶ | auto pt_copy = new Point{pt.x, pt.y}; |
Branch: 1 branch
| Branch | True | False | Total |
| auto pt_copy = new Point{pt.x, pt.y}; |
0 |
0 |
0 |
|
| 79 |
0 |
▶ | auto wrapped_pt = xs::out<>(pt_copy); |
Branch: 1 branch
| Branch | True | False | Total |
| auto wrapped_pt = xs::out<>(pt_copy); |
0 |
0 |
0 |
|
| 80 |
0 |
▶ | mXPUSHs(wrapped_pt.detach()); |
Branch: 3 branches
| Branch | True | False | Total |
| mXPUSHs(wrapped_pt.detach()); |
0 |
0 |
0 |
| mXPUSHs(wrapped_pt.detach()); |
0 |
0 |
0 |
| mXPUSHs(wrapped_pt.detach()); |
0 |
0 |
0 |
|
| 81 |
|
| |
| 82 |
0 |
▶ | if (GIMME_V == G_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_ARRAY) { |
0 |
0 |
0 |
|
| 83 |
0 |
▶ | auto ref = payload.at(idx); |
Branch: 1 branch
| Branch | True | False | Total |
| auto ref = payload.at(idx); |
0 |
0 |
0 |
|
| 84 |
0 |
| Sv value = SvRV(ref); |
| 85 |
0 |
▶ | mXPUSHs(value.detach()); |
Branch: 3 branches
| Branch | True | False | Total |
| mXPUSHs(value.detach()); |
0 |
0 |
0 |
| mXPUSHs(value.detach()); |
0 |
0 |
0 |
| mXPUSHs(value.detach()); |
0 |
0 |
0 |
|
| 86 |
0 |
| } |
| 87 |
|
| } |
| 88 |
|
| |
| 89 |
|
| void ShapeA::add_point(Point* pt, SV* maybe_label = nullptr) { |
| 90 |
0 |
▶ | THIS->add_point(*pt); |
Branch: 1 branch
| Branch | True | False | Total |
| THIS->add_point(*pt); |
0 |
0 |
0 |
|
| 91 |
0 |
▶ | Object self{ST(0)}; |
Branch: 1 branch
| Branch | True | False | Total |
| Object self{ST(0)}; |
0 |
0 |
0 |
|
| 92 |
0 |
▶ | Array payload(self.payload(&payload_marker_09).obj); |
Branch: 1 branch
| Branch | True | False | Total |
| Array payload(self.payload(&payload_marker_09).obj); |
0 |
0 |
0 |
|
| 93 |
0 |
▶ | Sv label = maybe_label ? Sv{maybe_label} : Sv::undef; |
Branch: 2 branches
| Branch | True | False | Total |
| Sv label = maybe_label ? Sv{maybe_label} : Sv::undef; |
0 |
0 |
0 |
| Sv label = maybe_label ? Sv{maybe_label} : Sv::undef; |
0 |
0 |
0 |
|
| 94 |
0 |
▶ | Sv ref = Ref::create(maybe_label); |
Branch: 1 branch
| Branch | True | False | Total |
| Sv ref = Ref::create(maybe_label); |
0 |
0 |
0 |
|
| 95 |
0 |
▶ | payload.push(ref); |
Branch: 1 branch
| Branch | True | False | Total |
| payload.push(ref); |
0 |
0 |
0 |
|
| 96 |
|
| } |
| 97 |
|
| |
| 98 |
|
| Sv ShapeA::new() { |
| 99 |
0 |
▶ | auto shape = new ShapeA(); |
Branch: 1 branch
| Branch | True | False | Total |
| auto shape = new ShapeA(); |
0 |
0 |
0 |
|
| 100 |
0 |
▶ | Object obj = xs::out<>(shape, CLASS); |
Branch: 2 branches
| Branch | True | False | Total |
| Object obj = xs::out<>(shape, CLASS); |
0 |
0 |
0 |
| Object obj = xs::out<>(shape, CLASS); |
0 |
0 |
0 |
|
| 101 |
0 |
▶ | auto payload = Array::create(); |
Branch: 1 branch
| Branch | True | False | Total |
| auto payload = Array::create(); |
0 |
0 |
0 |
|
| 102 |
0 |
▶ | obj.payload_attach(payload, &payload_marker_09); |
Branch: 1 branch
| Branch | True | False | Total |
| obj.payload_attach(payload, &payload_marker_09); |
0 |
0 |
0 |
|
| 103 |
0 |
▶ | RETVAL = obj.ref(); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = obj.ref(); |
0 |
0 |
0 |
| RETVAL = obj.ref(); |
0 |
0 |
0 |
|
| 104 |
|
| } |
| 105 |
|
| |
| 106 |
|
| MODULE = MyTest::Cookbook PACKAGE = MyTest::Cookbook::ShapeB |
| 107 |
|
| PROTOTYPES: DISABLE |
| 108 |
|
| |
| 109 |
0 |
| XSShapeA* XSShapeA::new() |
| 110 |
0 |
▶ | |
Branch: 1 branch
| Branch | True | False | Total |
|
0 |
0 |
0 |
|
| 111 |
0 |
▶ | void XSShapeA::add_point(Point* pt, SV* maybe_label = nullptr) { |
Branch: 2 branches
| Branch | True | False | Total |
| void XSShapeA::add_point(Point* pt, SV* maybe_label = nullptr) { |
0 |
0 |
0 |
| void XSShapeA::add_point(Point* pt, SV* maybe_label = nullptr) { |
0 |
0 |
0 |
|
| 112 |
0 |
| THIS->add_point(*pt); |
| 113 |
0 |
| THIS->add_label(maybe_label); |
| 114 |
|
| } |
| 115 |
|
| |
| 116 |
|
| void XSShapeA::get_point(size_t idx) { |
| 117 |
0 |
▶ | auto& pt = THIS->get_point(idx); |
Branch: 1 branch
| Branch | True | False | Total |
| auto& pt = THIS->get_point(idx); |
0 |
0 |
0 |
|
| 118 |
0 |
▶ | auto pt_copy = new Point{pt.x, pt.y}; |
Branch: 1 branch
| Branch | True | False | Total |
| auto pt_copy = new Point{pt.x, pt.y}; |
0 |
0 |
0 |
|
| 119 |
0 |
▶ | auto wrapped_pt = xs::out<>(pt_copy); |
Branch: 1 branch
| Branch | True | False | Total |
| auto wrapped_pt = xs::out<>(pt_copy); |
0 |
0 |
0 |
|
| 120 |
0 |
▶ | mXPUSHs(wrapped_pt.detach()); |
Branch: 3 branches
| Branch | True | False | Total |
| mXPUSHs(wrapped_pt.detach()); |
0 |
0 |
0 |
| mXPUSHs(wrapped_pt.detach()); |
0 |
0 |
0 |
| mXPUSHs(wrapped_pt.detach()); |
0 |
0 |
0 |
|
| 121 |
0 |
▶ | if (GIMME_V == G_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (GIMME_V == G_ARRAY) { |
0 |
0 |
0 |
|
| 122 |
0 |
▶ | Sv value = SvRV(THIS->get_ref(idx)); |
Branch: 1 branch
| Branch | True | False | Total |
| Sv value = SvRV(THIS->get_ref(idx)); |
0 |
0 |
0 |
|
| 123 |
0 |
▶ | mXPUSHs(value.detach()); |
Branch: 3 branches
| Branch | True | False | Total |
| mXPUSHs(value.detach()); |
0 |
0 |
0 |
| mXPUSHs(value.detach()); |
0 |
0 |
0 |
| mXPUSHs(value.detach()); |
0 |
0 |
0 |
|
| 124 |
0 |
| } |
| 125 |
|
| } |
| 126 |
|
| |
| 127 |
|
| BOOT { |
| 128 |
35 |
▶ | auto stash = Stash(__PACKAGE__, GV_ADD); |
Branch: 1 branch
| Branch | True | False | Total |
| auto stash = Stash(__PACKAGE__, GV_ADD); |
35 |
0 |
35 |
|
| 129 |
35 |
▶ | stash.inherit("MyTest::Cookbook::ShapeA"); |
Branch: 1 branch
| Branch | True | False | Total |
| stash.inherit("MyTest::Cookbook::ShapeA"); |
35 |
0 |
35 |
|
| 130 |
35 |
| } |