LP-92 Remove Feed Forward : flight / ground
[librepilot.git] / ground / gcs / src / libs / qtconcurrent / runextensions.h
blob01c8cd533027dd693a3ea6ca24f88c498c26beed
1 /**
2 ******************************************************************************
4 * @file runextensions.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @brief
8 * @see The GNU Public License (GPL) Version 3
9 * @defgroup
10 * @{
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef QTCONCURRENT_RUNEX_H
30 #define QTCONCURRENT_RUNEX_H
32 #include <qrunnable.h>
33 #include <qfutureinterface.h>
34 #include <qthreadpool.h>
36 QT_BEGIN_NAMESPACE
38 namespace QtConcurrent {
39 template <typename T, typename FunctionPointer>
40 class StoredInterfaceFunctionCall0 : public QRunnable {
41 public:
42 StoredInterfaceFunctionCall0(void(fn)(QFutureInterface<T> &))
43 : fn(fn) {}
45 QFuture<T> start()
47 futureInterface.reportStarted();
48 QFuture<T> future = futureInterface.future();
49 QThreadPool::globalInstance()->start(this);
50 return future;
53 void run()
55 fn(futureInterface);
56 futureInterface.reportFinished();
58 private:
59 QFutureInterface<T> futureInterface;
60 FunctionPointer fn;
62 template <typename T, typename FunctionPointer, typename Class>
63 class StoredInterfaceMemberFunctionCall0 : public QRunnable {
64 public:
65 StoredInterfaceMemberFunctionCall0(void(Class::*fn)(QFutureInterface<T> &), Class *object)
66 : fn(fn), object(object) {}
68 QFuture<T> start()
70 futureInterface.reportStarted();
71 QFuture<T> future = futureInterface.future();
72 QThreadPool::globalInstance()->start(this);
73 return future;
76 void run()
78 (object->*fn)(futureInterface);
79 futureInterface.reportFinished();
81 private:
82 QFutureInterface<T> futureInterface;
83 FunctionPointer fn;
84 Class *object;
87 template <typename T, typename FunctionPointer, typename Arg1>
88 class StoredInterfaceFunctionCall1 : public QRunnable {
89 public:
90 StoredInterfaceFunctionCall1(void(fn)(QFutureInterface<T> &, Arg1), Arg1 arg1)
91 : fn(fn), arg1(arg1) {}
93 QFuture<T> start()
95 futureInterface.reportStarted();
96 QFuture<T> future = futureInterface.future();
97 QThreadPool::globalInstance()->start(this);
98 return future;
101 void run()
103 fn(futureInterface, arg1);
104 futureInterface.reportFinished();
106 private:
107 QFutureInterface<T> futureInterface;
108 FunctionPointer fn;
109 Arg1 arg1;
111 template <typename T, typename FunctionPointer, typename Class, typename Arg1>
112 class StoredInterfaceMemberFunctionCall1 : public QRunnable {
113 public:
114 StoredInterfaceMemberFunctionCall1(void(Class::*fn)(QFutureInterface<T> &, Arg1), Class *object, Arg1 arg1)
115 : fn(fn), object(object), arg1(arg1) {}
117 QFuture<T> start()
119 futureInterface.reportStarted();
120 QFuture<T> future = futureInterface.future();
121 QThreadPool::globalInstance()->start(this);
122 return future;
125 void run()
127 (object->*fn)(futureInterface, arg1);
128 futureInterface.reportFinished();
130 private:
131 QFutureInterface<T> futureInterface;
132 FunctionPointer fn;
133 Class *object;
134 Arg1 arg1;
137 template <typename T, typename FunctionPointer, typename Arg1, typename Arg2>
138 class StoredInterfaceFunctionCall2 : public QRunnable {
139 public:
140 StoredInterfaceFunctionCall2(void(fn)(QFutureInterface<T> &, Arg1, Arg2), Arg1 arg1, Arg2 arg2)
141 : fn(fn), arg1(arg1), arg2(arg2) {}
143 QFuture<T> start()
145 futureInterface.reportStarted();
146 QFuture<T> future = futureInterface.future();
147 QThreadPool::globalInstance()->start(this);
148 return future;
151 void run()
153 fn(futureInterface, arg1, arg2);
154 futureInterface.reportFinished();
156 private:
157 QFutureInterface<T> futureInterface;
158 FunctionPointer fn;
159 Arg1 arg1; Arg2 arg2;
161 template <typename T, typename FunctionPointer, typename Class, typename Arg1, typename Arg2>
162 class StoredInterfaceMemberFunctionCall2 : public QRunnable {
163 public:
164 StoredInterfaceMemberFunctionCall2(void(Class::*fn)(QFutureInterface<T> &, Arg1, Arg2), Class *object, Arg1 arg1, Arg2 arg2)
165 : fn(fn), object(object), arg1(arg1), arg2(arg2) {}
167 QFuture<T> start()
169 futureInterface.reportStarted();
170 QFuture<T> future = futureInterface.future();
171 QThreadPool::globalInstance()->start(this);
172 return future;
175 void run()
177 (object->*fn)(futureInterface, arg1, arg2);
178 futureInterface.reportFinished();
180 private:
181 QFutureInterface<T> futureInterface;
182 FunctionPointer fn;
183 Class *object;
184 Arg1 arg1; Arg2 arg2;
187 template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3>
188 class StoredInterfaceFunctionCall3 : public QRunnable {
189 public:
190 StoredInterfaceFunctionCall3(void(fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3)
191 : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3) {}
193 QFuture<T> start()
195 futureInterface.reportStarted();
196 QFuture<T> future = futureInterface.future();
197 QThreadPool::globalInstance()->start(this);
198 return future;
201 void run()
203 fn(futureInterface, arg1, arg2, arg3);
204 futureInterface.reportFinished();
206 private:
207 QFutureInterface<T> futureInterface;
208 FunctionPointer fn;
209 Arg1 arg1; Arg2 arg2; Arg3 arg3;
211 template <typename T, typename FunctionPointer, typename Class, typename Arg1, typename Arg2, typename Arg3>
212 class StoredInterfaceMemberFunctionCall3 : public QRunnable {
213 public:
214 StoredInterfaceMemberFunctionCall3(void(Class::*fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3)
215 : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3) {}
217 QFuture<T> start()
219 futureInterface.reportStarted();
220 QFuture<T> future = futureInterface.future();
221 QThreadPool::globalInstance()->start(this);
222 return future;
225 void run()
227 (object->*fn)(futureInterface, arg1, arg2, arg3);
228 futureInterface.reportFinished();
230 private:
231 QFutureInterface<T> futureInterface;
232 FunctionPointer fn;
233 Class *object;
234 Arg1 arg1; Arg2 arg2; Arg3 arg3;
237 template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
238 class StoredInterfaceFunctionCall4 : public QRunnable {
239 public:
240 StoredInterfaceFunctionCall4(void(fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
241 : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) {}
243 QFuture<T> start()
245 futureInterface.reportStarted();
246 QFuture<T> future = futureInterface.future();
247 QThreadPool::globalInstance()->start(this);
248 return future;
251 void run()
253 fn(futureInterface, arg1, arg2, arg3, arg4);
254 futureInterface.reportFinished();
256 private:
257 QFutureInterface<T> futureInterface;
258 FunctionPointer fn;
259 Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4;
261 template <typename T, typename FunctionPointer, typename Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
262 class StoredInterfaceMemberFunctionCall4 : public QRunnable {
263 public:
264 StoredInterfaceMemberFunctionCall4(void(Class::*fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
265 : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) {}
267 QFuture<T> start()
269 futureInterface.reportStarted();
270 QFuture<T> future = futureInterface.future();
271 QThreadPool::globalInstance()->start(this);
272 return future;
275 void run()
277 (object->*fn)(futureInterface, arg1, arg2, arg3, arg4);
278 futureInterface.reportFinished();
280 private:
281 QFutureInterface<T> futureInterface;
282 FunctionPointer fn;
283 Class *object;
284 Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4;
287 template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
288 class StoredInterfaceFunctionCall5 : public QRunnable {
289 public:
290 StoredInterfaceFunctionCall5(void(fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
291 : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) {}
293 QFuture<T> start()
295 futureInterface.reportStarted();
296 QFuture<T> future = futureInterface.future();
297 QThreadPool::globalInstance()->start(this);
298 return future;
301 void run()
303 fn(futureInterface, arg1, arg2, arg3, arg4, arg5);
304 futureInterface.reportFinished();
306 private:
307 QFutureInterface<T> futureInterface;
308 FunctionPointer fn;
309 Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5;
311 template <typename T, typename FunctionPointer, typename Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
312 class StoredInterfaceMemberFunctionCall5 : public QRunnable {
313 public:
314 StoredInterfaceMemberFunctionCall5(void(Class::*fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
315 : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) {}
317 QFuture<T> start()
319 futureInterface.reportStarted();
320 QFuture<T> future = futureInterface.future();
321 QThreadPool::globalInstance()->start(this);
322 return future;
325 void run()
327 (object->*fn)(futureInterface, arg1, arg2, arg3, arg4, arg5);
328 futureInterface.reportFinished();
330 private:
331 QFutureInterface<T> futureInterface;
332 FunctionPointer fn;
333 Class *object;
334 Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5;
337 template <typename T>
338 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &))
340 return (new StoredInterfaceFunctionCall0<T, void (*)(QFutureInterface<T> &)>(functionPointer))->start();
342 template <typename T, typename Arg1>
343 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1), Arg1 arg1)
345 return (new StoredInterfaceFunctionCall1<T, void (*)(QFutureInterface<T> &, Arg1), Arg1>(functionPointer, arg1))->start();
347 template <typename T, typename Arg1, typename Arg2>
348 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1, Arg2), Arg1 arg1, Arg2 arg2)
350 return (new StoredInterfaceFunctionCall2<T, void (*)(QFutureInterface<T> &, Arg1, Arg2), Arg1, Arg2>(functionPointer, arg1, arg2))->start();
352 template <typename T, typename Arg1, typename Arg2, typename Arg3>
353 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3)
355 return (new StoredInterfaceFunctionCall3<T, void (*)(QFutureInterface<T> &, Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(functionPointer, arg1, arg2, arg3))->start();
357 template <typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
358 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
360 return (new StoredInterfaceFunctionCall4<T, void (*)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4), Arg1, Arg2, Arg3, Arg4>(functionPointer, arg1, arg2, arg3, arg4))->start();
362 template <typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
363 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
365 return (new StoredInterfaceFunctionCall5<T, void (*)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1, Arg2, Arg3, Arg4, Arg5>(functionPointer, arg1, arg2, arg3, arg4, arg5))->start();
368 template <typename Class, typename T>
369 QFuture<T> run(void (Class::*fn)(QFutureInterface<T> &), Class *object)
371 return (new StoredInterfaceMemberFunctionCall0<T, void(Class::*) (QFutureInterface<T> &), Class>(fn, object))->start();
373 } // namespace QtConcurrent
375 QT_END_NAMESPACE
377 #endif // QTCONCURRENT_RUNEX_H