aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Slot.hh
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-03 10:49:05 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-05-10 11:00:45 (GMT)
commit0775350fee345e37fb59835dda4d85664346b606 (patch)
tree390af82593f92e11033ca2a2590a5ec7b7a3d14c /src/FbTk/Slot.hh
parentbef2039d2c5a31ab9f974059d991557276647af1 (diff)
downloadfluxbox_pavel-0775350fee345e37fb59835dda4d85664346b606.zip
fluxbox_pavel-0775350fee345e37fb59835dda4d85664346b606.tar.bz2
Last round of simplification of Signal/Slot classes
- merged all the common stuff from 0,1,2,3 argument versions into one common base class - removed ReturnType template parameter as it was instantiated with "void" everywhere and the current ignores the return value of the callbacks anyway
Diffstat (limited to 'src/FbTk/Slot.hh')
-rw-r--r--src/FbTk/Slot.hh70
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
25namespace FbTk { 27namespace 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
28namespace SigImpl { 30namespace SigImpl {
29 31
32struct EmptyArg {};
33
30class SlotBase { 34class SlotBase {
31public: 35public:
32 virtual ~SlotBase() {} 36 virtual ~SlotBase() {}
33}; 37};
34 38
35template<typename ReturnType> 39template<typename Arg1, typename Arg2, typename Arg3>
36class SlotBase0: public SlotBase { 40class SlotTemplate: public SlotBase {
37public: 41public:
38 virtual ReturnType operator()() = 0; 42 virtual void operator()(Arg1, Arg2, Arg3) = 0;
39}; 43};
40 44
41template<typename ReturnType, typename Functor> 45template<typename Arg1, typename Arg2, typename Arg3, typename Functor>
42class Slot0: public SlotBase0<ReturnType> { 46class Slot: public SlotTemplate<Arg1, Arg2, Arg3> {
43public: 47public:
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
48private: 53private:
49 Functor m_functor; 54 Functor m_functor;
50}; 55};
51 56
52template<typename ReturnType, typename Arg1> 57// specialization for two arguments
53class SlotBase1: public SlotBase { 58template<typename Arg1, typename Arg2, typename Functor>
54public: 59class Slot<Arg1, Arg2, EmptyArg, Functor>: public SlotTemplate<Arg1, Arg2, EmptyArg> {
55 virtual ReturnType operator()(Arg1) = 0;
56};
57
58template<typename ReturnType, typename Arg1, typename Functor>
59class Slot1: public SlotBase1<ReturnType, Arg1> {
60public: 60public:
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
65private: 66private:
66 Functor m_functor; 67 Functor m_functor;
67}; 68};
68 69
69template<typename ReturnType, typename Arg1, typename Arg2> 70// specialization for one argument
70class SlotBase2: public SlotBase { 71template<typename Arg1, typename Functor>
71public: 72class Slot<Arg1, EmptyArg, EmptyArg, Functor>: public SlotTemplate<Arg1, EmptyArg, EmptyArg> {
72 virtual ReturnType operator()(Arg1, Arg2) = 0;
73};
74
75template<typename ReturnType, typename Arg1, typename Arg2, typename Functor>
76class Slot2: public SlotBase2<ReturnType, Arg1, Arg2> {
77public: 73public:
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
82private: 79private:
83 Functor m_functor; 80 Functor m_functor;
84}; 81};
85 82
86template<typename ReturnType, typename Arg1, typename Arg2, typename Arg3> 83// specialization for no arguments
87class SlotBase3: public SlotBase { 84template<typename Functor>
88public: 85class Slot<EmptyArg, EmptyArg, EmptyArg, Functor>: public SlotTemplate<EmptyArg, EmptyArg, EmptyArg> {
89 virtual ReturnType operator()(Arg1, Arg2, Arg3) = 0;
90 virtual ~SlotBase3() {}
91};
92
93template<typename ReturnType, typename Arg1, typename Arg2, typename Arg3, typename Functor>
94class Slot3: public SlotBase3<ReturnType, Arg1, Arg2, Arg3> {
95public: 86public:
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
101private: 92private:
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