aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MemFun.hh
diff options
context:
space:
mode:
authorHenrik Kinnunen <fluxgen@fluxbox.org>2010-03-18 09:45:33 (GMT)
committerHenrik Kinnunen <fluxgen@fluxbox.org>2010-03-18 09:45:33 (GMT)
commit0504de454a0a3bf06466029940af480e3caaa8b2 (patch)
tree0c4507b4fe965cbe2080329ef9bad443c14fa6aa /src/FbTk/MemFun.hh
parent5a91ada3c6c9f199b3646465206d4b2b613cad3e (diff)
downloadfluxbox_pavel-0504de454a0a3bf06466029940af480e3caaa8b2.zip
fluxbox_pavel-0504de454a0a3bf06466029940af480e3caaa8b2.tar.bz2
Added MemFunIgnoreArgs which ignores aditional arguments.
For example connecting a function that takes two arguments to a signal that emits three arguments: struct Functor { void show(int a, int b); }; Functor f; Signal<void, int, int, int> s3; s3.connect(MemFunIgnoreArgs(f, &Functor::show));
Diffstat (limited to 'src/FbTk/MemFun.hh')
-rw-r--r--src/FbTk/MemFun.hh90
1 files changed, 89 insertions, 1 deletions
diff --git a/src/FbTk/MemFun.hh b/src/FbTk/MemFun.hh
index 4c834dd..c2c6b20 100644
--- a/src/FbTk/MemFun.hh
+++ b/src/FbTk/MemFun.hh
@@ -38,7 +38,9 @@ public:
38 void operator ()() { 38 void operator ()() {
39 (m_obj.*m_action)(); 39 (m_obj.*m_action)();
40 } 40 }
41 41 void call() {
42 (m_obj.*m_action)();
43 }
42private: 44private:
43 Object& m_obj; 45 Object& m_obj;
44 Action m_action; 46 Action m_action;
@@ -133,6 +135,92 @@ MemFun( Object& obj, ReturnType (Object:: *action)(Arg1, Arg2, Arg3) ) {
133 return MemFun3<ReturnType, Object, Arg1, Arg2, Arg3>(obj, action); 135 return MemFun3<ReturnType, Object, Arg1, Arg2, Arg3>(obj, action);
134} 136}
135 137
138/// Ignores all arguments
139template <typename ReturnType, typename Object>
140class MemFun0IgnoreArgs: public MemFun0<ReturnType, Object> {
141public:
142 typedef MemFun0<ReturnType, Object> BaseType;
143
144 MemFun0IgnoreArgs(Object& obj,
145 typename BaseType::Action action):
146 BaseType(obj, action) {
147 }
148
149 template <typename IgnoreType1, typename IgnoreType2, typename IgnoreType3>
150 void operator ()(IgnoreType1&, IgnoreType2&, IgnoreType3&) {
151 BaseType::operator ()();
152 }
153
154 template <typename IgnoreType1, typename IgnoreType2>
155 void operator ()(IgnoreType1&, IgnoreType2&) {
156 BaseType::operator ()();
157 }
158
159 template <typename IgnoreType1>
160 void operator ()(IgnoreType1&) {
161 BaseType::operator ()();
162 }
163};
164
165/// Ignores second and third argument
166template <typename ReturnType, typename Object, typename Arg1>
167class MemFun1IgnoreArgs: public MemFun1<ReturnType, Object, Arg1> {
168public:
169 typedef MemFun1<ReturnType, Object, Arg1> BaseType;
170
171 MemFun1IgnoreArgs(Object& obj, typename BaseType::Action& action):
172 BaseType(obj, action) {
173 }
174
175 template <typename IgnoreType1, typename IgnoreType2>
176 void operator ()(Arg1 arg1, IgnoreType1&, IgnoreType2&) {
177 BaseType::operator ()(arg1);
178 }
179
180 template <typename IgnoreType>
181 void operator ()(Arg1 arg1, IgnoreType&) {
182 BaseType::operator ()(arg1);
183 }
184};
185
186/// Takes two arguments but ignores the third
187template <typename ReturnType, typename Object, typename Arg1, typename Arg2>
188class MemFun2IgnoreArgs: public MemFun2<ReturnType, Object, Arg1, Arg2> {
189public:
190 typedef MemFun2<ReturnType, Object, Arg1, Arg2> BaseType;
191
192 MemFun2IgnoreArgs(Object& obj, typename BaseType::Action& action):
193 BaseType(obj, action) {
194 }
195
196 template < typename IgnoreType >
197 void operator ()(Arg1 arg1, Arg2 arg2, IgnoreType&) {
198 BaseType::operator ()(arg1, arg2);
199 }
200};
201
202/// Creates functor that ignores all arguments.
203template <typename ReturnType, typename Object>
204MemFun0IgnoreArgs<ReturnType, Object>
205MemFunIgnoreArgs( Object& obj, ReturnType (Object:: *action)() ) {
206 return MemFun0IgnoreArgs<ReturnType, Object>(obj, action);
207}
208
209/// Creates functor that ignores second and third argument.
210template <typename ReturnType, typename Object, typename Arg1>
211MemFun1IgnoreArgs<ReturnType, Object, Arg1>
212MemFunIgnoreArgs( Object& obj, ReturnType (Object:: *action)(Arg1) ) {
213 return MemFun1IgnoreArgs<ReturnType, Object, Arg1>(obj, action);
214}
215
216/// Creates functor that ignores third argument.
217template <typename ReturnType, typename Object, typename Arg1, typename Arg2>
218MemFun2IgnoreArgs<ReturnType, Object, Arg1, Arg2>
219MemFunIgnoreArgs( Object& obj, ReturnType (Object:: *action)(Arg1,Arg2) ) {
220 return MemFun2IgnoreArgs<ReturnType, Object, Arg1, Arg2>(obj, action);
221}
222
223
136} // namespace FbTk 224} // namespace FbTk
137 225
138#endif // FBTK_MEM_FUN_HH 226#endif // FBTK_MEM_FUN_HH