-
Notifications
You must be signed in to change notification settings - Fork 0
/
signal_sigc_compat.hpp
56 lines (44 loc) · 1.09 KB
/
signal_sigc_compat.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef WAYROUND_I2P_20241223_224139_479111
#define WAYROUND_I2P_20241223_224139_479111
#include <sigc++/sigc++.h>
#include "signal.hpp"
namespace wayround_i2p::ccedit
{
template <class>
class SlotSigCCompat;
template <class RetT, class... Args>
class SlotSigCCompat<RetT(Args...)>;
template <class RetT, class... Args>
class SlotSigCCompat<RetT(Args...)>
: public SlotC<RetT(Args...)>,
public sigc::trackable
{
public:
SlotSigCCompat(std::function<RetT(Args...)> fun = nullptr) :
SlotC<RetT(Args...)>(fun)
{
}
~SlotSigCCompat()
{
}
RetT on_emission(Args... args)
{
auto x = dynamic_cast<Slot_shared<RetT(Args...)> *>(this);
if (!x)
{
// todo: better error
throw "!x";
}
return (*x)->on_emission(args...);
}
sigc::slot<RetT(Args...)> make_sigc_slot()
{
return sigc::mem_fun(*this, &SlotSigCCompat<RetT(Args...)>::on_emission);
}
operator sigc::slot<RetT(Args...)>()
{
return make_sigc_slot();
}
};
} // namespace wayround_i2p::ccedit
#endif