Mercurial > projects > qtd
annotate generator/typesystem_core-java.java @ 125:76e5e8597a83
fixes for ldc on windows
author | eldar |
---|---|
date | Fri, 05 Jun 2009 14:54:20 +0000 |
parents | ba63040afbf2 |
children | 39921f499a22 |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 package generator; | |
43 | |
44 import qt.*; | |
45 import qt.core.*; | |
46 | |
47 class QObject___ extends QObject { | |
48 | |
49 // list of QObjects references to prevent them from garbage collecting if they are managed by Qt | |
50 private static QObject[] __gc_ref_list; | |
51 | |
52 // this flag controls whether QObject is managed by D's GC, or it has a parent and therefore managed by Qt | |
53 private bool __gc_managed = true; | |
54 | |
55 // this flag needs to be set false when QObject is deleted from inside Qt so when deleting it from D it won't delete C++ object | |
56 public bool __no_real_delete = false; | |
57 }// class | |
58 | |
59 abstract class QAbstractItemModel___ extends QAbstractItemModel { | |
60 /* private native boolean setData_native(long id, int row, int col, Object value, int role); | |
61 | |
62 public final boolean setData(int row, int col, Object value) { | |
63 return setData_native(nativeId(), row, col, value, qt.core.Qt.ItemDataRole.DisplayRole); | |
64 } | |
65 | |
66 public final boolean setData(int row, int col, Object value, int role) { | |
67 return setData_native(nativeId(), row, col, value, role); | |
68 } | |
69 | |
70 private native Object data_native(long id, int row, int col, int role); | |
71 | |
72 public final Object data(int row, int col, int role) { | |
73 return data_native(nativeId(), row, col, role); | |
74 } | |
75 | |
76 public final Object data(int row, int col) { | |
77 return data_native(nativeId(), row, col, Qt.ItemDataRole.DisplayRole); | |
78 }*/ | |
79 }// class | |
80 | |
81 class QTimer___ extends QTimer { | |
82 static private class QSingleShotTimer extends QObject { | |
83 private int timerId = -1; | |
84 public Signal0 timeout = new Signal0(); | |
85 | |
86 public QSingleShotTimer(int msec, QObject obj, String method) { | |
87 super(obj); | |
88 timeout.connect(obj, method); | |
89 timerId = startTimer(msec); | |
90 } | |
91 | |
92 protected void disposed() { | |
93 if (timerId > 0) | |
94 killTimer(timerId); | |
95 super.disposed(); | |
96 } | |
97 | |
98 protected void timerEvent(QTimerEvent e) { | |
99 if (timerId > 0) | |
100 killTimer(timerId); | |
101 timerId = -1; | |
102 timeout.emit(); | |
103 disposeLater(); | |
104 } | |
105 } | |
106 | |
107 public static void singleShot(int msec, QObject obj, String method) { | |
108 new QSingleShotTimer(msec, obj, method); | |
109 } | |
110 }// class | |
111 | |
112 class QCoreApplication___ extends QCoreApplication { | |
113 | |
114 protected static QCoreApplication m_instance = null; | |
115 | |
90 | 116 this(in string[] args) |
1 | 117 { |
118 // if (m_instance != null) | |
119 // throw new RuntimeException("QCoreApplication can only be initialized once"); | |
120 | |
121 argc = args.length; | |
122 argv = toStringzArray(args); | |
123 this(&argc, argv); | |
124 | |
125 // m_instance.aboutToQuit.connect(m_instance, "disposeOfMyself()"); | |
126 } | |
127 | |
128 private int argc; | |
129 private char **argv; | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
130 /* |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
131 public static string translate(string context, string key, string disambiguation, QCoreApplication_Encoding encoding) { |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
132 string res; |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
133 qtd_QCoreApplication_translate_nativepointerchar_nativepointerchar_nativepointerchar_Encoding(&res, toStringz(context), toStringz(key), toStringz(disambiguation), encoding); |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
134 return res; |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
135 } |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
136 |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
137 public static string translate(string context, string key, string disambiguation, QCoreApplication_Encoding encoding, int n) { |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
138 string res; |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
139 qtd_QCoreApplication_translate_nativepointerchar_nativepointerchar_nativepointerchar_Encoding_int(&res, toStringz(context), toStringz(key), toStringz(disambiguation), encoding, n); |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
140 return res; |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
141 } |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
142 */ |
1 | 143 }// class |
144 | |
145 class QTranslator___ extends QTranslator { | |
146 public final bool load(ubyte[] data) { | |
147 return load(data.ptr, data.length); | |
148 } | |
149 }// class | |
150 | |
151 class QProcess___ extends QProcess { | |
152 | |
153 public static class DetachedProcessInfo { | |
154 public DetachedProcessInfo(boolean success, long pid) { | |
155 this.success = success; | |
156 this.pid = pid; | |
157 } | |
158 | |
159 public boolean success; | |
160 public long pid; | |
161 } | |
162 | |
163 public static DetachedProcessInfo startDetached(String program, java.util.List<String> arguments, String workingDirectory) { | |
164 QNativePointer pid = new QNativePointer(QNativePointer.Type.Long); | |
165 boolean success = startDetached(program, arguments, workingDirectory, pid); | |
166 return new DetachedProcessInfo(success, pid.longValue()); | |
167 } | |
168 }// class | |
169 | |
170 class QDataStream___ extends QDataStream { | |
171 | |
172 public final bool readBoolean() { | |
173 bool res; | |
174 operator_shift_right_boolean(&res); | |
175 return res; | |
176 } | |
177 | |
178 public final byte readByte() { | |
179 byte res; | |
180 operator_shift_right_byte(&res); | |
181 return res; | |
182 } | |
183 | |
184 public final short readShort() { | |
185 short res; | |
186 operator_shift_right_short(&res); | |
187 return res; | |
188 } | |
189 | |
190 public final int readInt() { | |
191 int res; | |
192 operator_shift_right_int(&res); | |
193 return res; | |
194 } | |
195 | |
196 public final long readLong() { | |
197 long res; | |
198 operator_shift_right_long(&res); | |
199 return res; | |
200 } | |
201 | |
202 public final ushort readChar() { | |
203 ushort res; | |
204 operator_shift_right_char(&res); | |
205 return res; | |
206 } | |
207 | |
208 public final float readFloat() { | |
209 float res; | |
210 operator_shift_right_float(&res); | |
211 return res; | |
212 } | |
213 | |
214 public final double readDouble() { | |
215 double res; | |
216 operator_shift_right_double(&res); | |
217 return res; | |
218 } | |
219 | |
220 public final QDataStream writeShort(short s) { | |
221 writeShort_char(s); | |
222 return this; | |
223 } | |
224 /* | |
225 private static extern(C) void qtd_QDataStream_readString_private(void* __this_nativeId); | |
226 | |
227 private native void writeString_private(long nativeId, String string); | |
228 | |
229 public final String readString() { | |
230 if (nativeId() == 0) | |
231 throw new QNoNativeResourcesException("Function call on incomplete object of type: " + getClass().getName()); | |
232 return readString_private(nativeId()); | |
233 } | |
234 | |
235 public final void writeString(String string) { | |
236 if (nativeId() == 0) | |
237 throw new QNoNativeResourcesException("Function call on incomplete object of type: " + getClass().getName()); | |
238 writeString_private(nativeId(), string); | |
239 } | |
240 | |
241 private native int writeBytes(long id, byte buffer[], int length); | |
242 | |
243 private native int readBytes(long id, byte buffer[], int length); | |
244 | |
245 public final int writeBytes(byte buffer[]) { | |
246 return writeBytes(buffer, buffer.length); | |
247 } | |
248 | |
249 public final int writeBytes(byte buffer[], int length) { | |
250 return writeBytes(nativeId(), buffer, length); | |
251 } | |
252 | |
253 public final int readBytes(byte buffer[]) { | |
254 return readBytes(buffer, buffer.length); | |
255 } | |
256 | |
257 public final int readBytes(byte buffer[], int length) { | |
258 return readBytes(nativeId(), buffer, length); | |
259 } | |
260 */ | |
261 }// class | |
262 | |
263 class QTextStream___ extends QTextStream { | |
264 /* public final void setCodec(String codecName) { | |
265 setCodec(QNativePointer.createCharPointer(codecName)); | |
266 if (codec() != __rcCodec) | |
267 __rcCodec = null; | |
268 } | |
269 | |
270 private QNativePointer srb = new QNativePointer(QNativePointer.Type.Byte, 32) { | |
271 { | |
272 setVerificationEnabled(false); | |
273 } | |
274 }; | |
275 | |
276 public final byte readByte() { | |
277 operator_shift_right_byte(srb); | |
278 return srb.byteValue(); | |
279 } | |
280 | |
281 public final short readShort() { | |
282 operator_shift_right_short(srb); | |
283 return srb.shortValue(); | |
284 } | |
285 | |
286 public final int readInt() { | |
287 operator_shift_right_int(srb); | |
288 return srb.intValue(); | |
289 } | |
290 | |
291 public final long readLong() { | |
292 operator_shift_right_long(srb); | |
293 return srb.longValue(); | |
294 } | |
295 | |
296 public final float readFloat() { | |
297 operator_shift_right_float(srb); | |
298 return srb.floatValue(); | |
299 } | |
300 | |
301 public final double readDouble() { | |
302 operator_shift_right_double(srb); | |
303 return srb.doubleValue(); | |
304 } | |
305 | |
306 public final QTextStream writeShort(short s) { | |
307 writeShort_char((char) s); | |
308 return this; | |
309 } | |
310 | |
311 public final QTextStream writeChar(char c) { | |
312 writeShort_char(c); | |
313 return this; | |
314 } | |
315 | |
316 public final char readChar() { | |
317 operator_shift_right_short(srb); | |
318 return srb.charValue(); | |
319 } | |
320 | |
321 public final String readString() { | |
322 return readString_native(nativeId()); | |
323 } | |
324 | |
325 public final void writeString(String string) { | |
326 writeString_native(nativeId(), string); | |
327 } | |
328 | |
329 private final native String readString_native(long id); | |
330 | |
331 private final native void writeString_native(long id, String string); | |
332 */ | |
333 }// class | |
334 | |
335 class QBitArray___ extends QBitArray { | |
336 /* | |
337 @qt.QtBlockedSlot | |
338 public final void xor(QBitArray other) { | |
339 operator_xor_assign(other); | |
340 } | |
341 | |
342 @qt.QtBlockedSlot | |
343 public final void and(QBitArray other) { | |
344 operator_and_assign(other); | |
345 } | |
346 | |
347 @qt.QtBlockedSlot | |
348 public final void or(QBitArray other) { | |
349 operator_or_assign(other); | |
350 } | |
351 | |
352 @qt.QtBlockedSlot | |
353 public final void set(QBitArray other) { | |
354 operator_assign(other); | |
355 } | |
356 | |
357 @qt.QtBlockedSlot | |
358 public final QBitArray inverted() { | |
359 return operator_negate(); | |
360 } | |
361 */ | |
362 }// class | |
363 | |
364 // hfr | |
365 | |
366 class QDate___ extends QDate { | |
367 | |
368 public final int weekNumber() { | |
369 return weekNumber(null); | |
370 } | |
371 | |
372 public final int yearOfWeekNumber() { | |
373 int np; | |
374 weekNumber(&np); | |
375 return np; | |
376 } | |
377 | |
378 }// class | |
379 | |
380 class QDir___ extends QDir { | |
381 /* | |
382 @qt.QtBlockedSlot | |
383 public String at(int i) { | |
384 return operator_subscript(i); | |
385 } | |
386 */ | |
387 }// class | |
388 | |
389 class QByteArray___ extends QByteArray { | |
390 public QByteArray(String s) { | |
391 this(); | |
392 append(s); | |
393 } | |
394 | |
395 public QByteArray(byte data[]) { | |
396 this(qt.internal.QtJambiInternal.byteArrayToNativePointer(data), data.length); | |
397 } | |
398 | |
399 public final boolean contains(String str) { | |
400 return contains(new QByteArray(str)); | |
401 } | |
402 | |
403 public final int count(String str) { | |
404 return count(new QByteArray(str)); | |
405 } | |
406 | |
407 public final boolean endsWith(String str) { | |
408 return endsWith(new QByteArray(str)); | |
409 } | |
410 | |
411 public final QByteArray prepend(String str) { | |
412 return prepend(new QByteArray(str)); | |
413 } | |
414 | |
415 public final QByteArray replace(QByteArray before, String after) { | |
416 return replace(before, new QByteArray(after)); | |
417 } | |
418 | |
419 public final QByteArray replace(String before, String after) { | |
420 return replace(new QByteArray(before), new QByteArray(after)); | |
421 } | |
422 | |
423 public final boolean startsWith(String str) { | |
424 return startsWith(new QByteArray(str)); | |
425 } | |
426 | |
427 public final byte[] toByteArray() { | |
428 byte[] res = new byte[size()]; | |
429 | |
430 for (int i = 0; i < size(); i++) { | |
431 res[i] = at(i); | |
432 } | |
433 return res; | |
434 } | |
435 | |
436 @qt.QtBlockedSlot | |
437 public final QByteArray set(QByteArray other) { | |
438 operator_assign(other); | |
439 return this; | |
440 } | |
441 | |
442 }// class | |
443 | |
444 class QFile___ extends QFile { | |
445 /* | |
446 public static String decodeName(String localFileName) { | |
447 return decodeName(qt.QNativePointer.createCharPointer(localFileName)); | |
448 } | |
449 */ | |
450 }// class | |
451 | |
452 class QIODevice___ extends QIODevice { | |
453 | |
454 /** | |
455 * Gets a byte from the device. | |
456 * | |
457 * @return -1 on failure, or the value of the byte on success | |
458 */ | |
459 /* public final int getByte() { | |
460 QNativePointer np = new QNativePointer(QNativePointer.Type.Byte); | |
461 boolean success = getByte(np); | |
462 return success ? np.byteValue() : -1; | |
463 } | |
464 */ | |
465 }// class | |
466 | |
467 class QCryptographicHash___ extends QCryptographicHash { | |
468 | |
469 public final void addData(byte data[]) { | |
470 QNativePointer np = qt.internal.QtJambiInternal.byteArrayToNativePointer(data); | |
471 addData(np, data.length); | |
472 } | |
473 | |
474 }// class | |
475 | |
476 class QTextCodec___ extends QTextCodec { | |
477 /* | |
478 static { | |
479 setCodecForTr(QTextCodec.codecForName("UTF-8")); | |
480 } | |
481 | |
482 public static QTextCodec codecForName(String name) { | |
483 return codecForName(qt.QNativePointer.createCharPointer(name)); | |
484 } | |
485 */ | |
486 }// class | |
487 | |
488 class QBuffer___ extends QBuffer { | |
489 | |
490 // retain a reference to avoid gc | |
491 private Object strongDataReference = null; | |
492 public final void setBuffer(QByteArray byteArray) { | |
90 | 493 setBuffer_private(byteArray); |
1 | 494 strongDataReference = byteArray; |
495 } | |
496 | |
497 public final void setData(byte data[]) { | |
90 | 498 setData(cast(char*)data.ptr, data.length); |
1 | 499 } |
500 | |
501 }// class | |
502 | |
503 class QSignalMapper___ extends QSignalMapper { | |
504 | |
505 private java.util.Hashtable<QObject, QObject> __rcObjectForObject = new java.util.Hashtable<QObject, QObject>(); | |
506 | |
507 private java.util.Hashtable<QObject, Object> __rcWidgetForObject = new java.util.Hashtable<QObject, Object>(); | |
508 | |
509 }// class | |
510 | |
511 class QAbstractFileEngine_MapExtensionReturn___ extends QAbstractFileEngine_MapExtensionReturn { | |
512 /* private QNativePointer currentAddressNativePointer; // don't garbage collect while in use | |
513 public final void setAddress(String address) { | |
514 currentAddressNativePointer = address != null ? QNativePointer.createCharPointer(address) : null; | |
515 address_private(currentAddressNativePointer); | |
516 } | |
517 | |
518 public final String address() { | |
519 QNativePointer np = address_private(); | |
520 return np != null ? qt.internal.QtJambiInternal.charPointerToString(np) : null; | |
521 }*/ | |
522 }// class | |
523 | |
524 class QAbstractFileEngine___ extends QAbstractFileEngine { | |
525 /** | |
526 * Adds <tt>path</tt> to the set of paths in which Qt Jambi should search for resources. Resources | |
527 * can be accessed using the "classpath:" scheme. | |
528 */ | |
529 /* public static void addSearchPathForResourceEngine(String path) | |
530 { | |
531 qt.internal.QClassPathEngine.addSearchPath(path); | |
532 } | |
533 */ | |
534 /** | |
535 * Removes <tt>path</tt> from the set of paths in which Qt Jambi searches | |
536 * for resources. | |
537 */ | |
538 /* public static void removeSearchPathForResourceEngine(String path) | |
539 { | |
540 qt.internal.QClassPathEngine.removeSearchPath(path); | |
541 } | |
542 */ | |
543 }// class | |
544 | |
545 class QAbstractFileEngine_UnMapExtensionOption___ extends QAbstractFileEngine_UnMapExtensionOption { | |
546 private QNativePointer currentAddressNativePointer; // don't garbage collect while in use | |
547 public final void setAddress(String address) { | |
548 currentAddressNativePointer = address != null ? QNativePointer.createCharPointer(address) : null; | |
549 address_private(currentAddressNativePointer); | |
550 } | |
551 | |
552 public final String address() { | |
553 QNativePointer np = address_private(); | |
554 return np != null ? qt.internal.QtJambiInternal.charPointerToString(np) : null; | |
555 } | |
556 }// class | |
557 | |
558 class QFutureWatcher___ extends QFutureWatcher { | |
559 | |
560 public final QFuture<T> future() { | |
561 if (nativeId() == 0) | |
562 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
563 return __qt_future(nativeId()); | |
564 } | |
565 private native QFuture<T> __qt_future(long nativeId); | |
566 | |
567 }// class | |
568 | |
569 class QFutureWatcherVoid___ extends QFutureWatcherVoid { | |
570 | |
571 public final QFutureVoid future() { | |
572 if (nativeId() == 0) | |
573 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
574 return __qt_future(nativeId()); | |
575 } | |
576 | |
577 private native QFutureVoid __qt_future(long nativeId); | |
578 | |
579 }// class | |
580 | |
581 class QFutureSynchronizer___ extends QFutureSynchronizer { | |
582 | |
583 public final java.util.List<QFuture<T>> futures() { | |
584 if (nativeId() == 0) | |
585 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
586 return __qt_futures(nativeId()); | |
587 } | |
588 private native java.util.List<QFuture<T>> __qt_futures(long nativeId); | |
589 | |
590 }// class | |
591 | |
592 class QFutureSynchronizerVoid___ extends QFutureSynchronizerVoid { | |
593 | |
594 public final java.util.List<QFutureVoid> futures() { | |
595 if (nativeId() == 0) | |
596 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
597 return __qt_futures(nativeId()); | |
598 } | |
599 private native java.util.List<QFutureVoid> __qt_futures(long nativeId); | |
600 | |
601 }// class | |
602 | |
603 class QLineF___ extends QLineF { | |
604 /* | |
605 public final QLineF.IntersectType intersect(QLineF line, qt.core.QPointF intersectionPoint) { | |
606 return intersect(line, intersectionPoint != null ? intersectionPoint.nativePointer() : null); | |
607 } | |
608 */ | |
609 }// class | |
610 | |
611 /** | |
612 The QtConcurrent class contains static methods for running computations in parallel (using separate threads) | |
613 on the items in a java.util.Collection, such as a Vector or LinkedList. We will now describe these methods. | |
614 | |
615 The QtConcurrent::map(), QtConcurrent::mapped() and QtConcurrent::mappedReduced() functions run computations in parallel on the items in a sequence such as a QList or a QVector. QtConcurrent::map() modifies a sequence in-place, QtConcurrent::mapped() returns a new sequence containing the modified content, and QtConcurrent::mappedReduced() returns a single result. | |
616 Concurrent Map | |
617 <p> | |
618 QtConcurrent::mapped() takes an input sequence and a map function. This map function is then called for each item in the sequence, and a new sequence containing the return values from the map function is returned. | |
619 <p> | |
620 The map function must be of the form: | |
621 <pre> | |
622 U function(const T &t); | |
623 </pre> | |
624 T and U can be any type (and they can even be the same type), but T must match the type stored in the sequence. The function returns the modified or mapped content. | |
625 <p> | |
626 This example shows how to apply a scale function to all the items in a sequence: | |
627 <pre> | |
628 QImage scaled(const QImage &image) | |
629 { | |
630 return image.scaled(100, 100); | |
631 } | |
632 | |
633 QList <QImage> images = ...; | |
634 QFuture<QImage> thumbnails = QtConcurrent::mapped(images, scaled); | |
635 </pre> | |
636 The results of the map are made available through QFuture. See the QFuture and QFutureWatcher documentation for more information on how to use QFuture in your applications. | |
637 <p> | |
638 If you want to modify a sequence in-place, use QtConcurrent::map(). The map function must then be of the form: | |
639 <pre> | |
640 U function(T &t); | |
641 </pre> | |
642 Note that the return value and return type of the map function are not used. | |
643 <p> | |
644 Using QtConcurrent::map() is similar to using QtConcurrent::mapped(): | |
645 <pre> | |
646 void scale(QImage &image) | |
647 { | |
648 image = image.scaled(100, 100); | |
649 } | |
650 | |
651 QList<QImage> images = ...; | |
652 QFuture<void> future = QtConcurrent::map(images, scale); | |
653 </pre> | |
654 Since the sequence is modified in place, QtConcurrent::map() does not return any results via QFuture. However, you can still use QFuture and QFutureWatcher to monitor the status of the map. | |
655 Concurrent Map-Reduce | |
656 <p> | |
657 QtConcurrent::mappedReduced() is similar to QtConcurrent::mapped(), but instead of returning a sequence with the new results, the results are combined into a single value using a reduce function. | |
658 <p> | |
659 The reduce function must be of the form: | |
660 <pre> | |
661 V function(T &result, const U &intermediate) | |
662 </pre> | |
663 T is the type of the final result, U is the return type of the map function. Note that the return value and return type of the reduce function are not used. | |
664 <p> | |
665 Call QtConcurrent::mappedReduced() like this: | |
666 <pre> | |
667 void addToCollage(QImage &collage, const QImage &thumbnail) | |
668 { | |
669 QPainter p(&collage); | |
670 static QPoint offset = QPoint(0, 0); | |
671 p.drawImage(offset, thumbnail); | |
672 offset += ...; | |
673 } | |
674 | |
675 QList<QImage> images = ...; | |
676 QFuture<QImage> collage = QtConcurrent::mappedReduced(images, scaled, addToCollage); | |
677 </pre> | |
678 The reduce function will be called once for each result returned by the map function, and should merge the intermediate into the result variable. QtConcurrent::mappedReduced() guarantees that only one thread will call reduce at a time, so using a mutex to lock the result variable is not neccesary. The QtConcurrent::ReduceOptions enum provides a way to control the order in which the reduction is done. If QtConcurrent::UnorderedReduce is used (the default), the order is undefined, while QtConcurrent::OrderedReduce ensures that the reduction is done in the order of the original sequence. | |
679 Additional API Features | |
680 Using Iterators instead of Sequence | |
681 <p> | |
682 Each of the above functions has a variant that takes an iterator range instead of a sequence. You use them in the same way as the sequence variants: | |
683 <pre> | |
684 QList<QImage> images = ...; | |
685 | |
686 QFuture<QImage> thumbnails = QtConcurrent::mapped(images.constBegin(), images.constEnd(), scaled); | |
687 | |
688 // map in-place only works on non-const iterators | |
689 QFuture<void> future = QtConcurrent::map(images.begin(), images.end(), scale); | |
690 | |
691 QFuture<QImage> collage = QtConcurrent::mappedReduced(images.constBegin(), images.constEnd(), scaled, addToCollage); | |
692 </pre> | |
693 Blocking Variants | |
694 <p> | |
695 Each of the above functions has a blocking variant that returns the final result instead of a QFuture. You use them in the same way as the asynchronous variants. | |
696 <pre> | |
697 QList<QImage> images = ...; | |
698 | |
699 // each call blocks until the entire operation is finished | |
700 QList<QImage> future = QtConcurrent::blockingMapped(images, scaled); | |
701 | |
702 QtConcurrent::blockingMap(images, scale); | |
703 | |
704 QImage collage = QtConcurrent::blockingMappedReduced(images, scaled, addToCollage); | |
705 </pre> | |
706 Note that the result types above are not QFuture objects, but real result types (in this case, QList<QImage> and QImage). | |
707 Using Member Functions | |
708 <p> | |
709 QtConcurrent::map(), QtConcurrent::mapped(), and QtConcurrent::mappedReduced() accept pointers to member functions. The member function class type must match the type stored in the sequence: | |
710 <pre> | |
711 // squeeze all strings in a QStringList | |
712 QStringList strings = ...; | |
713 QFuture<void> squeezedStrings = QtConcurrent::map(strings, &QString::squeeze); | |
714 | |
715 // swap the rgb values of all pixels on a list of images | |
716 QList<QImage> images = ...; | |
717 QFuture<QImage> bgrImages = QtConcurrent::mapped(images, &QImage::rgbSwapped); | |
718 | |
719 // create a set of the lengths of all strings in a list | |
720 QStringList strings = ...; | |
721 QFuture<QSet<int> > wordLengths = QtConcurrent::mappedReduced(string, &QString::length, &QSet<int>::insert); | |
722 </pre> | |
723 Note that when using QtConcurrent::mappedReduced(), you can mix the use of normal and member functions freely: | |
724 <p> | |
725 <pre> | |
726 // can mix normal functions and member functions with QtConcurrent::mappedReduced() | |
727 | |
728 // compute the average length of a list of strings | |
729 extern void computeAverage(int &average, int length); | |
730 QStringList strings = ...; | |
731 QFuture<int> averageWordLength = QtConcurrent::mappedReduced(strings, &QString::length, computeAverage); | |
732 | |
733 // create a set of the color distribution of all images in a list | |
734 extern int colorDistribution(const QImage &string); | |
735 QList<QImage> images = ...; | |
736 QFuture<QSet<int> > totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution, QSet<int>::insert); | |
737 </pre> | |
738 Using Function Objects | |
739 <p> | |
740 QtConcurrent::map(), QtConcurrent::mapped(), and QtConcurrent::mappedReduced() accept function objects, which can be used to add state to a function call. The result_type typedef must define the result type of the function call operator: | |
741 <pre> | |
742 struct Scaled | |
743 { | |
744 Scaled(int size) | |
745 : m_size(size) { } | |
746 | |
747 typedef QImage result_type; | |
748 | |
749 QImage operator()(const QImage &image) | |
750 { | |
751 return image.scaled(m_size, m_size); | |
752 } | |
753 | |
754 int m_size; | |
755 }; | |
756 | |
757 QList<QImage> images = ...; | |
758 QFuture<QImage> thumbnails = QtConcurrent::mapped(images, Scaled(100)); | |
759 </pre> | |
760 Using Bound Function Arguments | |
761 <p> | |
762 Note that Qt does not provide support for bound functions. This is provided by 3rd party libraries like Boost or C++ TR1 Library Extensions. | |
763 <p> | |
764 If you want to use a map function that takes more than one argument you can use boost::bind() or std::tr1::bind() to transform it onto a function that takes one argument. | |
765 <p> | |
766 As an example, we'll use QImage::scaledToWidth(): | |
767 <pre> | |
768 QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const; | |
769 </pre> | |
770 scaledToWidth takes three arguments (including the "this" pointer) and can't be used with QtConcurrent::mapped() directly, because QtConcurrent::mapped() expects a function that takes one argument. To use QImage::scaledToWidth() with QtConcurrent::mapped() we have to provide a value for the width and the transformation mode: | |
771 <pre> | |
772 boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation) | |
773 </pre> | |
774 The return value from boost::bind() is a function object (functor) with the following signature: | |
775 <pre> | |
776 QImage scaledToWith(const QImage &image) | |
777 </pre> | |
778 This matches what QtConcurrent::mapped() expects, and the complete example becomes: | |
779 <pre> | |
780 QList>QImage< images = ...; | |
781 QFuture>QImage< thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation)); | |
782 </pre> | |
783 */ | |
784 class QtConcurrent___ extends QtConcurrent { | |
785 | |
786 static { | |
787 qt.QtJambi_LibraryInitializer.init(); | |
788 qt.core.QtJambi_LibraryInitializer.init(); | |
789 } | |
790 | |
791 /** | |
792 * An implemetation of this interface is given one to QtConcurrent's map() methods. | |
793 * The map() method of this interface is called for each object in a java.util.Collection. | |
794 * | |
795 */ | |
796 public interface MapFunctor<T> { | |
797 | |
798 /** | |
799 * This function is called for each item in the Collection. The function is then free to alter <tt>object</tt> as it see fit. | |
800 */ | |
801 public void map(T object); | |
802 } | |
803 /** | |
804 * Calls function once for each item in sequence. The function is passed a reference to the item, so that any modifications done to the item will appear in sequence. | |
805 */ | |
806 public static native <T> QFutureVoid map(java.util.Collection<T> sequence, MapFunctor<T> functor); | |
807 | |
808 /** | |
809 * Calls function once for each item in sequence. The function is passed a reference to the item, so that any modifications done to the item will appear in sequence. | |
810 */ | |
811 public static native <T> void blockingMap(java.util.Collection<T> sequence, MapFunctor<T> functor); | |
812 | |
813 /** | |
814 * Implement this interface to perform a mapped operation. An implementation of the interface is sendt | |
815 * to ome of the mapped methods of QtConcurrent, which applies the MappedFunctor.map() method to all elements in a collection, | |
816 * and returns the result. | |
817 */ | |
818 public interface MappedFunctor<U, T> { | |
819 | |
820 /** | |
821 * This method is called for each object in a collection. It should returned a new altered | |
822 * object. | |
823 */ | |
824 public U map(T object); | |
825 } | |
826 | |
827 /** | |
828 * Calls function once for each item in sequence and returns a future with each mapped item as a result. You can QFutureIterator to iterate through the results. | |
829 * | |
830 */ | |
831 public static native <U, T> QFuture<U> mapped(java.util.Collection<T> sequence, MappedFunctor<U, T> functor); | |
832 | |
833 /** | |
834 * Calls function once for each item in sequence and returns a future with each mapped item as a result. You can QFutureIterator to iterate through the results. | |
835 */ | |
836 public static native <U, T> java.util.List<U> blockingMapped(java.util.Collection<T> sequence, MappedFunctor<U, T> functor); | |
837 | |
838 /** | |
839 * Implement this interface in order to perform a reduce operation. | |
840 * <p> | |
841 * The reduce method will be called once per intermediate result (the result of the mapping of the data) | |
842 * and the very first time the reduce() method is called for the particular data set, the result is set to | |
843 * the returned value of the defaultResult() method. | |
844 */ | |
845 public interface ReducedFunctor<U, T> { | |
846 public U defaultResult(); | |
847 | |
848 /** | |
849 * Performs a reduce operation on <tt>intermediate</tt>. <tt>result</tt> is the result of the reduction. | |
850 */ | |
851 public void reduce(U result, T intermediate); | |
852 } | |
853 | |
854 /** | |
855 * This is an overloaded method provided for convenience. | |
856 * <p> | |
857 * It is equivalent of mappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
858 */ | |
859 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor) { | |
860 return mappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
861 } | |
862 | |
863 | |
864 /** | |
865 * This is an overloaded method provided for convenience. | |
866 * <p> | |
867 * Note that while mapFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is determined by reduceOptions. | |
868 * | |
869 */ | |
870 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOption ... options) { | |
871 return mappedReduced(sequence, functor, reducedFunctor, new ReduceOptions(options)); | |
872 } | |
873 | |
874 /** | |
875 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
876 * <p> | |
877 * Note that while mapFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is determined by reduceOptions. | |
878 * | |
879 */ | |
880 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOptions options) { | |
881 return mappedReduced(sequence, functor, reducedFunctor, options.value()); | |
882 } | |
883 | |
884 private native static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, int options); | |
885 | |
886 | |
887 /** | |
888 * This is an overloaded method provided for convenience. | |
889 * <p> | |
890 * It is equivalent of calling blockingMappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
891 * | |
892 */ | |
893 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor) { | |
894 return blockingMappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
895 } | |
896 | |
897 /** | |
898 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
899 * <p> | |
900 * Note that while mapFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is determined by reduceOptions. | |
901 * <p> | |
902 * Note: This function will block until all items in the sequence have been processed. | |
903 */ | |
904 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOption ... options) { | |
905 return blockingMappedReduced(sequence, functor, reducedFunctor, new ReduceOptions(options)); | |
906 } | |
907 | |
908 /** | |
909 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
910 * <p> | |
911 * Note that while mapFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is determined by reduceOptions. | |
912 * <p> | |
913 * Note: This function will block until all items in the sequence have been processed. | |
914 */ | |
915 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOptions options) { | |
916 return blockingMappedReduced(sequence, functor, reducedFunctor, options.value()); | |
917 } | |
918 | |
919 private native static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, int options); | |
920 | |
921 /** | |
922 * An implementation of this interface is given to one of QtConcurrent's filtered() methods. | |
923 * The filter method if this interface is called for each item in a java.util.Collection. | |
924 * | |
925 */ | |
926 public interface FilteredFunctor<T> { | |
927 | |
928 /** | |
929 * This method is called for each item in a java.util.Collection. The items for which | |
930 * this method returns true are removed from the collection. | |
931 */ | |
932 public boolean filter(T object); | |
933 } | |
934 | |
935 /** | |
936 * Calls filterFunctor's filtered() method once for each item in sequence and returns a new Sequence of kept items. If filterFunction returns true, a copy of the item is put in the new Sequence. Otherwise, the item will not appear in the new Sequence. | |
937 */ | |
938 public native static <T> QFuture<T> filtered(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor); | |
939 | |
940 /** | |
941 * Calls filterFunctor's filtered() method once for each item in sequence and returns a new Sequence of kept items. If filterFunction returns true, a copy of the item is put in the new Sequence. Otherwise, the item will not appear in the new Sequence. | |
942 */ | |
943 public native static <T> java.util.List<T> blockingFiltered(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor); | |
944 | |
945 | |
946 /** | |
947 * This is an overloaded method provided for convenience. It is equivalent of calling filteredReduced(sequence, filteredFunctor, ReduceOption.UnorderedReduce, ReduceOption.Seq This is an overloaded method provided for convenience. It is equivalent of calling filteredReduced) | |
948 */ | |
949 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor) { | |
950 return filteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
951 } | |
952 | |
953 /** | |
954 * Calls filterFunction once for each item in sequence. If filterFunction returns true for an item, that item is then passed to reduceFunction. In other words, the return value is the result of reduceFunction for each item where filterFunction returns true. | |
955 * <p> | |
956 * Note that while filterFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduceFunction is called in the order of the original sequence. | |
957 */ | |
958 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOption ... options) { | |
959 return filteredReduced(sequence, filteredFunctor, reducedFunctor, new ReduceOptions(options)); | |
960 } | |
961 | |
962 /** | |
963 * Calls filterFunction once for each item in sequence. If filterFunction returns true for an item, that item is then passed to reduceFunction. In other words, the return value is the result of reduceFunction for each item where filterFunction returns true. | |
964 * <p> | |
965 * Note that while filterFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduceFunction is called in the order of the original sequence. | |
966 */ | |
967 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOptions options) { | |
968 return filteredReduced(sequence, filteredFunctor, reducedFunctor, options.value()); | |
969 } | |
970 private native static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, int options); | |
971 | |
972 /** | |
973 * This is an overloaded method provided for convenience. It is the equivalent of calling blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
974 */ | |
975 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor) { | |
976 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
977 } | |
978 | |
979 /** | |
980 * Calls filterFunction once for each item in sequence. If filterFunction returns true for an item, that item is then passed to reduceFunction. In other words, the return value is the result of reduceFunction for each item where filterFunction returns true. | |
981 * <p> | |
982 * Note that while filterFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduceFunction is called in the order of the original sequence. | |
983 */ | |
984 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOption ... options) { | |
985 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, new ReduceOptions(options)); | |
986 } | |
987 | |
988 /** | |
989 * Calls filterFunction once for each item in sequence. If filterFunction returns true for an item, that item is then passed to reduceFunction. In other words, the return value is the result of reduceFunction for each item where filterFunction returns true. | |
990 * <p> | |
991 * Note that while filterFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduceFunction is called in the order of the original sequence. | |
992 */ | |
993 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOptions options) { | |
994 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, options.value()); | |
995 } | |
996 | |
997 private native static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, int options); | |
998 | |
999 /** | |
1000 * Executes the method <tt>m</tt> through the QtConcurrent framework with the given arguments. The returned QFuture object's result wil be the | |
1001 * return value of <tt>m</tt>. Note that this method does not accept function that return void. use runVoidMethod() for this. | |
1002 */ | |
1003 public static <T> QFuture<T> run(Object _this, java.lang.reflect.Method m, Object ... args) { | |
1004 if (m.getReturnType() == null || m.getReturnType().equals(Void.TYPE)) | |
1005 throw new IllegalArgumentException("Cannot call run on method returning void. Use 'runVoidMethod' instead."); | |
1006 | |
1007 return runPrivate(_this, m.getDeclaringClass(), m, args, qt.internal.QtJambiInternal.resolveConversionSchema(m.getParameterTypes(), m.getParameterTypes()), qt.internal.QtJambiInternal.typeConversionCode(m.getReturnType())); | |
1008 } | |
1009 private native static <T> QFuture<T> runPrivate(Object _this, Class<?> declaringClass, java.lang.reflect.Method m, Object args[], int conversionScheme[], byte returnType); | |
1010 | |
1011 /** | |
1012 * Executes the method <tt>m</tt> with the given arguments using the QtConcurrent framework. Notice that runVoidMethod() does not | |
1013 * accept methods that has a return value. Use the run() method for this purpose. | |
1014 */ | |
1015 public static QFutureVoid runVoidMethod(Object _this, java.lang.reflect.Method m, Object ... args) { | |
1016 if (m.getReturnType() != null && !m.getReturnType().equals(Void.TYPE)) | |
1017 throw new IllegalArgumentException("Cannot call runVoidMethod on method returning non-void type. Use 'run' instead."); | |
1018 | |
1019 return runVoidMethodPrivate(_this, m.getDeclaringClass(), m, args, qt.internal.QtJambiInternal.resolveConversionSchema(m.getParameterTypes(), m.getParameterTypes())); | |
1020 } | |
1021 private native static QFutureVoid runVoidMethodPrivate(Object _this, Class<?> declaringClass, java.lang.reflect.Method m, Object args[], int conversionScheme[]); | |
1022 | |
1023 | |
1024 }// class |