Mercurial > projects > qtd
annotate generator/typesystem_core-java.java @ 180:39921f499a22
Fix #26
author | SokoL_SD |
---|---|
date | Thu, 02 Jul 2009 12:04:40 +0000 |
parents | ba63040afbf2 |
children | d3f4f14d43a5 |
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 */ | |
180 | 465 |
466 public final long write(string str) { | |
467 return write(str.ptr, str.length); | |
468 } | |
1 | 469 }// class |
470 | |
471 class QCryptographicHash___ extends QCryptographicHash { | |
472 | |
473 public final void addData(byte data[]) { | |
474 QNativePointer np = qt.internal.QtJambiInternal.byteArrayToNativePointer(data); | |
475 addData(np, data.length); | |
476 } | |
477 | |
478 }// class | |
479 | |
480 class QTextCodec___ extends QTextCodec { | |
481 /* | |
482 static { | |
483 setCodecForTr(QTextCodec.codecForName("UTF-8")); | |
484 } | |
485 | |
486 public static QTextCodec codecForName(String name) { | |
487 return codecForName(qt.QNativePointer.createCharPointer(name)); | |
488 } | |
489 */ | |
490 }// class | |
491 | |
492 class QBuffer___ extends QBuffer { | |
493 | |
494 // retain a reference to avoid gc | |
495 private Object strongDataReference = null; | |
496 public final void setBuffer(QByteArray byteArray) { | |
90 | 497 setBuffer_private(byteArray); |
1 | 498 strongDataReference = byteArray; |
499 } | |
500 | |
501 public final void setData(byte data[]) { | |
90 | 502 setData(cast(char*)data.ptr, data.length); |
1 | 503 } |
504 | |
505 }// class | |
506 | |
507 class QSignalMapper___ extends QSignalMapper { | |
508 | |
509 private java.util.Hashtable<QObject, QObject> __rcObjectForObject = new java.util.Hashtable<QObject, QObject>(); | |
510 | |
511 private java.util.Hashtable<QObject, Object> __rcWidgetForObject = new java.util.Hashtable<QObject, Object>(); | |
512 | |
513 }// class | |
514 | |
515 class QAbstractFileEngine_MapExtensionReturn___ extends QAbstractFileEngine_MapExtensionReturn { | |
516 /* private QNativePointer currentAddressNativePointer; // don't garbage collect while in use | |
517 public final void setAddress(String address) { | |
518 currentAddressNativePointer = address != null ? QNativePointer.createCharPointer(address) : null; | |
519 address_private(currentAddressNativePointer); | |
520 } | |
521 | |
522 public final String address() { | |
523 QNativePointer np = address_private(); | |
524 return np != null ? qt.internal.QtJambiInternal.charPointerToString(np) : null; | |
525 }*/ | |
526 }// class | |
527 | |
528 class QAbstractFileEngine___ extends QAbstractFileEngine { | |
529 /** | |
530 * Adds <tt>path</tt> to the set of paths in which Qt Jambi should search for resources. Resources | |
531 * can be accessed using the "classpath:" scheme. | |
532 */ | |
533 /* public static void addSearchPathForResourceEngine(String path) | |
534 { | |
535 qt.internal.QClassPathEngine.addSearchPath(path); | |
536 } | |
537 */ | |
538 /** | |
539 * Removes <tt>path</tt> from the set of paths in which Qt Jambi searches | |
540 * for resources. | |
541 */ | |
542 /* public static void removeSearchPathForResourceEngine(String path) | |
543 { | |
544 qt.internal.QClassPathEngine.removeSearchPath(path); | |
545 } | |
546 */ | |
547 }// class | |
548 | |
549 class QAbstractFileEngine_UnMapExtensionOption___ extends QAbstractFileEngine_UnMapExtensionOption { | |
550 private QNativePointer currentAddressNativePointer; // don't garbage collect while in use | |
551 public final void setAddress(String address) { | |
552 currentAddressNativePointer = address != null ? QNativePointer.createCharPointer(address) : null; | |
553 address_private(currentAddressNativePointer); | |
554 } | |
555 | |
556 public final String address() { | |
557 QNativePointer np = address_private(); | |
558 return np != null ? qt.internal.QtJambiInternal.charPointerToString(np) : null; | |
559 } | |
560 }// class | |
561 | |
562 class QFutureWatcher___ extends QFutureWatcher { | |
563 | |
564 public final QFuture<T> future() { | |
565 if (nativeId() == 0) | |
566 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
567 return __qt_future(nativeId()); | |
568 } | |
569 private native QFuture<T> __qt_future(long nativeId); | |
570 | |
571 }// class | |
572 | |
573 class QFutureWatcherVoid___ extends QFutureWatcherVoid { | |
574 | |
575 public final QFutureVoid future() { | |
576 if (nativeId() == 0) | |
577 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
578 return __qt_future(nativeId()); | |
579 } | |
580 | |
581 private native QFutureVoid __qt_future(long nativeId); | |
582 | |
583 }// class | |
584 | |
585 class QFutureSynchronizer___ extends QFutureSynchronizer { | |
586 | |
587 public final java.util.List<QFuture<T>> futures() { | |
588 if (nativeId() == 0) | |
589 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
590 return __qt_futures(nativeId()); | |
591 } | |
592 private native java.util.List<QFuture<T>> __qt_futures(long nativeId); | |
593 | |
594 }// class | |
595 | |
596 class QFutureSynchronizerVoid___ extends QFutureSynchronizerVoid { | |
597 | |
598 public final java.util.List<QFutureVoid> futures() { | |
599 if (nativeId() == 0) | |
600 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
601 return __qt_futures(nativeId()); | |
602 } | |
603 private native java.util.List<QFutureVoid> __qt_futures(long nativeId); | |
604 | |
605 }// class | |
606 | |
607 class QLineF___ extends QLineF { | |
608 /* | |
609 public final QLineF.IntersectType intersect(QLineF line, qt.core.QPointF intersectionPoint) { | |
610 return intersect(line, intersectionPoint != null ? intersectionPoint.nativePointer() : null); | |
611 } | |
612 */ | |
613 }// class | |
614 | |
615 /** | |
616 The QtConcurrent class contains static methods for running computations in parallel (using separate threads) | |
617 on the items in a java.util.Collection, such as a Vector or LinkedList. We will now describe these methods. | |
618 | |
619 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. | |
620 Concurrent Map | |
621 <p> | |
622 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. | |
623 <p> | |
624 The map function must be of the form: | |
625 <pre> | |
626 U function(const T &t); | |
627 </pre> | |
628 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. | |
629 <p> | |
630 This example shows how to apply a scale function to all the items in a sequence: | |
631 <pre> | |
632 QImage scaled(const QImage &image) | |
633 { | |
634 return image.scaled(100, 100); | |
635 } | |
636 | |
637 QList <QImage> images = ...; | |
638 QFuture<QImage> thumbnails = QtConcurrent::mapped(images, scaled); | |
639 </pre> | |
640 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. | |
641 <p> | |
642 If you want to modify a sequence in-place, use QtConcurrent::map(). The map function must then be of the form: | |
643 <pre> | |
644 U function(T &t); | |
645 </pre> | |
646 Note that the return value and return type of the map function are not used. | |
647 <p> | |
648 Using QtConcurrent::map() is similar to using QtConcurrent::mapped(): | |
649 <pre> | |
650 void scale(QImage &image) | |
651 { | |
652 image = image.scaled(100, 100); | |
653 } | |
654 | |
655 QList<QImage> images = ...; | |
656 QFuture<void> future = QtConcurrent::map(images, scale); | |
657 </pre> | |
658 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. | |
659 Concurrent Map-Reduce | |
660 <p> | |
661 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. | |
662 <p> | |
663 The reduce function must be of the form: | |
664 <pre> | |
665 V function(T &result, const U &intermediate) | |
666 </pre> | |
667 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. | |
668 <p> | |
669 Call QtConcurrent::mappedReduced() like this: | |
670 <pre> | |
671 void addToCollage(QImage &collage, const QImage &thumbnail) | |
672 { | |
673 QPainter p(&collage); | |
674 static QPoint offset = QPoint(0, 0); | |
675 p.drawImage(offset, thumbnail); | |
676 offset += ...; | |
677 } | |
678 | |
679 QList<QImage> images = ...; | |
680 QFuture<QImage> collage = QtConcurrent::mappedReduced(images, scaled, addToCollage); | |
681 </pre> | |
682 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. | |
683 Additional API Features | |
684 Using Iterators instead of Sequence | |
685 <p> | |
686 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: | |
687 <pre> | |
688 QList<QImage> images = ...; | |
689 | |
690 QFuture<QImage> thumbnails = QtConcurrent::mapped(images.constBegin(), images.constEnd(), scaled); | |
691 | |
692 // map in-place only works on non-const iterators | |
693 QFuture<void> future = QtConcurrent::map(images.begin(), images.end(), scale); | |
694 | |
695 QFuture<QImage> collage = QtConcurrent::mappedReduced(images.constBegin(), images.constEnd(), scaled, addToCollage); | |
696 </pre> | |
697 Blocking Variants | |
698 <p> | |
699 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. | |
700 <pre> | |
701 QList<QImage> images = ...; | |
702 | |
703 // each call blocks until the entire operation is finished | |
704 QList<QImage> future = QtConcurrent::blockingMapped(images, scaled); | |
705 | |
706 QtConcurrent::blockingMap(images, scale); | |
707 | |
708 QImage collage = QtConcurrent::blockingMappedReduced(images, scaled, addToCollage); | |
709 </pre> | |
710 Note that the result types above are not QFuture objects, but real result types (in this case, QList<QImage> and QImage). | |
711 Using Member Functions | |
712 <p> | |
713 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: | |
714 <pre> | |
715 // squeeze all strings in a QStringList | |
716 QStringList strings = ...; | |
717 QFuture<void> squeezedStrings = QtConcurrent::map(strings, &QString::squeeze); | |
718 | |
719 // swap the rgb values of all pixels on a list of images | |
720 QList<QImage> images = ...; | |
721 QFuture<QImage> bgrImages = QtConcurrent::mapped(images, &QImage::rgbSwapped); | |
722 | |
723 // create a set of the lengths of all strings in a list | |
724 QStringList strings = ...; | |
725 QFuture<QSet<int> > wordLengths = QtConcurrent::mappedReduced(string, &QString::length, &QSet<int>::insert); | |
726 </pre> | |
727 Note that when using QtConcurrent::mappedReduced(), you can mix the use of normal and member functions freely: | |
728 <p> | |
729 <pre> | |
730 // can mix normal functions and member functions with QtConcurrent::mappedReduced() | |
731 | |
732 // compute the average length of a list of strings | |
733 extern void computeAverage(int &average, int length); | |
734 QStringList strings = ...; | |
735 QFuture<int> averageWordLength = QtConcurrent::mappedReduced(strings, &QString::length, computeAverage); | |
736 | |
737 // create a set of the color distribution of all images in a list | |
738 extern int colorDistribution(const QImage &string); | |
739 QList<QImage> images = ...; | |
740 QFuture<QSet<int> > totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution, QSet<int>::insert); | |
741 </pre> | |
742 Using Function Objects | |
743 <p> | |
744 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: | |
745 <pre> | |
746 struct Scaled | |
747 { | |
748 Scaled(int size) | |
749 : m_size(size) { } | |
750 | |
751 typedef QImage result_type; | |
752 | |
753 QImage operator()(const QImage &image) | |
754 { | |
755 return image.scaled(m_size, m_size); | |
756 } | |
757 | |
758 int m_size; | |
759 }; | |
760 | |
761 QList<QImage> images = ...; | |
762 QFuture<QImage> thumbnails = QtConcurrent::mapped(images, Scaled(100)); | |
763 </pre> | |
764 Using Bound Function Arguments | |
765 <p> | |
766 Note that Qt does not provide support for bound functions. This is provided by 3rd party libraries like Boost or C++ TR1 Library Extensions. | |
767 <p> | |
768 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. | |
769 <p> | |
770 As an example, we'll use QImage::scaledToWidth(): | |
771 <pre> | |
772 QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const; | |
773 </pre> | |
774 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: | |
775 <pre> | |
776 boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation) | |
777 </pre> | |
778 The return value from boost::bind() is a function object (functor) with the following signature: | |
779 <pre> | |
780 QImage scaledToWith(const QImage &image) | |
781 </pre> | |
782 This matches what QtConcurrent::mapped() expects, and the complete example becomes: | |
783 <pre> | |
784 QList>QImage< images = ...; | |
785 QFuture>QImage< thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation)); | |
786 </pre> | |
787 */ | |
788 class QtConcurrent___ extends QtConcurrent { | |
789 | |
790 static { | |
791 qt.QtJambi_LibraryInitializer.init(); | |
792 qt.core.QtJambi_LibraryInitializer.init(); | |
793 } | |
794 | |
795 /** | |
796 * An implemetation of this interface is given one to QtConcurrent's map() methods. | |
797 * The map() method of this interface is called for each object in a java.util.Collection. | |
798 * | |
799 */ | |
800 public interface MapFunctor<T> { | |
801 | |
802 /** | |
803 * This function is called for each item in the Collection. The function is then free to alter <tt>object</tt> as it see fit. | |
804 */ | |
805 public void map(T object); | |
806 } | |
807 /** | |
808 * 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. | |
809 */ | |
810 public static native <T> QFutureVoid map(java.util.Collection<T> sequence, MapFunctor<T> functor); | |
811 | |
812 /** | |
813 * 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. | |
814 */ | |
815 public static native <T> void blockingMap(java.util.Collection<T> sequence, MapFunctor<T> functor); | |
816 | |
817 /** | |
818 * Implement this interface to perform a mapped operation. An implementation of the interface is sendt | |
819 * to ome of the mapped methods of QtConcurrent, which applies the MappedFunctor.map() method to all elements in a collection, | |
820 * and returns the result. | |
821 */ | |
822 public interface MappedFunctor<U, T> { | |
823 | |
824 /** | |
825 * This method is called for each object in a collection. It should returned a new altered | |
826 * object. | |
827 */ | |
828 public U map(T object); | |
829 } | |
830 | |
831 /** | |
832 * 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. | |
833 * | |
834 */ | |
835 public static native <U, T> QFuture<U> mapped(java.util.Collection<T> sequence, MappedFunctor<U, T> functor); | |
836 | |
837 /** | |
838 * 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. | |
839 */ | |
840 public static native <U, T> java.util.List<U> blockingMapped(java.util.Collection<T> sequence, MappedFunctor<U, T> functor); | |
841 | |
842 /** | |
843 * Implement this interface in order to perform a reduce operation. | |
844 * <p> | |
845 * The reduce method will be called once per intermediate result (the result of the mapping of the data) | |
846 * and the very first time the reduce() method is called for the particular data set, the result is set to | |
847 * the returned value of the defaultResult() method. | |
848 */ | |
849 public interface ReducedFunctor<U, T> { | |
850 public U defaultResult(); | |
851 | |
852 /** | |
853 * Performs a reduce operation on <tt>intermediate</tt>. <tt>result</tt> is the result of the reduction. | |
854 */ | |
855 public void reduce(U result, T intermediate); | |
856 } | |
857 | |
858 /** | |
859 * This is an overloaded method provided for convenience. | |
860 * <p> | |
861 * It is equivalent of mappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
862 */ | |
863 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor) { | |
864 return mappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
865 } | |
866 | |
867 | |
868 /** | |
869 * This is an overloaded method provided for convenience. | |
870 * <p> | |
871 * 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. | |
872 * | |
873 */ | |
874 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOption ... options) { | |
875 return mappedReduced(sequence, functor, reducedFunctor, new ReduceOptions(options)); | |
876 } | |
877 | |
878 /** | |
879 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
880 * <p> | |
881 * 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. | |
882 * | |
883 */ | |
884 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOptions options) { | |
885 return mappedReduced(sequence, functor, reducedFunctor, options.value()); | |
886 } | |
887 | |
888 private native static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, int options); | |
889 | |
890 | |
891 /** | |
892 * This is an overloaded method provided for convenience. | |
893 * <p> | |
894 * It is equivalent of calling blockingMappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
895 * | |
896 */ | |
897 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor) { | |
898 return blockingMappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
899 } | |
900 | |
901 /** | |
902 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
903 * <p> | |
904 * 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. | |
905 * <p> | |
906 * Note: This function will block until all items in the sequence have been processed. | |
907 */ | |
908 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOption ... options) { | |
909 return blockingMappedReduced(sequence, functor, reducedFunctor, new ReduceOptions(options)); | |
910 } | |
911 | |
912 /** | |
913 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
914 * <p> | |
915 * 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. | |
916 * <p> | |
917 * Note: This function will block until all items in the sequence have been processed. | |
918 */ | |
919 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOptions options) { | |
920 return blockingMappedReduced(sequence, functor, reducedFunctor, options.value()); | |
921 } | |
922 | |
923 private native static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, int options); | |
924 | |
925 /** | |
926 * An implementation of this interface is given to one of QtConcurrent's filtered() methods. | |
927 * The filter method if this interface is called for each item in a java.util.Collection. | |
928 * | |
929 */ | |
930 public interface FilteredFunctor<T> { | |
931 | |
932 /** | |
933 * This method is called for each item in a java.util.Collection. The items for which | |
934 * this method returns true are removed from the collection. | |
935 */ | |
936 public boolean filter(T object); | |
937 } | |
938 | |
939 /** | |
940 * 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. | |
941 */ | |
942 public native static <T> QFuture<T> filtered(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor); | |
943 | |
944 /** | |
945 * 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. | |
946 */ | |
947 public native static <T> java.util.List<T> blockingFiltered(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor); | |
948 | |
949 | |
950 /** | |
951 * 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) | |
952 */ | |
953 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor) { | |
954 return filteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
955 } | |
956 | |
957 /** | |
958 * 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. | |
959 * <p> | |
960 * 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. | |
961 */ | |
962 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOption ... options) { | |
963 return filteredReduced(sequence, filteredFunctor, reducedFunctor, new ReduceOptions(options)); | |
964 } | |
965 | |
966 /** | |
967 * 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. | |
968 * <p> | |
969 * 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. | |
970 */ | |
971 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOptions options) { | |
972 return filteredReduced(sequence, filteredFunctor, reducedFunctor, options.value()); | |
973 } | |
974 private native static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, int options); | |
975 | |
976 /** | |
977 * This is an overloaded method provided for convenience. It is the equivalent of calling blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
978 */ | |
979 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor) { | |
980 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
981 } | |
982 | |
983 /** | |
984 * 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. | |
985 * <p> | |
986 * 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. | |
987 */ | |
988 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOption ... options) { | |
989 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, new ReduceOptions(options)); | |
990 } | |
991 | |
992 /** | |
993 * 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. | |
994 * <p> | |
995 * 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. | |
996 */ | |
997 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOptions options) { | |
998 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, options.value()); | |
999 } | |
1000 | |
1001 private native static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, int options); | |
1002 | |
1003 /** | |
1004 * Executes the method <tt>m</tt> through the QtConcurrent framework with the given arguments. The returned QFuture object's result wil be the | |
1005 * return value of <tt>m</tt>. Note that this method does not accept function that return void. use runVoidMethod() for this. | |
1006 */ | |
1007 public static <T> QFuture<T> run(Object _this, java.lang.reflect.Method m, Object ... args) { | |
1008 if (m.getReturnType() == null || m.getReturnType().equals(Void.TYPE)) | |
1009 throw new IllegalArgumentException("Cannot call run on method returning void. Use 'runVoidMethod' instead."); | |
1010 | |
1011 return runPrivate(_this, m.getDeclaringClass(), m, args, qt.internal.QtJambiInternal.resolveConversionSchema(m.getParameterTypes(), m.getParameterTypes()), qt.internal.QtJambiInternal.typeConversionCode(m.getReturnType())); | |
1012 } | |
1013 private native static <T> QFuture<T> runPrivate(Object _this, Class<?> declaringClass, java.lang.reflect.Method m, Object args[], int conversionScheme[], byte returnType); | |
1014 | |
1015 /** | |
1016 * Executes the method <tt>m</tt> with the given arguments using the QtConcurrent framework. Notice that runVoidMethod() does not | |
1017 * accept methods that has a return value. Use the run() method for this purpose. | |
1018 */ | |
1019 public static QFutureVoid runVoidMethod(Object _this, java.lang.reflect.Method m, Object ... args) { | |
1020 if (m.getReturnType() != null && !m.getReturnType().equals(Void.TYPE)) | |
1021 throw new IllegalArgumentException("Cannot call runVoidMethod on method returning non-void type. Use 'run' instead."); | |
1022 | |
1023 return runVoidMethodPrivate(_this, m.getDeclaringClass(), m, args, qt.internal.QtJambiInternal.resolveConversionSchema(m.getParameterTypes(), m.getParameterTypes())); | |
1024 } | |
1025 private native static QFutureVoid runVoidMethodPrivate(Object _this, Class<?> declaringClass, java.lang.reflect.Method m, Object args[], int conversionScheme[]); | |
1026 | |
1027 | |
1028 }// class |