aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Slot.hh
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-19 10:32:42 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-06-15 15:34:40 (GMT)
commitbf291201e14ee7438c986b273e67d28f43bf10f7 (patch)
treec861fbbfbe66d6fe6190052542c0da71614b86dc /src/FbTk/Slot.hh
parented7d21b2982db3ef29b4d003fe021caed6691485 (diff)
downloadfluxbox_pavel-bf291201e14ee7438c986b273e67d28f43bf10f7.zip
fluxbox_pavel-bf291201e14ee7438c986b273e67d28f43bf10f7.tar.bz2
Prepare the Slot classes to be used as lua callbacks
Added some polish around them and, to mark this special occasion, moved them out of the SigImpl namespace. PS: This partially reverts commit 0775350fee345e37fb59835dda4d85664346b606, since I had to reintroduce ReturnType template parameter, because it will be used in lua. But Signal classes remain without the ReturnType, because I still cannot imagine how would it be used.
Diffstat (limited to 'src/FbTk/Slot.hh')
-rw-r--r--src/FbTk/Slot.hh90
1 files changed, 59 insertions, 31 deletions
diff --git a/src/FbTk/Slot.hh b/src/FbTk/Slot.hh
index ea7ee2f..71bf6ab 100644
--- a/src/FbTk/Slot.hh
+++ b/src/FbTk/Slot.hh
@@ -22,7 +22,7 @@
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" 25#include "NotCopyable.hh"
26 26
27namespace FbTk { 27namespace FbTk {
28 28
@@ -31,71 +31,99 @@ namespace SigImpl {
31 31
32struct EmptyArg {}; 32struct EmptyArg {};
33 33
34class SlotBase { 34/** A base class for all slots. It's purpose is to provide a virtual destructor and to enable the
35 * Signal class to hold a pointer to a generic slot.
36 */
37class SlotBase: private FbTk::NotCopyable {
35public: 38public:
36 virtual ~SlotBase() {} 39 virtual ~SlotBase() {}
37}; 40};
38 41
39template<typename Arg1, typename Arg2, typename Arg3> 42} // namespace SigImpl
40class SlotTemplate: public SlotBase { 43
44/** Declares a pure virtual function call operator with a specific number of arguments (depending
45 * on the template specialization). This allows us to "call" any functor in an opaque way.
46 */
47template<typename ReturnType, typename Arg1 = SigImpl::EmptyArg,
48 typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg>
49class Slot: public SigImpl::SlotBase {
50public:
51 virtual ReturnType operator()(Arg1, Arg2, Arg3) = 0;
52};
53
54/// Specialization for two arguments
55template<typename ReturnType, typename Arg1, typename Arg2>
56class Slot<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::SlotBase {
57public:
58 virtual ReturnType operator()(Arg1, Arg2) = 0;
59};
60
61/// Specialization for one argument
62template<typename ReturnType, typename Arg1>
63class Slot<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SlotBase {
64public:
65 virtual ReturnType operator()(Arg1) = 0;
66};
67
68/// Specialization for no arguments
69template<typename ReturnType>
70class Slot<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SlotBase {
41public: 71public:
42 virtual void operator()(Arg1, Arg2, Arg3) = 0; 72 virtual ReturnType operator()() = 0;
43}; 73};
44 74
45template<typename Arg1, typename Arg2, typename Arg3, typename Functor> 75/** A class which knows how to call a specific functor. It inherits from Slot and implemetents
46class Slot: public SlotTemplate<Arg1, Arg2, Arg3> { 76 * the function call operator
77 */
78template<typename Functor, typename ReturnType, typename Arg1 = SigImpl::EmptyArg,
79 typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg>
80class SlotImpl: public Slot<ReturnType, Arg1, Arg2, Arg3> {
47public: 81public:
48 virtual void operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3) 82 virtual ReturnType operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3)
49 { m_functor(arg1, arg2, arg3); } 83 { return m_functor(arg1, arg2, arg3); }
50 84
51 Slot(Functor functor) : m_functor(functor) {} 85 SlotImpl(Functor functor) : m_functor(functor) {}
52 86
53private: 87private:
54 Functor m_functor; 88 Functor m_functor;
55}; 89};
56 90
57// specialization for two arguments 91/// Specialization for two arguments
58template<typename Arg1, typename Arg2, typename Functor> 92template<typename Functor, typename ReturnType, typename Arg1, typename Arg2>
59class Slot<Arg1, Arg2, EmptyArg, Functor>: public SlotTemplate<Arg1, Arg2, EmptyArg> { 93class SlotImpl<Functor, ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public Slot<ReturnType, Arg1, Arg2> {
60public: 94public:
61 virtual void operator()(Arg1 arg1, Arg2 arg2, EmptyArg) 95 virtual ReturnType operator()(Arg1 arg1, Arg2 arg2) { return m_functor(arg1, arg2); }
62 { m_functor(arg1, arg2); }
63 96
64 Slot(Functor functor) : m_functor(functor) {} 97 SlotImpl(Functor functor) : m_functor(functor) {}
65 98
66private: 99private:
67 Functor m_functor; 100 Functor m_functor;
68}; 101};
69 102
70// specialization for one argument 103/// Specialization for one argument
71template<typename Arg1, typename Functor> 104template<typename Functor, typename ReturnType, typename Arg1>
72class Slot<Arg1, EmptyArg, EmptyArg, Functor>: public SlotTemplate<Arg1, EmptyArg, EmptyArg> { 105class SlotImpl<Functor, ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public Slot<ReturnType, Arg1> {
73public: 106public:
74 virtual void operator()(Arg1 arg1, EmptyArg, EmptyArg) 107 virtual ReturnType operator()(Arg1 arg1) { return m_functor(arg1); }
75 { m_functor(arg1); }
76 108
77 Slot(Functor functor) : m_functor(functor) {} 109 SlotImpl(Functor functor) : m_functor(functor) {}
78 110
79private: 111private:
80 Functor m_functor; 112 Functor m_functor;
81}; 113};
82 114
83// specialization for no arguments 115/// Specialization for no arguments
84template<typename Functor> 116template<typename Functor, typename ReturnType>
85class Slot<EmptyArg, EmptyArg, EmptyArg, Functor>: public SlotTemplate<EmptyArg, EmptyArg, EmptyArg> { 117class SlotImpl<Functor, ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public Slot<ReturnType> {
86public: 118public:
87 virtual void operator()(EmptyArg, EmptyArg, EmptyArg) 119 virtual ReturnType operator()() { return m_functor(); }
88 { m_functor(); }
89 120
90 Slot(Functor functor) : m_functor(functor) {} 121 SlotImpl(Functor functor) : m_functor(functor) {}
91 122
92private: 123private:
93 Functor m_functor; 124 Functor m_functor;
94}; 125};
95 126
96} // namespace SigImpl
97
98} // namespace FbTk 127} // namespace FbTk
99 128
100
101#endif // FBTK_SLOT_H 129#endif // FBTK_SLOT_H