| 1 |
|
| #include <xs.h> |
| 2 |
|
| #include <xs/CallbackDispatcher.h> |
| 3 |
|
| |
| 4 |
|
| using namespace xs; |
| 5 |
|
| |
| 6 |
|
| using panda::string; |
| 7 |
|
| using panda::string_view; |
| 8 |
|
| using panda::CallbackDispatcher; |
| 9 |
|
| template <class T> using iptr = panda::iptr<T>; |
| 10 |
|
| |
| 11 |
|
| struct NoTmStruct { |
| 12 |
|
| string val; |
| 13 |
|
| }; |
| 14 |
|
| |
| 15 |
|
| struct SomeClass : panda::Refcnt {}; |
| 16 |
|
| struct SomeClass2 : panda::Refcnt {}; |
| 17 |
|
| |
| 18 |
|
| using cdVS = CallbackDispatcher<void(string)>; |
| 19 |
|
| using cdIS = CallbackDispatcher<int(string)>; |
| 20 |
|
| using cdIV = CallbackDispatcher<int(void)>; |
| 21 |
|
| using cdVIref = CallbackDispatcher<void(const int&)>; |
| 22 |
|
| using cdVPtrref = CallbackDispatcher<void(const panda::iptr<SomeClass>&)>; |
| 23 |
|
| using cdVV = CallbackDispatcher<void()>; |
| 24 |
|
| using cdPtrPtr = CallbackDispatcher<void(iptr<SomeClass>, iptr<SomeClass2>)>; |
| 25 |
|
| using cdNoTm = CallbackDispatcher<NoTmStruct(NoTmStruct)>; |
| 26 |
|
| |
| 27 |
|
| struct DispatchingObject { |
| 28 |
|
| cdVS vs; |
| 29 |
|
| cdIV iv; |
| 30 |
|
| cdVIref viref; |
| 31 |
|
| cdVPtrref vptrref; |
| 32 |
|
| cdIS is; |
| 33 |
|
| cdVV vv; |
| 34 |
|
| cdNoTm notm; |
| 35 |
|
| cdPtrPtr ptrptr; |
| 36 |
|
| }; |
| 37 |
|
| |
| 38 |
|
| namespace xs { |
| 39 |
|
| template <class TYPE> struct Typemap<DispatchingObject*,TYPE> : TypemapObject<DispatchingObject*, TYPE, ObjectTypePtr, ObjectStorageMG> { |
| 40 |
2 |
| static panda::string_view package () { return "MyTest::DispatchingObject"; } |
| 41 |
|
| }; |
| 42 |
|
| |
| 43 |
|
| template <class TYPE> struct Typemap<SomeClass*,TYPE> : TypemapObject<SomeClass*, TYPE, ObjectTypePtr, ObjectStorageMG> { |
| 44 |
0 |
| static panda::string_view package () { return "MyTest::SomeClass"; } |
| 45 |
|
| }; |
| 46 |
|
| |
| 47 |
|
| template <class TYPE> struct Typemap<SomeClass2*,TYPE> : TypemapObject<SomeClass2*, TYPE, ObjectTypePtr, ObjectStorageMG> { |
| 48 |
0 |
| static panda::string_view package () { return "MyTest::SomeClass2"; } |
| 49 |
|
| }; |
| 50 |
|
| } |
| 51 |
|
| |
| 52 |
|
| MODULE = MyTest::Typemap::CD PACKAGE = MyTest::DispatchingObject |
| 53 |
|
| PROTOTYPES: DISABLE |
| 54 |
|
| |
| 55 |
8 |
| DispatchingObject* new (SV*) |
| 56 |
8 |
▶ | |
Branch: 4 branches
| Branch | True | False | Total |
|
8 |
0 |
8 |
|
8 |
0 |
8 |
|
8 |
0 |
8 |
|
0 |
0 |
0 |
|
| 57 |
|
| XSCallbackDispatcher* DispatchingObject::vs (string_view type = string_view()) { |
| 58 |
55 |
| if (type == "") |
| 59 |
55 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->vs); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->vs); |
55 |
0 |
55 |
| RETVAL = XSCallbackDispatcher::create(THIS->vs); |
48 |
7 |
55 |
|
| 60 |
48 |
▶ | else if (type == "nullptr") |
Branch: 1 branch
| Branch | True | False | Total |
| else if (type == "nullptr") |
48 |
0 |
48 |
|
| 61 |
7 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->vs, nullptr); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->vs, nullptr); |
7 |
0 |
7 |
| RETVAL = XSCallbackDispatcher::create(THIS->vs, nullptr); |
2 |
5 |
7 |
|
| 62 |
2 |
▶ | else if (type == "pair_inout") |
Branch: 1 branch
| Branch | True | False | Total |
| else if (type == "pair_inout") |
2 |
0 |
2 |
|
| 63 |
5 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
5 |
0 |
5 |
| RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
2 |
3 |
5 |
|
| 64 |
2 |
▶ | [](string str) { return Simple(str + " custom_out"); }, |
Branch: 2 branches
| Branch | True | False | Total |
| [](string str) { return Simple(str + " custom_out"); }, |
2 |
0 |
2 |
| [](string str) { return Simple(str + " custom_out"); }, |
2 |
0 |
2 |
|
| 65 |
1 |
▶ | [](const Sv& sv) { return xs::in<string>(sv) + " custom_in"; } |
Branch: 2 branches
| Branch | True | False | Total |
| [](const Sv& sv) { return xs::in<string>(sv) + " custom_in"; } |
1 |
0 |
1 |
| [](const Sv& sv) { return xs::in<string>(sv) + " custom_in"; } |
1 |
0 |
1 |
|
| 66 |
3 |
▶ | )); |
Branch: 2 branches
| Branch | True | False | Total |
| )); |
1 |
0 |
1 |
| )); |
1 |
0 |
1 |
|
| 67 |
|
| else if (type == "pair_out") |
| 68 |
3 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
3 |
0 |
3 |
| RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
1 |
2 |
3 |
|
| 69 |
1 |
▶ | [](string str) { return Simple(str + " custom_out"); }, |
Branch: 1 branch
| Branch | True | False | Total |
| [](string str) { return Simple(str + " custom_out"); }, |
1 |
0 |
1 |
|
| 70 |
1 |
▶ | nullptr |
Branch: 2 branches
| Branch | True | False | Total |
| nullptr |
1 |
0 |
1 |
| nullptr |
1 |
0 |
1 |
|
| 71 |
2 |
▶ | )); |
Branch: 1 branch
| Branch | True | False | Total |
| )); |
1 |
0 |
1 |
|
| 72 |
|
| else if (type == "pair_in") |
| 73 |
2 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
2 |
0 |
2 |
| RETVAL = XSCallbackDispatcher::create(THIS->vs, std::make_pair( |
2 |
0 |
2 |
|
| 74 |
2 |
▶ | nullptr, |
Branch: 1 branch
| Branch | True | False | Total |
| nullptr, |
2 |
0 |
2 |
|
| 75 |
2 |
▶ | [](const Sv& sv) { return xs::in<string>(sv) + " custom_in"; } |
Branch: 1 branch
| Branch | True | False | Total |
| [](const Sv& sv) { return xs::in<string>(sv) + " custom_in"; } |
2 |
0 |
2 |
|
| 76 |
3 |
▶ | )); |
Branch: 2 branches
| Branch | True | False | Total |
| )); |
1 |
0 |
1 |
| )); |
1 |
0 |
1 |
|
| 77 |
|
| else throw "wtf"; |
| 78 |
0 |
| } |
| 79 |
|
| |
| 80 |
|
| cdIV* DispatchingObject::iv () { |
| 81 |
18 |
| RETVAL = &THIS->iv; |
| 82 |
18 |
▶ | } |
Branch: 1 branch
| Branch | True | False | Total |
| } |
18 |
0 |
18 |
|
| 83 |
|
| |
| 84 |
|
| XSCallbackDispatcher* DispatchingObject::viref () { |
| 85 |
2 |
| RETVAL = XSCallbackDispatcher::create(THIS->viref, std::make_pair( |
| 86 |
2 |
▶ | [](const int& v) { return xs::out<int>(v); }, |
Branch: 2 branches
| Branch | True | False | Total |
| [](const int& v) { return xs::out<int>(v); }, |
2 |
0 |
2 |
| [](const int& v) { return xs::out<int>(v); }, |
2 |
0 |
2 |
|
| 87 |
1 |
▶ | [](const Sv& sv) { return xs::in<int>(sv); } |
Branch: 1 branch
| Branch | True | False | Total |
| [](const Sv& sv) { return xs::in<int>(sv); } |
1 |
0 |
1 |
|
| 88 |
3 |
▶ | )); |
Branch: 1 branch
| Branch | True | False | Total |
| )); |
2 |
0 |
2 |
|
| 89 |
|
| } |
| 90 |
|
| |
| 91 |
|
| cdVPtrref* DispatchingObject::vptrref () { |
| 92 |
0 |
| RETVAL = &THIS->vptrref; |
| 93 |
0 |
▶ | } |
Branch: 1 branch
| Branch | True | False | Total |
| } |
0 |
0 |
0 |
|
| 94 |
|
| |
| 95 |
|
| XSCallbackDispatcher* DispatchingObject::is (string_view type = string_view()) { |
| 96 |
14 |
| if (type == "") |
| 97 |
14 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->is); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->is); |
14 |
0 |
14 |
| RETVAL = XSCallbackDispatcher::create(THIS->is); |
8 |
6 |
14 |
|
| 98 |
8 |
▶ | else if (type == "nullptr") |
Branch: 1 branch
| Branch | True | False | Total |
| else if (type == "nullptr") |
8 |
0 |
8 |
|
| 99 |
6 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->is, nullptr); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->is, nullptr); |
6 |
0 |
6 |
| RETVAL = XSCallbackDispatcher::create(THIS->is, nullptr); |
2 |
4 |
6 |
|
| 100 |
2 |
▶ | else if (type == "ret_inout") |
Branch: 1 branch
| Branch | True | False | Total |
| else if (type == "ret_inout") |
2 |
0 |
2 |
|
| 101 |
4 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->is, std::make_pair( |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->is, std::make_pair( |
4 |
0 |
4 |
| RETVAL = XSCallbackDispatcher::create(THIS->is, std::make_pair( |
2 |
2 |
4 |
|
| 102 |
2 |
▶ | [](panda::optional<int> val) { return val ? Simple(*val + 100) : Simple::undef; }, |
Branch: 2 branches
| Branch | True | False | Total |
| [](panda::optional<int> val) { return val ? Simple(*val + 100) : Simple::undef; }, |
2 |
0 |
2 |
| [](panda::optional<int> val) { return val ? Simple(*val + 100) : Simple::undef; }, |
2 |
0 |
2 |
|
| 103 |
1 |
▶ | [](const Sv& sv) { return xs::in<int>(sv) + 10; } |
Branch: 1 branch
| Branch | True | False | Total |
| [](const Sv& sv) { return xs::in<int>(sv) + 10; } |
1 |
0 |
1 |
|
| 104 |
3 |
| )); |
| 105 |
|
| else if (type == "ret_arg_inout") |
| 106 |
2 |
▶ | RETVAL = XSCallbackDispatcher::create(THIS->is, std::make_pair( |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = XSCallbackDispatcher::create(THIS->is, std::make_pair( |
2 |
0 |
2 |
| RETVAL = XSCallbackDispatcher::create(THIS->is, std::make_pair( |
2 |
0 |
2 |
|
| 107 |
2 |
▶ | [](panda::optional<int> val) { return val ? Simple(*val + 100) : Simple::undef; }, |
Branch: 2 branches
| Branch | True | False | Total |
| [](panda::optional<int> val) { return val ? Simple(*val + 100) : Simple::undef; }, |
2 |
0 |
2 |
| [](panda::optional<int> val) { return val ? Simple(*val + 100) : Simple::undef; }, |
2 |
0 |
2 |
|
| 108 |
1 |
▶ | [](const Sv& sv) { return xs::in<int>(sv) + 10; } |
Branch: 1 branch
| Branch | True | False | Total |
| [](const Sv& sv) { return xs::in<int>(sv) + 10; } |
1 |
0 |
1 |
|
| 109 |
1 |
| ), std::make_pair( |
| 110 |
2 |
▶ | [](string str) { return Simple(str + " custom_out"); }, |
Branch: 1 branch
| Branch | True | False | Total |
| [](string str) { return Simple(str + " custom_out"); }, |
2 |
0 |
2 |
|
| 111 |
1 |
▶ | [](const Sv& sv) { return xs::in<string>(sv) + " custom_in"; } |
Branch: 2 branches
| Branch | True | False | Total |
| [](const Sv& sv) { return xs::in<string>(sv) + " custom_in"; } |
1 |
0 |
1 |
| [](const Sv& sv) { return xs::in<string>(sv) + " custom_in"; } |
1 |
0 |
1 |
|
| 112 |
3 |
▶ | )); |
Branch: 2 branches
| Branch | True | False | Total |
| )); |
1 |
0 |
1 |
| )); |
1 |
0 |
1 |
|
| 113 |
|
| else throw "wtf"; |
| 114 |
0 |
| } |
| 115 |
|
| |
| 116 |
|
| cdVV* DispatchingObject::vv () { |
| 117 |
18 |
| RETVAL = &THIS->vv; |
| 118 |
18 |
▶ | } |
Branch: 1 branch
| Branch | True | False | Total |
| } |
18 |
0 |
18 |
|
| 119 |
|
| |
| 120 |
|
| XSCallbackDispatcher* DispatchingObject::notm () { |
| 121 |
4 |
| auto caster = std::make_pair( |
| 122 |
4 |
▶ | [](panda::optional<NoTmStruct> a) { return a ? Simple(a.value().val + "o") : Simple::undef; }, |
Branch: 1 branch
| Branch | True | False | Total |
| [](panda::optional<NoTmStruct> a) { return a ? Simple(a.value().val + "o") : Simple::undef; }, |
4 |
0 |
4 |
|
| 123 |
4 |
▶ | [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
Branch: 9 branches
| Branch | True | False | Total |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
4 |
0 |
4 |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
4 |
0 |
4 |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
4 |
0 |
4 |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
4 |
0 |
4 |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
0 |
0 |
0 |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
4 |
0 |
4 |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
4 |
0 |
4 |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
0 |
0 |
0 |
| [](const Sv& arg) { return NoTmStruct { xs::in<string>(arg) + "i" }; } |
0 |
0 |
0 |
|
| 124 |
4 |
▶ | ); |
Branch: 2 branches
| Branch | True | False | Total |
| ); |
4 |
0 |
4 |
| ); |
4 |
0 |
4 |
|
| 125 |
|
| RETVAL = XSCallbackDispatcher::create(THIS->notm, caster, caster); |
| 126 |
4 |
▶ | } |
Branch: 2 branches
| Branch | True | False | Total |
| } |
4 |
0 |
4 |
| } |
4 |
0 |
4 |
|
| 127 |
|
| |
| 128 |
|
| cdPtrPtr* DispatchingObject::ptrptr () { |
| 129 |
0 |
| RETVAL = &THIS->ptrptr; |
| 130 |
0 |
▶ | } |
Branch: 1 branch
| Branch | True | False | Total |
| } |
0 |
0 |
0 |
|
| 131 |
|
| |
| 132 |
|
| void DispatchingObject::call_vv (size_t cnt) { |
| 133 |
0 |
▶ | for (size_t i = 0; i < cnt; ++i) THIS->vv(); |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < cnt; ++i) THIS->vv(); |
0 |
0 |
0 |
|
| 134 |
|
| } |
| 135 |
|
| |
| 136 |
|
| void DispatchingObject::call_vs (size_t cnt) { |
| 137 |
0 |
▶ | for (size_t i = 0; i < cnt; ++i) THIS->vs("hello"); |
Branch: 2 branches
| Branch | True | False | Total |
| for (size_t i = 0; i < cnt; ++i) THIS->vs("hello"); |
0 |
0 |
0 |
| for (size_t i = 0; i < cnt; ++i) THIS->vs("hello"); |
0 |
0 |
0 |
|
| 138 |
|
| } |