diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-04-29 08:32:21 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-05-10 11:00:44 (GMT) |
commit | 54230c9a4474baf4f1c56773992212093e222349 (patch) | |
tree | 1cdf6bc41270b6f3da96770f2f6e7b6d021f54e5 | |
parent | d5bd23e41a05cc66676d9c4bf480e59b8566b7ac (diff) | |
download | fluxbox-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.
-rw-r--r-- | src/FbTk/Signal.hh | 94 |
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 | 104 | struct EmptyArg {}; |
105 | template <typename ReturnType> | ||
106 | class Signal0: public SignalHolder { | ||
107 | public: | ||
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. |
124 | template <typename ReturnType, typename Arg1> | 110 | template <typename ReturnType, |
125 | class Signal1: public SignalHolder { | 111 | typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg > |
112 | class Signal: public SigImpl::SignalHolder { | ||
126 | public: | 113 | public: |
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. |
144 | template <typename ReturnType, typename Arg1, typename Arg2> | 128 | template <typename ReturnType, typename Arg1, typename Arg2> |
145 | class Signal2: public SignalHolder { | 129 | class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::SignalHolder { |
146 | public: | 130 | public: |
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. |
163 | template <typename ReturnType, typename Arg1, typename Arg2, typename Arg3> | 145 | template <typename ReturnType, typename Arg1> |
164 | class Signal3: public SignalHolder { | 146 | class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder { |
165 | public: | 147 | public: |
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 | ||
182 | struct EmptyArg {}; | 161 | /// Specialization for no arguments. |
183 | 162 | template <typename ReturnType> | |
184 | } // namespace SigImpl | 163 | class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::SignalHolder { |
185 | |||
186 | |||
187 | /// Specialization for three arguments. | ||
188 | template <typename ReturnType, | ||
189 | typename Arg1 = SigImpl::EmptyArg, typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg > | ||
190 | class Signal: public SigImpl::Signal3< ReturnType, Arg1, Arg2, Arg3 > { | ||
191 | public: | 164 | public: |
192 | }; | 165 | typedef SigImpl::Slot0<ReturnType> SlotType; |
193 | 166 | ||
194 | /// Specialization for two arguments. | 167 | void emit() { |
195 | template <typename ReturnType, typename Arg1, typename Arg2> | 168 | for ( Iterator it = begin(); it != end(); ++it ) { |
196 | class Signal<ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public SigImpl::Signal2< ReturnType, Arg1, Arg2 > { | 169 | static_cast<SlotType&>(*it)(); |
197 | public: | 170 | } |
198 | }; | 171 | } |
199 | |||
200 | /// Specialization for one argument. | ||
201 | template <typename ReturnType, typename Arg1> | ||
202 | class Signal<ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::Signal1< ReturnType, Arg1 > { | ||
203 | public: | ||
204 | }; | ||
205 | 172 | ||
206 | /// Specialization for no argument. | 173 | SlotID connect(const SlotType& slot) { |
207 | template <typename ReturnType> | 174 | return SignalHolder::connect(slot); |
208 | class Signal<ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public SigImpl::Signal0< ReturnType > { | 175 | } |
209 | public: | ||
210 | }; | 176 | }; |
211 | 177 | ||
212 | /** | 178 | /** |