diff options
Diffstat (limited to 'src/FbTk/Slot.hh')
-rw-r--r-- | src/FbTk/Slot.hh | 70 |
1 files changed, 31 insertions, 39 deletions
diff --git a/src/FbTk/Slot.hh b/src/FbTk/Slot.hh index 3daca4e..ea7ee2f 100644 --- a/src/FbTk/Slot.hh +++ b/src/FbTk/Slot.hh | |||
@@ -22,81 +22,72 @@ | |||
22 | #ifndef FBTK_SLOT_HH | 22 | #ifndef FBTK_SLOT_HH |
23 | #define FBTK_SLOT_HH | 23 | #define FBTK_SLOT_HH |
24 | 24 | ||
25 | #include "RefCount.hh" | ||
26 | |||
25 | namespace FbTk { | 27 | namespace FbTk { |
26 | 28 | ||
27 | /// \namespace Implementation details for signals, do not use anything in this namespace | 29 | /// \namespace Implementation details for signals, do not use anything in this namespace |
28 | namespace SigImpl { | 30 | namespace SigImpl { |
29 | 31 | ||
32 | struct EmptyArg {}; | ||
33 | |||
30 | class SlotBase { | 34 | class SlotBase { |
31 | public: | 35 | public: |
32 | virtual ~SlotBase() {} | 36 | virtual ~SlotBase() {} |
33 | }; | 37 | }; |
34 | 38 | ||
35 | template<typename ReturnType> | 39 | template<typename Arg1, typename Arg2, typename Arg3> |
36 | class SlotBase0: public SlotBase { | 40 | class SlotTemplate: public SlotBase { |
37 | public: | 41 | public: |
38 | virtual ReturnType operator()() = 0; | 42 | virtual void operator()(Arg1, Arg2, Arg3) = 0; |
39 | }; | 43 | }; |
40 | 44 | ||
41 | template<typename ReturnType, typename Functor> | 45 | template<typename Arg1, typename Arg2, typename Arg3, typename Functor> |
42 | class Slot0: public SlotBase0<ReturnType> { | 46 | class Slot: public SlotTemplate<Arg1, Arg2, Arg3> { |
43 | public: | 47 | public: |
44 | virtual ReturnType operator()() { return m_functor(); } | 48 | virtual void operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3) |
49 | { m_functor(arg1, arg2, arg3); } | ||
45 | 50 | ||
46 | Slot0(Functor functor) : m_functor(functor) {} | 51 | Slot(Functor functor) : m_functor(functor) {} |
47 | 52 | ||
48 | private: | 53 | private: |
49 | Functor m_functor; | 54 | Functor m_functor; |
50 | }; | 55 | }; |
51 | 56 | ||
52 | template<typename ReturnType, typename Arg1> | 57 | // specialization for two arguments |
53 | class SlotBase1: public SlotBase { | 58 | template<typename Arg1, typename Arg2, typename Functor> |
54 | public: | 59 | class Slot<Arg1, Arg2, EmptyArg, Functor>: public SlotTemplate<Arg1, Arg2, EmptyArg> { |
55 | virtual ReturnType operator()(Arg1) = 0; | ||
56 | }; | ||
57 | |||
58 | template<typename ReturnType, typename Arg1, typename Functor> | ||
59 | class Slot1: public SlotBase1<ReturnType, Arg1> { | ||
60 | public: | 60 | public: |
61 | virtual ReturnType operator()(Arg1 arg1) { return m_functor(arg1); } | 61 | virtual void operator()(Arg1 arg1, Arg2 arg2, EmptyArg) |
62 | { m_functor(arg1, arg2); } | ||
62 | 63 | ||
63 | Slot1(Functor functor) : m_functor(functor) {} | 64 | Slot(Functor functor) : m_functor(functor) {} |
64 | 65 | ||
65 | private: | 66 | private: |
66 | Functor m_functor; | 67 | Functor m_functor; |
67 | }; | 68 | }; |
68 | 69 | ||
69 | template<typename ReturnType, typename Arg1, typename Arg2> | 70 | // specialization for one argument |
70 | class SlotBase2: public SlotBase { | 71 | template<typename Arg1, typename Functor> |
71 | public: | 72 | class Slot<Arg1, EmptyArg, EmptyArg, Functor>: public SlotTemplate<Arg1, EmptyArg, EmptyArg> { |
72 | virtual ReturnType operator()(Arg1, Arg2) = 0; | ||
73 | }; | ||
74 | |||
75 | template<typename ReturnType, typename Arg1, typename Arg2, typename Functor> | ||
76 | class Slot2: public SlotBase2<ReturnType, Arg1, Arg2> { | ||
77 | public: | 73 | public: |
78 | virtual ReturnType operator()(Arg1 arg1, Arg2 arg2) { return m_functor(arg1, arg2); } | 74 | virtual void operator()(Arg1 arg1, EmptyArg, EmptyArg) |
75 | { m_functor(arg1); } | ||
79 | 76 | ||
80 | Slot2(Functor functor) : m_functor(functor) {} | 77 | Slot(Functor functor) : m_functor(functor) {} |
81 | 78 | ||
82 | private: | 79 | private: |
83 | Functor m_functor; | 80 | Functor m_functor; |
84 | }; | 81 | }; |
85 | 82 | ||
86 | template<typename ReturnType, typename Arg1, typename Arg2, typename Arg3> | 83 | // specialization for no arguments |
87 | class SlotBase3: public SlotBase { | 84 | template<typename Functor> |
88 | public: | 85 | class Slot<EmptyArg, EmptyArg, EmptyArg, Functor>: public SlotTemplate<EmptyArg, EmptyArg, EmptyArg> { |
89 | virtual ReturnType operator()(Arg1, Arg2, Arg3) = 0; | ||
90 | virtual ~SlotBase3() {} | ||
91 | }; | ||
92 | |||
93 | template<typename ReturnType, typename Arg1, typename Arg2, typename Arg3, typename Functor> | ||
94 | class Slot3: public SlotBase3<ReturnType, Arg1, Arg2, Arg3> { | ||
95 | public: | 86 | public: |
96 | virtual ReturnType operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3) | 87 | virtual void operator()(EmptyArg, EmptyArg, EmptyArg) |
97 | { return m_functor(arg1, arg2, arg3); } | 88 | { m_functor(); } |
98 | 89 | ||
99 | Slot3(Functor functor) : m_functor(functor) {} | 90 | Slot(Functor functor) : m_functor(functor) {} |
100 | 91 | ||
101 | private: | 92 | private: |
102 | Functor m_functor; | 93 | Functor m_functor; |
@@ -106,4 +97,5 @@ private: | |||
106 | 97 | ||
107 | } // namespace FbTk | 98 | } // namespace FbTk |
108 | 99 | ||
100 | |||
109 | #endif // FBTK_SLOT_H | 101 | #endif // FBTK_SLOT_H |