aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
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
parentbef2039d2c5a31ab9f974059d991557276647af1 (diff)
downloadfluxbox_paul-0775350fee345e37fb59835dda4d85664346b606.zip
fluxbox_paul-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')
-rw-r--r--src/FbTk/MenuTheme.hh2
-rw-r--r--src/FbTk/Signal.hh102
-rw-r--r--src/FbTk/Slot.hh70
-rw-r--r--src/FbTk/Theme.hh6
4 files changed, 72 insertions, 108 deletions
diff --git a/src/FbTk/MenuTheme.hh b/src/FbTk/MenuTheme.hh
index b575860..d39b5df 100644
--- a/src/FbTk/MenuTheme.hh
+++ b/src/FbTk/MenuTheme.hh
@@ -130,7 +130,7 @@ public:
130 m_hl_selected_pixmap->pixmap().dontFree(); 130 m_hl_selected_pixmap->pixmap().dontFree();
131 } 131 }
132 132
133 virtual Signal<void> &reconfigSig() { return Theme::reconfigSig(); } 133 virtual Signal<> &reconfigSig() { return Theme::reconfigSig(); }
134 134
135 virtual MenuTheme &operator *() { return *this; } 135 virtual MenuTheme &operator *() { return *this; }
136 virtual const MenuTheme &operator *() const { return *this; } 136 virtual const MenuTheme &operator *() const { return *this; }
diff --git a/src/FbTk/Signal.hh b/src/FbTk/Signal.hh
index 432bb3f..a7b91ba 100644
--- a/src/FbTk/Signal.hh
+++ b/src/FbTk/Signal.hh
@@ -22,7 +22,6 @@
22#ifndef FBTK_SIGNAL_HH 22#ifndef FBTK_SIGNAL_HH
23#define FBTK_SIGNAL_HH 23#define FBTK_SIGNAL_HH
24 24
25#include "RefCount.hh"
26#include "Slot.hh" 25#include "Slot.hh"
27#include <algorithm> 26#include <algorithm>
28#include <list> 27#include <list>
@@ -35,7 +34,7 @@ namespace FbTk {
35namespace SigImpl { 34namespace SigImpl {
36 35
37/** 36/**
38 * Parent class for all \c Signal[0...*] classes. 37 * Parent class for all \c Signal template classes.
39 * It handles the disconnect and holds all the slots. The connect must be 38 * It handles the disconnect and holds all the slots. The connect must be
40 * handled by the child class so it can do the type checking. 39 * handled by the child class so it can do the type checking.
41 */ 40 */
@@ -121,93 +120,66 @@ private:
121 unsigned m_emitting; 120 unsigned m_emitting;
122}; 121};
123 122
124struct EmptyArg {}; 123template <typename Arg1, typename Arg2, typename Arg3>
125 124class SignalTemplate: public SignalHolder {
126} // namespace SigImpl
127
128
129/// Specialization for three arguments.
130template <typename ReturnType,
131 typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg >
132class Signal: public SigImpl::SignalHolder {
133public: 125public:
134 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) { 126 template<typename Functor>
127 SlotID connect(const Functor& functor) {
128 return SignalHolder::connect(SlotPtr( new Slot<Arg1, Arg2, Arg3, Functor>(functor) ));
129 }
130
131protected:
132 void emit_(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
135 begin_emitting(); 133 begin_emitting();
136 for ( Iterator it = begin(); it != end(); ++it ) { 134 for ( Iterator it = begin(); it != end(); ++it ) {
137 if(*it) 135 if(*it)
138 static_cast<SigImpl::SlotBase3<ReturnType, Arg1, Arg2, Arg3> &>(**it)(arg1, arg2, arg3); 136 static_cast<SigImpl::SlotTemplate<Arg1, Arg2, Arg3> &>(**it)(arg1, arg2, arg3);
139 } 137 }
140 end_emitting(); 138 end_emitting();
141 } 139 }
140};
142 141
143 template<typename Functor> 142} // namespace SigImpl
144 SlotID connect(const Functor& functor) { 143
145 return SignalHolder::connect(SlotPtr( 144
146 new SigImpl::Slot3<ReturnType, Arg1, Arg2, Arg3, Functor>(functor) 145/// Base template for three arguments.
147 )); 146template <typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg >
148 } 147class Signal: public SigImpl::SignalTemplate<Arg1, Arg2, Arg3> {
148public:
149 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3)
150 { SigImpl::SignalTemplate<Arg1, Arg2, Arg3>::emit_(arg1, arg2, arg3); }
149}; 151};
150 152
151/// Specialization for two arguments. 153/// Specialization for two arguments.
152template <typename ReturnType, typename Arg1, typename Arg2> 154template <typename Arg1, typename Arg2>
153class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::SignalHolder { 155class Signal<Arg1, Arg2, SigImpl::EmptyArg>:
156 public SigImpl::SignalTemplate<Arg1, Arg2, SigImpl::EmptyArg> {
154public: 157public:
155 void emit(Arg1 arg1, Arg2 arg2) { 158 void emit(Arg1 arg1, Arg2 arg2) {
156 begin_emitting(); 159 SigImpl::SignalTemplate<Arg1, Arg2, SigImpl::EmptyArg>::
157 for ( Iterator it = begin(); it != end(); ++it ) { 160 emit_(arg1, arg2, SigImpl::EmptyArg());
158 if(*it)
159 static_cast<SigImpl::SlotBase2<ReturnType, Arg1, Arg2> &>(**it)(arg1, arg2);
160 }
161 end_emitting();
162 }
163
164 template<typename Functor>
165 SlotID connect(const Functor& functor) {
166 return SignalHolder::connect(SlotPtr(
167 new SigImpl::Slot2<ReturnType, Arg1, Arg2, Functor>(functor)
168 ));
169 } 161 }
170}; 162};
171 163
172/// Specialization for one argument. 164/// Specialization for one argument.
173template <typename ReturnType, typename Arg1> 165template <typename Arg1>
174class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder { 166class Signal<Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>:
167 public SigImpl::SignalTemplate<Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg> {
175public: 168public:
176 void emit(Arg1 arg) { 169 void emit(Arg1 arg1) {
177 begin_emitting(); 170 SigImpl::SignalTemplate<Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>
178 for ( Iterator it = begin(); it != end(); ++it ) { 171 ::emit_(arg1, SigImpl::EmptyArg(), SigImpl::EmptyArg());
179 if(*it)
180 static_cast<SigImpl::SlotBase1<ReturnType, Arg1> &>(**it)(arg);
181 }
182 end_emitting();
183 }
184
185 template<typename Functor>
186 SlotID connect(const Functor& functor) {
187 return SignalHolder::connect(SlotPtr(
188 new SigImpl::Slot1<ReturnType, Arg1, Functor>(functor)
189 ));
190 } 172 }
191}; 173};
192 174
193/// Specialization for no arguments. 175/// Specialization for no arguments.
194template <typename ReturnType> 176template <>
195class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder { 177class Signal<SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>:
178 public SigImpl::SignalTemplate<SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg> {
196public: 179public:
197 void emit() { 180 void emit() {
198 begin_emitting(); 181 SigImpl::SignalTemplate<SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>
199 for ( Iterator it = begin(); it != end(); ++it ) { 182 ::emit_(SigImpl::EmptyArg(), SigImpl::EmptyArg(), SigImpl::EmptyArg());
200 if(*it)
201 static_cast<SigImpl::SlotBase0<ReturnType> &>(**it)();
202 }
203 end_emitting();
204 }
205
206 template<typename Functor>
207 SlotID connect(const Functor& functor) {
208 return SignalHolder::connect(SlotPtr(
209 new SigImpl::Slot0<ReturnType, Functor>(functor)
210 ));
211 } 183 }
212}; 184};
213 185
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
diff --git a/src/FbTk/Theme.hh b/src/FbTk/Theme.hh
index c700f9b..a0f2717 100644
--- a/src/FbTk/Theme.hh
+++ b/src/FbTk/Theme.hh
@@ -107,13 +107,13 @@ public:
107 template <typename T> 107 template <typename T>
108 void remove(ThemeItem<T> &item); 108 void remove(ThemeItem<T> &item);
109 virtual bool fallback(ThemeItem_base &) { return false; } 109 virtual bool fallback(ThemeItem_base &) { return false; }
110 Signal<void> &reconfigSig() { return m_reconfig_sig; } 110 Signal<> &reconfigSig() { return m_reconfig_sig; }
111 111
112private: 112private:
113 const int m_screen_num; 113 const int m_screen_num;
114 114
115 ItemList m_themeitems; 115 ItemList m_themeitems;
116 Signal<void> m_reconfig_sig; 116 Signal<> m_reconfig_sig;
117}; 117};
118 118
119/// Proxy interface for themes, so they can be substituted dynamically 119/// Proxy interface for themes, so they can be substituted dynamically
@@ -122,7 +122,7 @@ class ThemeProxy {
122public: 122public:
123 virtual ~ThemeProxy() { } 123 virtual ~ThemeProxy() { }
124 124
125 virtual Signal<void> &reconfigSig() = 0; 125 virtual Signal<> &reconfigSig() = 0;
126 126
127 virtual BaseTheme &operator *() = 0; 127 virtual BaseTheme &operator *() = 0;
128 virtual const BaseTheme &operator *() const = 0; 128 virtual const BaseTheme &operator *() const = 0;