1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef QTCONCURRENT_RUNEX_H
35 #define QTCONCURRENT_RUNEX_H
37 #include <qrunnable.h>
38 #include <qfutureinterface.h>
39 #include <qthreadpool.h>
43 namespace QtConcurrent {
45 template <typename T, typename FunctionPointer>
46 class StoredInterfaceFunctionCall0 : public QRunnable
49 StoredInterfaceFunctionCall0(void (fn)(QFutureInterface<T> &))
54 futureInterface.reportStarted();
55 QFuture<T> future = futureInterface.future();
56 QThreadPool::globalInstance()->start(this);
63 futureInterface.reportFinished();
66 QFutureInterface<T> futureInterface;
70 template <typename T, typename FunctionPointer, typename Class>
71 class StoredInterfaceMemberFunctionCall0 : public QRunnable
74 StoredInterfaceMemberFunctionCall0(void (Class::*fn)(QFutureInterface<T> &), Class *object)
75 : fn(fn), object(object) { }
79 futureInterface.reportStarted();
80 QFuture<T> future = futureInterface.future();
81 QThreadPool::globalInstance()->start(this);
87 (object->*fn)(futureInterface);
88 futureInterface.reportFinished();
91 QFutureInterface<T> futureInterface;
97 template <typename T, typename FunctionPointer, typename Arg1>
98 class StoredInterfaceFunctionCall1 : public QRunnable
101 StoredInterfaceFunctionCall1(void (fn)(QFutureInterface<T> &, Arg1), Arg1 arg1)
102 : fn(fn), arg1(arg1) { }
106 futureInterface.reportStarted();
107 QFuture<T> future = futureInterface.future();
108 QThreadPool::globalInstance()->start(this);
114 fn(futureInterface, arg1);
115 futureInterface.reportFinished();
118 QFutureInterface<T> futureInterface;
122 template <typename T, typename FunctionPointer, typename Class, typename Arg1>
123 class StoredInterfaceMemberFunctionCall1 : public QRunnable
126 StoredInterfaceMemberFunctionCall1(void (Class::*fn)(QFutureInterface<T> &, Arg1), Class *object, Arg1 arg1)
127 : fn(fn), object(object), arg1(arg1) { }
131 futureInterface.reportStarted();
132 QFuture<T> future = futureInterface.future();
133 QThreadPool::globalInstance()->start(this);
139 (object->*fn)(futureInterface, arg1);
140 futureInterface.reportFinished();
143 QFutureInterface<T> futureInterface;
149 template <typename T, typename FunctionPointer, typename Arg1, typename Arg2>
150 class StoredInterfaceFunctionCall2 : public QRunnable
153 StoredInterfaceFunctionCall2(void (fn)(QFutureInterface<T> &, Arg1, Arg2), Arg1 arg1, Arg2 arg2)
154 : fn(fn), arg1(arg1), arg2(arg2) { }
158 futureInterface.reportStarted();
159 QFuture<T> future = futureInterface.future();
160 QThreadPool::globalInstance()->start(this);
166 fn(futureInterface, arg1, arg2);
167 futureInterface.reportFinished();
170 QFutureInterface<T> futureInterface;
172 Arg1 arg1; Arg2 arg2;
174 template <typename T, typename FunctionPointer, typename Class, typename Arg1, typename Arg2>
175 class StoredInterfaceMemberFunctionCall2 : public QRunnable
178 StoredInterfaceMemberFunctionCall2(void (Class::*fn)(QFutureInterface<T> &, Arg1, Arg2), Class *object, Arg1 arg1, Arg2 arg2)
179 : fn(fn), object(object), arg1(arg1), arg2(arg2) { }
183 futureInterface.reportStarted();
184 QFuture<T> future = futureInterface.future();
185 QThreadPool::globalInstance()->start(this);
191 (object->*fn)(futureInterface, arg1, arg2);
192 futureInterface.reportFinished();
195 QFutureInterface<T> futureInterface;
198 Arg1 arg1; Arg2 arg2;
201 template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3>
202 class StoredInterfaceFunctionCall3 : public QRunnable
205 StoredInterfaceFunctionCall3(void (fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3)
206 : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3) { }
210 futureInterface.reportStarted();
211 QFuture<T> future = futureInterface.future();
212 QThreadPool::globalInstance()->start(this);
218 fn(futureInterface, arg1, arg2, arg3);
219 futureInterface.reportFinished();
222 QFutureInterface<T> futureInterface;
224 Arg1 arg1; Arg2 arg2; Arg3 arg3;
226 template <typename T, typename FunctionPointer, typename Class, typename Arg1, typename Arg2, typename Arg3>
227 class StoredInterfaceMemberFunctionCall3 : public QRunnable
230 StoredInterfaceMemberFunctionCall3(void (Class::*fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3)
231 : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3) { }
235 futureInterface.reportStarted();
236 QFuture<T> future = futureInterface.future();
237 QThreadPool::globalInstance()->start(this);
243 (object->*fn)(futureInterface, arg1, arg2, arg3);
244 futureInterface.reportFinished();
247 QFutureInterface<T> futureInterface;
250 Arg1 arg1; Arg2 arg2; Arg3 arg3;
253 template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
254 class StoredInterfaceFunctionCall4 : public QRunnable
257 StoredInterfaceFunctionCall4(void (fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
258 : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) { }
262 futureInterface.reportStarted();
263 QFuture<T> future = futureInterface.future();
264 QThreadPool::globalInstance()->start(this);
270 fn(futureInterface, arg1, arg2, arg3, arg4);
271 futureInterface.reportFinished();
274 QFutureInterface<T> futureInterface;
276 Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4;
278 template <typename T, typename FunctionPointer, typename Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
279 class StoredInterfaceMemberFunctionCall4 : public QRunnable
282 StoredInterfaceMemberFunctionCall4(void (Class::*fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
283 : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) { }
287 futureInterface.reportStarted();
288 QFuture<T> future = futureInterface.future();
289 QThreadPool::globalInstance()->start(this);
295 (object->*fn)(futureInterface, arg1, arg2, arg3, arg4);
296 futureInterface.reportFinished();
299 QFutureInterface<T> futureInterface;
302 Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4;
305 template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
306 class StoredInterfaceFunctionCall5 : public QRunnable
309 StoredInterfaceFunctionCall5(void (fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
310 : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) { }
314 futureInterface.reportStarted();
315 QFuture<T> future = futureInterface.future();
316 QThreadPool::globalInstance()->start(this);
322 fn(futureInterface, arg1, arg2, arg3, arg4, arg5);
323 futureInterface.reportFinished();
326 QFutureInterface<T> futureInterface;
328 Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5;
330 template <typename T, typename FunctionPointer, typename Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
331 class StoredInterfaceMemberFunctionCall5 : public QRunnable
334 StoredInterfaceMemberFunctionCall5(void (Class::*fn)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
335 : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) { }
339 futureInterface.reportStarted();
340 QFuture<T> future = futureInterface.future();
341 QThreadPool::globalInstance()->start(this);
347 (object->*fn)(futureInterface, arg1, arg2, arg3, arg4, arg5);
348 futureInterface.reportFinished();
351 QFutureInterface<T> futureInterface;
354 Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5;
357 template <typename T>
358 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &))
360 return (new StoredInterfaceFunctionCall0<T, void (*)(QFutureInterface<T> &)>(functionPointer))->start();
362 template <typename T, typename Arg1>
363 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1), Arg1 arg1)
365 return (new StoredInterfaceFunctionCall1<T, void (*)(QFutureInterface<T> &, Arg1), Arg1>(functionPointer, arg1))->start();
367 template <typename T, typename Arg1, typename Arg2>
368 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1, Arg2), Arg1 arg1, Arg2 arg2)
370 return (new StoredInterfaceFunctionCall2<T, void (*)(QFutureInterface<T> &, Arg1, Arg2), Arg1, Arg2>(functionPointer, arg1, arg2))->start();
372 template <typename T, typename Arg1, typename Arg2, typename Arg3>
373 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3)
375 return (new StoredInterfaceFunctionCall3<T, void (*)(QFutureInterface<T> &, Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(functionPointer, arg1, arg2, arg3))->start();
377 template <typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
378 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
380 return (new StoredInterfaceFunctionCall4<T, void (*)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4), Arg1, Arg2, Arg3, Arg4>(functionPointer, arg1, arg2, arg3, arg4))->start();
382 template <typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
383 QFuture<T> run(void (*functionPointer)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
385 return (new StoredInterfaceFunctionCall5<T, void (*)(QFutureInterface<T> &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1, Arg2, Arg3, Arg4, Arg5>(functionPointer, arg1, arg2, arg3, arg4, arg5))->start();
388 template <typename Class, typename T>
389 QFuture<T> run(void (Class::*fn)(QFutureInterface<T> &), Class *object)
391 return (new StoredInterfaceMemberFunctionCall0<T, void (Class::*)(QFutureInterface<T> &), Class>(fn, object))->start();
394 } // namespace QtConcurrent
398 #endif // QTCONCURRENT_RUNEX_H