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