aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Signal.hh
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-04-29 08:32:21 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-05-10 11:00:44 (GMT)
commit54230c9a4474baf4f1c56773992212093e222349 (patch)
tree1cdf6bc41270b6f3da96770f2f6e7b6d021f54e5 /src/FbTk/Signal.hh
parentd5bd23e41a05cc66676d9c4bf480e59b8566b7ac (diff)
downloadfluxbox-54230c9a4474baf4f1c56773992212093e222349.zip
fluxbox-54230c9a4474baf4f1c56773992212093e222349.tar.bz2
Simplify FbTk::Signal template classes a bit
basically, i just got rid of Signal[0-3] classes and moved their contents to the appropriate specialization of FbTk::Signal also, this fixes the no matching function for call to 'MemFunIgnoreArgs(FbTk::Signal<void, FbTk::SigImpl::EmptyArg, FbTk::SigImpl::EmptyArg, FbTk::SigImpl::EmptyArg>&, void (FbTk::SigImpl::Signal0<void>::*)())' error i had in the following commit.
Diffstat (limited to 'src/FbTk/Signal.hh')
-rw-r--r--src/FbTk/Signal.hh94
1 files changed, 30 insertions, 64 deletions
diff --git a/src/FbTk/Signal.hh b/src/FbTk/Signal.hh
index 3c17d1a..79d001f 100644
--- a/src/FbTk/Signal.hh
+++ b/src/FbTk/Signal.hh
@@ -101,52 +101,34 @@ private:
101 Trackers m_trackers; ///< all instances that tracks this signal. 101 Trackers m_trackers; ///< all instances that tracks this signal.
102}; 102};
103 103
104/// Signal with no argument 104struct EmptyArg {};
105template <typename ReturnType>
106class Signal0: public SignalHolder {
107public:
108 typedef Slot0<ReturnType> SlotType;
109
110 ~Signal0() { }
111 105
112 void emit() { 106} // namespace SigImpl
113 for ( Iterator it = begin(); it != end(); ++it ) {
114 static_cast<SlotType&>(*it)();
115 }
116 }
117 107
118 SlotID connect(const SlotType& slot) {
119 return SignalHolder::connect(slot);
120 }
121};
122 108
123/// Signal with one argument 109/// Specialization for three arguments.
124template <typename ReturnType, typename Arg1> 110template <typename ReturnType,
125class Signal1: public SignalHolder { 111 typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg >
112class Signal: public SigImpl::SignalHolder {
126public: 113public:
127 typedef Slot1<ReturnType, Arg1> SlotType; 114 typedef SigImpl::Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType;
128 115
129 ~Signal1() { } 116 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
130
131 void emit(Arg1 arg) {
132 for ( Iterator it = begin(); it != end(); ++it ) { 117 for ( Iterator it = begin(); it != end(); ++it ) {
133 static_cast<SlotType&>(*it)(arg); 118 static_cast<SlotType&>(*it)(arg1, arg2, arg3);
134 } 119 }
135 } 120 }
136 121
137 SlotID connect(const SlotType& slot) { 122 SlotID connect(const SlotType& slot) {
138 return SignalHolder::connect(slot); 123 return SignalHolder::connect(slot);
139 } 124 }
140
141}; 125};
142 126
143/// Signal with two arguments 127/// Specialization for two arguments.
144template <typename ReturnType, typename Arg1, typename Arg2> 128template <typename ReturnType, typename Arg1, typename Arg2>
145class Signal2: public SignalHolder { 129class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::SignalHolder {
146public: 130public:
147 typedef Slot2<ReturnType, Arg1, Arg2> SlotType; 131 typedef SigImpl::Slot2<ReturnType, Arg1, Arg2> SlotType;
148
149 ~Signal2() { }
150 132
151 void emit(Arg1 arg1, Arg2 arg2) { 133 void emit(Arg1 arg1, Arg2 arg2) {
152 for ( Iterator it = begin(); it != end(); ++it ) { 134 for ( Iterator it = begin(); it != end(); ++it ) {
@@ -159,54 +141,38 @@ public:
159 } 141 }
160}; 142};
161 143
162/// Signal with three arguments 144/// Specialization for one argument.
163template <typename ReturnType, typename Arg1, typename Arg2, typename Arg3> 145template <typename ReturnType, typename Arg1>
164class Signal3: public SignalHolder { 146class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder {
165public: 147public:
166 typedef Slot3<ReturnType, Arg1, Arg2, Arg3> SlotType; 148 typedef SigImpl::Slot1<ReturnType, Arg1> SlotType;
167 149
168 ~Signal3() { } 150 void emit(Arg1 arg) {
169
170 void emit(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
171 for ( Iterator it = begin(); it != end(); ++it ) { 151 for ( Iterator it = begin(); it != end(); ++it ) {
172 static_cast<SlotType&>(*it)(arg1, arg2, arg3); 152 static_cast<SlotType&>(*it)(arg);
173 } 153 }
174 } 154 }
175 155
176 SlotID connect(const SlotType& slot) { 156 SlotID connect(const SlotType& slot) {
177 return SignalHolder::connect(slot); 157 return SignalHolder::connect(slot);
178 } 158 }
179
180}; 159};
181 160
182struct EmptyArg {}; 161/// Specialization for no arguments.
183 162template <typename ReturnType>
184} // namespace SigImpl 163class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder {
185
186
187/// Specialization for three arguments.
188template <typename ReturnType,
189 typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg >
190class Signal: public SigImpl::Signal3< ReturnType, Arg1, Arg2, Arg3 > {
191public: 164public:
192}; 165 typedef SigImpl::Slot0<ReturnType> SlotType;
193 166
194/// Specialization for two arguments. 167 void emit() {
195template <typename ReturnType, typename Arg1, typename Arg2> 168 for ( Iterator it = begin(); it != end(); ++it ) {
196class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::Signal2< ReturnType, Arg1, Arg2 > { 169 static_cast<SlotType&>(*it)();
197public: 170 }
198}; 171 }
199
200/// Specialization for one argument.
201template <typename ReturnType, typename Arg1>
202class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::Signal1< ReturnType, Arg1 > {
203public:
204};
205 172
206/// Specialization for no argument. 173 SlotID connect(const SlotType& slot) {
207template <typename ReturnType> 174 return SignalHolder::connect(slot);
208class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::Signal0< ReturnType > { 175 }
209public:
210}; 176};
211 177
212/** 178/**