comparison generator/typesystem_core-java.java @ 1:e78566595089

initial import
author mandel
date Mon, 11 May 2009 16:01:50 +0000
parents
children d5a6b6269f44
comparison
equal deleted inserted replaced
0:36fb74dc547d 1:e78566595089
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;
130 }// class
131
132 class QTranslator___ extends QTranslator {
133 public final bool load(ubyte[] data) {
134 return load(data.ptr, data.length);
135 }
136 }// class
137
138 class QProcess___ extends QProcess {
139
140 public static class DetachedProcessInfo {
141 public DetachedProcessInfo(boolean success, long pid) {
142 this.success = success;
143 this.pid = pid;
144 }
145
146 public boolean success;
147 public long pid;
148 }
149
150 public static DetachedProcessInfo startDetached(String program, java.util.List<String> arguments, String workingDirectory) {
151 QNativePointer pid = new QNativePointer(QNativePointer.Type.Long);
152 boolean success = startDetached(program, arguments, workingDirectory, pid);
153 return new DetachedProcessInfo(success, pid.longValue());
154 }
155 }// class
156
157 class QDataStream___ extends QDataStream {
158
159 public final bool readBoolean() {
160 bool res;
161 operator_shift_right_boolean(&res);
162 return res;
163 }
164
165 public final byte readByte() {
166 byte res;
167 operator_shift_right_byte(&res);
168 return res;
169 }
170
171 public final short readShort() {
172 short res;
173 operator_shift_right_short(&res);
174 return res;
175 }
176
177 public final int readInt() {
178 int res;
179 operator_shift_right_int(&res);
180 return res;
181 }
182
183 public final long readLong() {
184 long res;
185 operator_shift_right_long(&res);
186 return res;
187 }
188
189 public final ushort readChar() {
190 ushort res;
191 operator_shift_right_char(&res);
192 return res;
193 }
194
195 public final float readFloat() {
196 float res;
197 operator_shift_right_float(&res);
198 return res;
199 }
200
201 public final double readDouble() {
202 double res;
203 operator_shift_right_double(&res);
204 return res;
205 }
206
207 public final QDataStream writeShort(short s) {
208 writeShort_char(s);
209 return this;
210 }
211 /*
212 private static extern(C) void qtd_QDataStream_readString_private(void* __this_nativeId);
213
214 private native void writeString_private(long nativeId, String string);
215
216 public final String readString() {
217 if (nativeId() == 0)
218 throw new QNoNativeResourcesException("Function call on incomplete object of type: " + getClass().getName());
219 return readString_private(nativeId());
220 }
221
222 public final void writeString(String string) {
223 if (nativeId() == 0)
224 throw new QNoNativeResourcesException("Function call on incomplete object of type: " + getClass().getName());
225 writeString_private(nativeId(), string);
226 }
227
228 private native int writeBytes(long id, byte buffer[], int length);
229
230 private native int readBytes(long id, byte buffer[], int length);
231
232 public final int writeBytes(byte buffer[]) {
233 return writeBytes(buffer, buffer.length);
234 }
235
236 public final int writeBytes(byte buffer[], int length) {
237 return writeBytes(nativeId(), buffer, length);
238 }
239
240 public final int readBytes(byte buffer[]) {
241 return readBytes(buffer, buffer.length);
242 }
243
244 public final int readBytes(byte buffer[], int length) {
245 return readBytes(nativeId(), buffer, length);
246 }
247 */
248 }// class
249
250 class QTextStream___ extends QTextStream {
251 /* public final void setCodec(String codecName) {
252 setCodec(QNativePointer.createCharPointer(codecName));
253 if (codec() != __rcCodec)
254 __rcCodec = null;
255 }
256
257 private QNativePointer srb = new QNativePointer(QNativePointer.Type.Byte, 32) {
258 {
259 setVerificationEnabled(false);
260 }
261 };
262
263 public final byte readByte() {
264 operator_shift_right_byte(srb);
265 return srb.byteValue();
266 }
267
268 public final short readShort() {
269 operator_shift_right_short(srb);
270 return srb.shortValue();
271 }
272
273 public final int readInt() {
274 operator_shift_right_int(srb);
275 return srb.intValue();
276 }
277
278 public final long readLong() {
279 operator_shift_right_long(srb);
280 return srb.longValue();
281 }
282
283 public final float readFloat() {
284 operator_shift_right_float(srb);
285 return srb.floatValue();
286 }
287
288 public final double readDouble() {
289 operator_shift_right_double(srb);
290 return srb.doubleValue();
291 }
292
293 public final QTextStream writeShort(short s) {
294 writeShort_char((char) s);
295 return this;
296 }
297
298 public final QTextStream writeChar(char c) {
299 writeShort_char(c);
300 return this;
301 }
302
303 public final char readChar() {
304 operator_shift_right_short(srb);
305 return srb.charValue();
306 }
307
308 public final String readString() {
309 return readString_native(nativeId());
310 }
311
312 public final void writeString(String string) {
313 writeString_native(nativeId(), string);
314 }
315
316 private final native String readString_native(long id);
317
318 private final native void writeString_native(long id, String string);
319 */
320 }// class
321
322 class QBitArray___ extends QBitArray {
323 /*
324 @qt.QtBlockedSlot
325 public final void xor(QBitArray other) {
326 operator_xor_assign(other);
327 }
328
329 @qt.QtBlockedSlot
330 public final void and(QBitArray other) {
331 operator_and_assign(other);
332 }
333
334 @qt.QtBlockedSlot
335 public final void or(QBitArray other) {
336 operator_or_assign(other);
337 }
338
339 @qt.QtBlockedSlot
340 public final void set(QBitArray other) {
341 operator_assign(other);
342 }
343
344 @qt.QtBlockedSlot
345 public final QBitArray inverted() {
346 return operator_negate();
347 }
348 */
349 }// class
350
351 // hfr
352
353 class QDate___ extends QDate {
354
355 public final int weekNumber() {
356 return weekNumber(null);
357 }
358
359 public final int yearOfWeekNumber() {
360 int np;
361 weekNumber(&np);
362 return np;
363 }
364
365 }// class
366
367 class QDir___ extends QDir {
368 /*
369 @qt.QtBlockedSlot
370 public String at(int i) {
371 return operator_subscript(i);
372 }
373 */
374 }// class
375
376 class QByteArray___ extends QByteArray {
377 public QByteArray(String s) {
378 this();
379 append(s);
380 }
381
382 public QByteArray(byte data[]) {
383 this(qt.internal.QtJambiInternal.byteArrayToNativePointer(data), data.length);
384 }
385
386 public final boolean contains(String str) {
387 return contains(new QByteArray(str));
388 }
389
390 public final int count(String str) {
391 return count(new QByteArray(str));
392 }
393
394 public final boolean endsWith(String str) {
395 return endsWith(new QByteArray(str));
396 }
397
398 public final QByteArray prepend(String str) {
399 return prepend(new QByteArray(str));
400 }
401
402 public final QByteArray replace(QByteArray before, String after) {
403 return replace(before, new QByteArray(after));
404 }
405
406 public final QByteArray replace(String before, String after) {
407 return replace(new QByteArray(before), new QByteArray(after));
408 }
409
410 public final boolean startsWith(String str) {
411 return startsWith(new QByteArray(str));
412 }
413
414 public final byte[] toByteArray() {
415 byte[] res = new byte[size()];
416
417 for (int i = 0; i < size(); i++) {
418 res[i] = at(i);
419 }
420 return res;
421 }
422
423 @qt.QtBlockedSlot
424 public final QByteArray set(QByteArray other) {
425 operator_assign(other);
426 return this;
427 }
428
429 }// class
430
431 class QFile___ extends QFile {
432 /*
433 public static String decodeName(String localFileName) {
434 return decodeName(qt.QNativePointer.createCharPointer(localFileName));
435 }
436 */
437 }// class
438
439 class QIODevice___ extends QIODevice {
440
441 /**
442 * Gets a byte from the device.
443 *
444 * @return -1 on failure, or the value of the byte on success
445 */
446 /* public final int getByte() {
447 QNativePointer np = new QNativePointer(QNativePointer.Type.Byte);
448 boolean success = getByte(np);
449 return success ? np.byteValue() : -1;
450 }
451 */
452 }// class
453
454 class QCryptographicHash___ extends QCryptographicHash {
455
456 public final void addData(byte data[]) {
457 QNativePointer np = qt.internal.QtJambiInternal.byteArrayToNativePointer(data);
458 addData(np, data.length);
459 }
460
461 }// class
462
463 class QTextCodec___ extends QTextCodec {
464 /*
465 static {
466 setCodecForTr(QTextCodec.codecForName("UTF-8"));
467 }
468
469 public static QTextCodec codecForName(String name) {
470 return codecForName(qt.QNativePointer.createCharPointer(name));
471 }
472 */
473 }// class
474
475 class QBuffer___ extends QBuffer {
476
477 // retain a reference to avoid gc
478 private Object strongDataReference = null;
479
480 public QBuffer(QByteArray byteArray, QObject parent) {
481 this(byteArray.nativePointer(), parent);
482 strongDataReference = byteArray;
483 }
484
485 public QBuffer(QByteArray byteArray) {
486 this(byteArray, null);
487 }
488
489 public final void setBuffer(QByteArray byteArray) {
490 setBuffer(byteArray.nativePointer());
491 strongDataReference = byteArray;
492 }
493
494 public final void setData(byte data[]) {
495 QNativePointer np = qt.internal.QtJambiInternal.byteArrayToNativePointer(data);
496 setData(np, data.length);
497 }
498
499 }// class
500
501 class QSignalMapper___ extends QSignalMapper {
502
503 private java.util.Hashtable<QObject, QObject> __rcObjectForObject = new java.util.Hashtable<QObject, QObject>();
504
505 private java.util.Hashtable<QObject, Object> __rcWidgetForObject = new java.util.Hashtable<QObject, Object>();
506
507 }// class
508
509 class QAbstractFileEngine_MapExtensionReturn___ extends QAbstractFileEngine_MapExtensionReturn {
510 /* private QNativePointer currentAddressNativePointer; // don't garbage collect while in use
511 public final void setAddress(String address) {
512 currentAddressNativePointer = address != null ? QNativePointer.createCharPointer(address) : null;
513 address_private(currentAddressNativePointer);
514 }
515
516 public final String address() {
517 QNativePointer np = address_private();
518 return np != null ? qt.internal.QtJambiInternal.charPointerToString(np) : null;
519 }*/
520 }// class
521
522 class QAbstractFileEngine___ extends QAbstractFileEngine {
523 /**
524 * Adds <tt>path</tt> to the set of paths in which Qt Jambi should search for resources. Resources
525 * can be accessed using the "classpath:" scheme.
526 */
527 /* public static void addSearchPathForResourceEngine(String path)
528 {
529 qt.internal.QClassPathEngine.addSearchPath(path);
530 }
531 */
532 /**
533 * Removes <tt>path</tt> from the set of paths in which Qt Jambi searches
534 * for resources.
535 */
536 /* public static void removeSearchPathForResourceEngine(String path)
537 {
538 qt.internal.QClassPathEngine.removeSearchPath(path);
539 }
540 */
541 }// class
542
543 class QAbstractFileEngine_UnMapExtensionOption___ extends QAbstractFileEngine_UnMapExtensionOption {
544 private QNativePointer currentAddressNativePointer; // don't garbage collect while in use
545 public final void setAddress(String address) {
546 currentAddressNativePointer = address != null ? QNativePointer.createCharPointer(address) : null;
547 address_private(currentAddressNativePointer);
548 }
549
550 public final String address() {
551 QNativePointer np = address_private();
552 return np != null ? qt.internal.QtJambiInternal.charPointerToString(np) : null;
553 }
554 }// class
555
556 class QFutureWatcher___ extends QFutureWatcher {
557
558 public final QFuture<T> future() {
559 if (nativeId() == 0)
560 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName());
561 return __qt_future(nativeId());
562 }
563 private native QFuture<T> __qt_future(long nativeId);
564
565 }// class
566
567 class QFutureWatcherVoid___ extends QFutureWatcherVoid {
568
569 public final QFutureVoid future() {
570 if (nativeId() == 0)
571 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName());
572 return __qt_future(nativeId());
573 }
574
575 private native QFutureVoid __qt_future(long nativeId);
576
577 }// class
578
579 class QFutureSynchronizer___ extends QFutureSynchronizer {
580
581 public final java.util.List<QFuture<T>> futures() {
582 if (nativeId() == 0)
583 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName());
584 return __qt_futures(nativeId());
585 }
586 private native java.util.List<QFuture<T>> __qt_futures(long nativeId);
587
588 }// class
589
590 class QFutureSynchronizerVoid___ extends QFutureSynchronizerVoid {
591
592 public final java.util.List<QFutureVoid> futures() {
593 if (nativeId() == 0)
594 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName());
595 return __qt_futures(nativeId());
596 }
597 private native java.util.List<QFutureVoid> __qt_futures(long nativeId);
598
599 }// class
600
601 class QLineF___ extends QLineF {
602 /*
603 public final QLineF.IntersectType intersect(QLineF line, qt.core.QPointF intersectionPoint) {
604 return intersect(line, intersectionPoint != null ? intersectionPoint.nativePointer() : null);
605 }
606 */
607 }// class
608
609 /**
610 The QtConcurrent class contains static methods for running computations in parallel (using separate threads)
611 on the items in a java.util.Collection, such as a Vector or LinkedList. We will now describe these methods.
612
613 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.
614 Concurrent Map
615 <p>
616 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.
617 <p>
618 The map function must be of the form:
619 <pre>
620 U function(const T &amp;t);
621 </pre>
622 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.
623 <p>
624 This example shows how to apply a scale function to all the items in a sequence:
625 <pre>
626 QImage scaled(const QImage &amp;image)
627 {
628 return image.scaled(100, 100);
629 }
630
631 QList &lt;QImage&gt; images = ...;
632 QFuture&lt;QImage&gt; thumbnails = QtConcurrent::mapped(images, scaled);
633 </pre>
634 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.
635 <p>
636 If you want to modify a sequence in-place, use QtConcurrent::map(). The map function must then be of the form:
637 <pre>
638 U function(T &amp;t);
639 </pre>
640 Note that the return value and return type of the map function are not used.
641 <p>
642 Using QtConcurrent::map() is similar to using QtConcurrent::mapped():
643 <pre>
644 void scale(QImage &amp;image)
645 {
646 image = image.scaled(100, 100);
647 }
648
649 QList&lt;QImage&gt; images = ...;
650 QFuture&lt;void&gt; future = QtConcurrent::map(images, scale);
651 </pre>
652 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.
653 Concurrent Map-Reduce
654 <p>
655 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.
656 <p>
657 The reduce function must be of the form:
658 <pre>
659 V function(T &amp;result, const U &amp;intermediate)
660 </pre>
661 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.
662 <p>
663 Call QtConcurrent::mappedReduced() like this:
664 <pre>
665 void addToCollage(QImage &amp;collage, const QImage &amp;thumbnail)
666 {
667 QPainter p(&amp;collage);
668 static QPoint offset = QPoint(0, 0);
669 p.drawImage(offset, thumbnail);
670 offset += ...;
671 }
672
673 QList&lt;QImage&gt; images = ...;
674 QFuture&lt;QImage&gt; collage = QtConcurrent::mappedReduced(images, scaled, addToCollage);
675 </pre>
676 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.
677 Additional API Features
678 Using Iterators instead of Sequence
679 <p>
680 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:
681 <pre>
682 QList&lt;QImage&gt; images = ...;
683
684 QFuture&lt;QImage&gt; thumbnails = QtConcurrent::mapped(images.constBegin(), images.constEnd(), scaled);
685
686 // map in-place only works on non-const iterators
687 QFuture&lt;void&gt; future = QtConcurrent::map(images.begin(), images.end(), scale);
688
689 QFuture&lt;QImage&gt; collage = QtConcurrent::mappedReduced(images.constBegin(), images.constEnd(), scaled, addToCollage);
690 </pre>
691 Blocking Variants
692 <p>
693 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.
694 <pre>
695 QList&lt;QImage&gt; images = ...;
696
697 // each call blocks until the entire operation is finished
698 QList&lt;QImage&gt; future = QtConcurrent::blockingMapped(images, scaled);
699
700 QtConcurrent::blockingMap(images, scale);
701
702 QImage collage = QtConcurrent::blockingMappedReduced(images, scaled, addToCollage);
703 </pre>
704 Note that the result types above are not QFuture objects, but real result types (in this case, QList&lt;QImage&gt; and QImage).
705 Using Member Functions
706 <p>
707 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:
708 <pre>
709 // squeeze all strings in a QStringList
710 QStringList strings = ...;
711 QFuture&lt;void&gt; squeezedStrings = QtConcurrent::map(strings, &amp;QString::squeeze);
712
713 // swap the rgb values of all pixels on a list of images
714 QList&lt;QImage&gt; images = ...;
715 QFuture&lt;QImage&gt; bgrImages = QtConcurrent::mapped(images, &amp;QImage::rgbSwapped);
716
717 // create a set of the lengths of all strings in a list
718 QStringList strings = ...;
719 QFuture&lt;QSet&lt;int&gt; &gt; wordLengths = QtConcurrent::mappedReduced(string, &amp;QString::length, &amp;QSet&lt;int&gt;::insert);
720 </pre>
721 Note that when using QtConcurrent::mappedReduced(), you can mix the use of normal and member functions freely:
722 <p>
723 <pre>
724 // can mix normal functions and member functions with QtConcurrent::mappedReduced()
725
726 // compute the average length of a list of strings
727 extern void computeAverage(int &amp;average, int length);
728 QStringList strings = ...;
729 QFuture&lt;int&gt; averageWordLength = QtConcurrent::mappedReduced(strings, &amp;QString::length, computeAverage);
730
731 // create a set of the color distribution of all images in a list
732 extern int colorDistribution(const QImage &amp;string);
733 QList&lt;QImage&gt; images = ...;
734 QFuture&lt;QSet&lt;int&gt; &gt; totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution, QSet&lt;int&gt;::insert);
735 </pre>
736 Using Function Objects
737 <p>
738 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:
739 <pre>
740 struct Scaled
741 {
742 Scaled(int size)
743 : m_size(size) { }
744
745 typedef QImage result_type;
746
747 QImage operator()(const QImage &amp;image)
748 {
749 return image.scaled(m_size, m_size);
750 }
751
752 int m_size;
753 };
754
755 QList&lt;QImage&gt; images = ...;
756 QFuture&lt;QImage&gt; thumbnails = QtConcurrent::mapped(images, Scaled(100));
757 </pre>
758 Using Bound Function Arguments
759 <p>
760 Note that Qt does not provide support for bound functions. This is provided by 3rd party libraries like Boost or C++ TR1 Library Extensions.
761 <p>
762 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.
763 <p>
764 As an example, we'll use QImage::scaledToWidth():
765 <pre>
766 QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const;
767 </pre>
768 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:
769 <pre>
770 boost::bind(&amp;QImage::scaledToWidth, 100 Qt::SmoothTransformation)
771 </pre>
772 The return value from boost::bind() is a function object (functor) with the following signature:
773 <pre>
774 QImage scaledToWith(const QImage &amp;image)
775 </pre>
776 This matches what QtConcurrent::mapped() expects, and the complete example becomes:
777 <pre>
778 QList&gt;QImage&lt; images = ...;
779 QFuture&gt;QImage&lt; thumbnails = QtConcurrent::mapped(images, boost::bind(&amp;QImage::scaledToWidth, 100 Qt::SmoothTransformation));
780 </pre>
781 */
782 class QtConcurrent___ extends QtConcurrent {
783
784 static {
785 qt.QtJambi_LibraryInitializer.init();
786 qt.core.QtJambi_LibraryInitializer.init();
787 }
788
789 /**
790 * An implemetation of this interface is given one to QtConcurrent's map() methods.
791 * The map() method of this interface is called for each object in a java.util.Collection.
792 *
793 */
794 public interface MapFunctor<T> {
795
796 /**
797 * This function is called for each item in the Collection. The function is then free to alter <tt>object</tt> as it see fit.
798 */
799 public void map(T object);
800 }
801 /**
802 * 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.
803 */
804 public static native <T> QFutureVoid map(java.util.Collection<T> sequence, MapFunctor<T> functor);
805
806 /**
807 * 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.
808 */
809 public static native <T> void blockingMap(java.util.Collection<T> sequence, MapFunctor<T> functor);
810
811 /**
812 * Implement this interface to perform a mapped operation. An implementation of the interface is sendt
813 * to ome of the mapped methods of QtConcurrent, which applies the MappedFunctor.map() method to all elements in a collection,
814 * and returns the result.
815 */
816 public interface MappedFunctor<U, T> {
817
818 /**
819 * This method is called for each object in a collection. It should returned a new altered
820 * object.
821 */
822 public U map(T object);
823 }
824
825 /**
826 * 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.
827 *
828 */
829 public static native <U, T> QFuture<U> mapped(java.util.Collection<T> sequence, MappedFunctor<U, T> functor);
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 public static native <U, T> java.util.List<U> blockingMapped(java.util.Collection<T> sequence, MappedFunctor<U, T> functor);
835
836 /**
837 * Implement this interface in order to perform a reduce operation.
838 * <p>
839 * The reduce method will be called once per intermediate result (the result of the mapping of the data)
840 * and the very first time the reduce() method is called for the particular data set, the result is set to
841 * the returned value of the defaultResult() method.
842 */
843 public interface ReducedFunctor<U, T> {
844 public U defaultResult();
845
846 /**
847 * Performs a reduce operation on <tt>intermediate</tt>. <tt>result</tt> is the result of the reduction.
848 */
849 public void reduce(U result, T intermediate);
850 }
851
852 /**
853 * This is an overloaded method provided for convenience.
854 * <p>
855 * It is equivalent of mappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce)
856 */
857 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor) {
858 return mappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce);
859 }
860
861
862 /**
863 * This is an overloaded method provided for convenience.
864 * <p>
865 * 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.
866 *
867 */
868 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOption ... options) {
869 return mappedReduced(sequence, functor, reducedFunctor, new ReduceOptions(options));
870 }
871
872 /**
873 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction.
874 * <p>
875 * 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.
876 *
877 */
878 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOptions options) {
879 return mappedReduced(sequence, functor, reducedFunctor, options.value());
880 }
881
882 private native static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, int options);
883
884
885 /**
886 * This is an overloaded method provided for convenience.
887 * <p>
888 * It is equivalent of calling blockingMappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce)
889 *
890 */
891 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor) {
892 return blockingMappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce);
893 }
894
895 /**
896 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction.
897 * <p>
898 * 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.
899 * <p>
900 * Note: This function will block until all items in the sequence have been processed.
901 */
902 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOption ... options) {
903 return blockingMappedReduced(sequence, functor, reducedFunctor, new ReduceOptions(options));
904 }
905
906 /**
907 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction.
908 * <p>
909 * 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.
910 * <p>
911 * Note: This function will block until all items in the sequence have been processed.
912 */
913 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOptions options) {
914 return blockingMappedReduced(sequence, functor, reducedFunctor, options.value());
915 }
916
917 private native static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, int options);
918
919 /**
920 * An implementation of this interface is given to one of QtConcurrent's filtered() methods.
921 * The filter method if this interface is called for each item in a java.util.Collection.
922 *
923 */
924 public interface FilteredFunctor<T> {
925
926 /**
927 * This method is called for each item in a java.util.Collection. The items for which
928 * this method returns true are removed from the collection.
929 */
930 public boolean filter(T object);
931 }
932
933 /**
934 * 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.
935 */
936 public native static <T> QFuture<T> filtered(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor);
937
938 /**
939 * 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.
940 */
941 public native static <T> java.util.List<T> blockingFiltered(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor);
942
943
944 /**
945 * 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)
946 */
947 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor) {
948 return filteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce);
949 }
950
951 /**
952 * 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.
953 * <p>
954 * 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.
955 */
956 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOption ... options) {
957 return filteredReduced(sequence, filteredFunctor, reducedFunctor, new ReduceOptions(options));
958 }
959
960 /**
961 * 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.
962 * <p>
963 * 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.
964 */
965 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOptions options) {
966 return filteredReduced(sequence, filteredFunctor, reducedFunctor, options.value());
967 }
968 private native static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, int options);
969
970 /**
971 * This is an overloaded method provided for convenience. It is the equivalent of calling blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce)
972 */
973 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor) {
974 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce);
975 }
976
977 /**
978 * 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.
979 * <p>
980 * 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.
981 */
982 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOption ... options) {
983 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, new ReduceOptions(options));
984 }
985
986 /**
987 * 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.
988 * <p>
989 * 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.
990 */
991 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOptions options) {
992 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, options.value());
993 }
994
995 private native static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, int options);
996
997 /**
998 * Executes the method <tt>m</tt> through the QtConcurrent framework with the given arguments. The returned QFuture object's result wil be the
999 * return value of <tt>m</tt>. Note that this method does not accept function that return void. use runVoidMethod() for this.
1000 */
1001 public static <T> QFuture<T> run(Object _this, java.lang.reflect.Method m, Object ... args) {
1002 if (m.getReturnType() == null || m.getReturnType().equals(Void.TYPE))
1003 throw new IllegalArgumentException("Cannot call run on method returning void. Use 'runVoidMethod' instead.");
1004
1005 return runPrivate(_this, m.getDeclaringClass(), m, args, qt.internal.QtJambiInternal.resolveConversionSchema(m.getParameterTypes(), m.getParameterTypes()), qt.internal.QtJambiInternal.typeConversionCode(m.getReturnType()));
1006 }
1007 private native static <T> QFuture<T> runPrivate(Object _this, Class<?> declaringClass, java.lang.reflect.Method m, Object args[], int conversionScheme[], byte returnType);
1008
1009 /**
1010 * Executes the method <tt>m</tt> with the given arguments using the QtConcurrent framework. Notice that runVoidMethod() does not
1011 * accept methods that has a return value. Use the run() method for this purpose.
1012 */
1013 public static QFutureVoid runVoidMethod(Object _this, java.lang.reflect.Method m, Object ... args) {
1014 if (m.getReturnType() != null && !m.getReturnType().equals(Void.TYPE))
1015 throw new IllegalArgumentException("Cannot call runVoidMethod on method returning non-void type. Use 'run' instead.");
1016
1017 return runVoidMethodPrivate(_this, m.getDeclaringClass(), m, args, qt.internal.QtJambiInternal.resolveConversionSchema(m.getParameterTypes(), m.getParameterTypes()));
1018 }
1019 private native static QFutureVoid runVoidMethodPrivate(Object _this, Class<?> declaringClass, java.lang.reflect.Method m, Object args[], int conversionScheme[]);
1020
1021
1022 }// class