Mercurial > projects > qtd
annotate generator/typesystem_core-java.java @ 405:9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
It is specified to be private in the type system back from QtJambi because the functions take a char pointer instead of a QString, but the conversion functions were missing so far.
author | David Nadlinger <code@klickverbot.at> |
---|---|
date | Thu, 17 Mar 2011 23:09:43 +0100 |
parents | e67ce7c21758 |
children |
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. | |
253 | 25 * |
1 | 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 { | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
48 |
368
185df9220ea7
Fixed startsWith. Implemented meta-object members as ranges. Freed QMetaObject from stuff that belongs to MetaClass
Max Samukha <maxter@maxter.com>
parents:
365
diff
changeset
|
49 alias QMetaObject Meta; |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
50 |
253 | 51 /* TODO: test whether the linked list is really a better solution |
183 | 52 public bool __stackAllocated = false; |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
53 |
184
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
54 new(size_t size, void* p = null) |
183 | 55 { |
56 if (!p) | |
57 { | |
58 p = malloc(size); | |
59 if (!p) | |
60 assert(false, "Out of memory"); | |
184
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
61 GC.addRange(p, size); |
183 | 62 } |
63 return p; | |
64 } | |
65 | |
66 delete(void* p) | |
67 { | |
184
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
68 if(p) |
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
69 { |
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
70 if (!(cast(typeof(this))p).__stackAllocated) { |
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
71 free(p); |
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
72 GC.removeRange(p); |
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
73 } |
7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
eldar
parents:
183
diff
changeset
|
74 } |
183 | 75 } |
253 | 76 */ |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
77 |
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
78 /* |
253 | 79 override void onSignalHandlerCreated(ref SignalHandler sh) |
80 { | |
81 sh.signalEvent = &onSignalEvent; | |
82 } | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
83 |
253 | 84 private void onSignalEvent(int signalId, SignalEventId event) |
85 { | |
86 stringz signature; | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
87 signalSignature(signalId, signature); |
253 | 88 if (signature) |
89 { | |
90 switch (event) | |
91 { | |
92 case SignalEventId.firstSlotConnected: | |
93 qtd_connect(__nativeId, signature, signalId, cast(bool)(__flags_ & QtdObjectFlags.dynamicEntity)); | |
94 break; | |
95 case SignalEventId.lastSlotDisconnected: | |
96 qtd_disconnect(__nativeId, signature, signalId, cast(bool)(__flags_ & QtdObjectFlags.dynamicEntity)); | |
97 break; | |
98 default: | |
99 assert (false); | |
100 } | |
101 } | |
102 } | |
288 | 103 */ |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
104 |
253 | 105 /** |
106 */ | |
107 T findChild(T : QObject = QObject)(string name = null) | |
108 { | |
109 foreach (obj; children) | |
110 { | |
111 auto tmp = cast(T)obj; | |
112 if (tmp && (!name.length || tmp.objectName == name)) | |
113 return tmp; | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
114 |
253 | 115 tmp = obj.findChild!(T)(name); |
116 if (tmp) | |
117 return tmp; | |
118 } | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
119 |
253 | 120 return null; |
121 } | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
122 |
253 | 123 /** |
124 */ | |
125 T[] findChildren(T : QObject = QObject)(string name = null) | |
126 { | |
127 T[] result; | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
128 |
253 | 129 void find(QObject[] objects) |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
130 { |
253 | 131 foreach (obj; objects) |
132 { | |
133 auto tmp = cast(T)obj; | |
134 if (tmp && (!name.length || tmp.objectName == name)) | |
135 result ~= tmp; | |
136 find(obj.children); | |
137 } | |
138 } | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
139 |
253 | 140 find(children); |
141 return result; | |
142 } | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
368
diff
changeset
|
143 |
337 | 144 static void connect(QObject sender, string signal, QObject receiver, string method, int type = 0) |
288 | 145 { |
337 | 146 QMetaObject.connectImpl(sender, signal, receiver, method, type); |
288 | 147 } |
405
9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
David Nadlinger <code@klickverbot.at>
parents:
402
diff
changeset
|
148 |
9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
David Nadlinger <code@klickverbot.at>
parents:
402
diff
changeset
|
149 public final QVariant property(string name) { |
9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
David Nadlinger <code@klickverbot.at>
parents:
402
diff
changeset
|
150 return property(name is null? null : toStringz(name)); |
9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
David Nadlinger <code@klickverbot.at>
parents:
402
diff
changeset
|
151 } |
9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
David Nadlinger <code@klickverbot.at>
parents:
402
diff
changeset
|
152 |
9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
David Nadlinger <code@klickverbot.at>
parents:
402
diff
changeset
|
153 public final bool setProperty(string name, QVariant value) { |
9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
David Nadlinger <code@klickverbot.at>
parents:
402
diff
changeset
|
154 return setProperty(name is null? null : toStringz(name), value); |
9d6e4703a458
Make QObject::property()/setProperty() accessible from D.
David Nadlinger <code@klickverbot.at>
parents:
402
diff
changeset
|
155 } |
1 | 156 }// class |
157 | |
158 abstract class QAbstractItemModel___ extends QAbstractItemModel { | |
159 /* private native boolean setData_native(long id, int row, int col, Object value, int role); | |
160 | |
161 public final boolean setData(int row, int col, Object value) { | |
162 return setData_native(nativeId(), row, col, value, qt.core.Qt.ItemDataRole.DisplayRole); | |
163 } | |
164 | |
165 public final boolean setData(int row, int col, Object value, int role) { | |
166 return setData_native(nativeId(), row, col, value, role); | |
167 } | |
168 | |
169 private native Object data_native(long id, int row, int col, int role); | |
170 | |
171 public final Object data(int row, int col, int role) { | |
172 return data_native(nativeId(), row, col, role); | |
173 } | |
174 | |
175 public final Object data(int row, int col) { | |
176 return data_native(nativeId(), row, col, Qt.ItemDataRole.DisplayRole); | |
177 }*/ | |
178 }// class | |
179 | |
180 class QTimer___ extends QTimer { | |
181 static private class QSingleShotTimer extends QObject { | |
182 private int timerId = -1; | |
183 public Signal0 timeout = new Signal0(); | |
184 | |
185 public QSingleShotTimer(int msec, QObject obj, String method) { | |
186 super(obj); | |
187 timeout.connect(obj, method); | |
188 timerId = startTimer(msec); | |
189 } | |
190 | |
191 protected void disposed() { | |
192 if (timerId > 0) | |
193 killTimer(timerId); | |
194 super.disposed(); | |
195 } | |
196 | |
197 protected void timerEvent(QTimerEvent e) { | |
198 if (timerId > 0) | |
199 killTimer(timerId); | |
200 timerId = -1; | |
201 timeout.emit(); | |
202 disposeLater(); | |
203 } | |
204 } | |
205 | |
206 public static void singleShot(int msec, QObject obj, String method) { | |
207 new QSingleShotTimer(msec, obj, method); | |
208 } | |
209 }// class | |
210 | |
211 class QCoreApplication___ extends QCoreApplication { | |
212 | |
213 protected static QCoreApplication m_instance = null; | |
214 | |
188 | 215 this(string[] args) |
1 | 216 { |
217 // if (m_instance != null) | |
218 // throw new RuntimeException("QCoreApplication can only be initialized once"); | |
253 | 219 |
402 | 220 argc = cast(int) args.length; |
1 | 221 argv = toStringzArray(args); |
222 this(&argc, argv); | |
223 | |
224 // m_instance.aboutToQuit.connect(m_instance, "disposeOfMyself()"); | |
225 } | |
253 | 226 |
1 | 227 private int argc; |
228 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
|
229 /* |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 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
|
234 } |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
235 |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 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
|
240 } |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
1
diff
changeset
|
241 */ |
1 | 242 }// class |
243 | |
244 class QTranslator___ extends QTranslator { | |
245 public final bool load(ubyte[] data) { | |
402 | 246 return load(data.ptr, cast(int)data.length); |
1 | 247 } |
248 }// class | |
249 | |
250 class QProcess___ extends QProcess { | |
251 | |
252 public static class DetachedProcessInfo { | |
253 public DetachedProcessInfo(boolean success, long pid) { | |
254 this.success = success; | |
255 this.pid = pid; | |
256 } | |
257 | |
258 public boolean success; | |
259 public long pid; | |
260 } | |
261 | |
262 public static DetachedProcessInfo startDetached(String program, java.util.List<String> arguments, String workingDirectory) { | |
263 QNativePointer pid = new QNativePointer(QNativePointer.Type.Long); | |
264 boolean success = startDetached(program, arguments, workingDirectory, pid); | |
265 return new DetachedProcessInfo(success, pid.longValue()); | |
266 } | |
267 }// class | |
268 | |
269 class QDataStream___ extends QDataStream { | |
270 | |
271 public final bool readBoolean() { | |
272 bool res; | |
273 operator_shift_right_boolean(&res); | |
274 return res; | |
275 } | |
276 | |
277 public final byte readByte() { | |
278 byte res; | |
279 operator_shift_right_byte(&res); | |
280 return res; | |
281 } | |
282 | |
283 public final short readShort() { | |
284 short res; | |
285 operator_shift_right_short(&res); | |
286 return res; | |
287 } | |
288 | |
289 public final int readInt() { | |
290 int res; | |
291 operator_shift_right_int(&res); | |
292 return res; | |
293 } | |
294 | |
295 public final long readLong() { | |
296 long res; | |
297 operator_shift_right_long(&res); | |
298 return res; | |
299 } | |
300 | |
301 public final ushort readChar() { | |
302 ushort res; | |
303 operator_shift_right_char(&res); | |
304 return res; | |
305 } | |
306 | |
307 public final float readFloat() { | |
308 float res; | |
309 operator_shift_right_float(&res); | |
310 return res; | |
311 } | |
312 | |
313 public final double readDouble() { | |
314 double res; | |
315 operator_shift_right_double(&res); | |
316 return res; | |
317 } | |
318 | |
319 public final QDataStream writeShort(short s) { | |
320 writeShort_char(s); | |
321 return this; | |
322 } | |
323 /* | |
324 private static extern(C) void qtd_QDataStream_readString_private(void* __this_nativeId); | |
325 | |
326 private native void writeString_private(long nativeId, String string); | |
327 | |
328 public final String readString() { | |
329 if (nativeId() == 0) | |
330 throw new QNoNativeResourcesException("Function call on incomplete object of type: " + getClass().getName()); | |
331 return readString_private(nativeId()); | |
332 } | |
333 | |
334 public final void writeString(String string) { | |
335 if (nativeId() == 0) | |
336 throw new QNoNativeResourcesException("Function call on incomplete object of type: " + getClass().getName()); | |
337 writeString_private(nativeId(), string); | |
338 } | |
339 | |
340 private native int writeBytes(long id, byte buffer[], int length); | |
341 | |
342 private native int readBytes(long id, byte buffer[], int length); | |
343 | |
344 public final int writeBytes(byte buffer[]) { | |
345 return writeBytes(buffer, buffer.length); | |
346 } | |
347 | |
348 public final int writeBytes(byte buffer[], int length) { | |
349 return writeBytes(nativeId(), buffer, length); | |
350 } | |
351 | |
352 public final int readBytes(byte buffer[]) { | |
353 return readBytes(buffer, buffer.length); | |
354 } | |
355 | |
356 public final int readBytes(byte buffer[], int length) { | |
357 return readBytes(nativeId(), buffer, length); | |
358 } | |
359 */ | |
360 }// class | |
361 | |
362 class QTextStream___ extends QTextStream { | |
363 /* public final void setCodec(String codecName) { | |
364 setCodec(QNativePointer.createCharPointer(codecName)); | |
365 if (codec() != __rcCodec) | |
366 __rcCodec = null; | |
367 } | |
368 | |
369 private QNativePointer srb = new QNativePointer(QNativePointer.Type.Byte, 32) { | |
370 { | |
371 setVerificationEnabled(false); | |
372 } | |
373 }; | |
374 | |
375 public final byte readByte() { | |
376 operator_shift_right_byte(srb); | |
377 return srb.byteValue(); | |
378 } | |
379 | |
380 public final short readShort() { | |
381 operator_shift_right_short(srb); | |
382 return srb.shortValue(); | |
383 } | |
384 | |
385 public final int readInt() { | |
386 operator_shift_right_int(srb); | |
387 return srb.intValue(); | |
388 } | |
389 | |
390 public final long readLong() { | |
391 operator_shift_right_long(srb); | |
392 return srb.longValue(); | |
393 } | |
394 | |
395 public final float readFloat() { | |
396 operator_shift_right_float(srb); | |
397 return srb.floatValue(); | |
398 } | |
399 | |
400 public final double readDouble() { | |
401 operator_shift_right_double(srb); | |
402 return srb.doubleValue(); | |
403 } | |
404 | |
405 public final QTextStream writeShort(short s) { | |
406 writeShort_char((char) s); | |
407 return this; | |
408 } | |
409 | |
410 public final QTextStream writeChar(char c) { | |
411 writeShort_char(c); | |
412 return this; | |
413 } | |
414 | |
415 public final char readChar() { | |
416 operator_shift_right_short(srb); | |
417 return srb.charValue(); | |
418 } | |
419 | |
420 public final String readString() { | |
421 return readString_native(nativeId()); | |
422 } | |
423 | |
424 public final void writeString(String string) { | |
425 writeString_native(nativeId(), string); | |
426 } | |
427 | |
428 private final native String readString_native(long id); | |
429 | |
430 private final native void writeString_native(long id, String string); | |
431 */ | |
432 }// class | |
433 | |
434 class QBitArray___ extends QBitArray { | |
435 /* | |
436 @qt.QtBlockedSlot | |
437 public final void xor(QBitArray other) { | |
438 operator_xor_assign(other); | |
439 } | |
440 | |
441 @qt.QtBlockedSlot | |
442 public final void and(QBitArray other) { | |
443 operator_and_assign(other); | |
444 } | |
445 | |
446 @qt.QtBlockedSlot | |
447 public final void or(QBitArray other) { | |
448 operator_or_assign(other); | |
449 } | |
450 | |
451 @qt.QtBlockedSlot | |
452 public final void set(QBitArray other) { | |
453 operator_assign(other); | |
454 } | |
455 | |
456 @qt.QtBlockedSlot | |
457 public final QBitArray inverted() { | |
458 return operator_negate(); | |
459 } | |
460 */ | |
461 }// class | |
462 | |
463 // hfr | |
464 | |
465 class QDate___ extends QDate { | |
466 | |
467 public final int weekNumber() { | |
468 return weekNumber(null); | |
469 } | |
470 | |
471 public final int yearOfWeekNumber() { | |
472 int np; | |
473 weekNumber(&np); | |
474 return np; | |
475 } | |
476 | |
477 }// class | |
478 | |
479 class QDir___ extends QDir { | |
480 /* | |
481 @qt.QtBlockedSlot | |
482 public String at(int i) { | |
483 return operator_subscript(i); | |
484 } | |
485 */ | |
486 }// class | |
487 | |
488 class QByteArray___ extends QByteArray { | |
489 public QByteArray(String s) { | |
490 this(); | |
491 append(s); | |
492 } | |
493 | |
494 public QByteArray(byte data[]) { | |
495 this(qt.internal.QtJambiInternal.byteArrayToNativePointer(data), data.length); | |
496 } | |
497 | |
498 public final boolean contains(String str) { | |
499 return contains(new QByteArray(str)); | |
500 } | |
501 | |
502 public final int count(String str) { | |
503 return count(new QByteArray(str)); | |
504 } | |
505 | |
506 public final boolean endsWith(String str) { | |
507 return endsWith(new QByteArray(str)); | |
508 } | |
509 | |
510 public final QByteArray prepend(String str) { | |
511 return prepend(new QByteArray(str)); | |
512 } | |
513 | |
514 public final QByteArray replace(QByteArray before, String after) { | |
515 return replace(before, new QByteArray(after)); | |
516 } | |
517 | |
518 public final QByteArray replace(String before, String after) { | |
519 return replace(new QByteArray(before), new QByteArray(after)); | |
520 } | |
521 | |
522 public final boolean startsWith(String str) { | |
523 return startsWith(new QByteArray(str)); | |
524 } | |
525 | |
526 public final byte[] toByteArray() { | |
527 byte[] res = new byte[size()]; | |
528 | |
529 for (int i = 0; i < size(); i++) { | |
530 res[i] = at(i); | |
531 } | |
532 return res; | |
533 } | |
534 | |
535 @qt.QtBlockedSlot | |
536 public final QByteArray set(QByteArray other) { | |
537 operator_assign(other); | |
538 return this; | |
539 } | |
540 | |
541 }// class | |
542 | |
543 class QFile___ extends QFile { | |
544 /* | |
545 public static String decodeName(String localFileName) { | |
546 return decodeName(qt.QNativePointer.createCharPointer(localFileName)); | |
547 } | |
548 */ | |
549 }// class | |
550 | |
551 class QIODevice___ extends QIODevice { | |
552 | |
553 /** | |
554 * Gets a byte from the device. | |
555 * | |
556 * @return -1 on failure, or the value of the byte on success | |
557 */ | |
558 /* public final int getByte() { | |
559 QNativePointer np = new QNativePointer(QNativePointer.Type.Byte); | |
560 boolean success = getByte(np); | |
561 return success ? np.byteValue() : -1; | |
562 } | |
563 */ | |
180 | 564 |
565 public final long write(string str) { | |
566 return write(str.ptr, str.length); | |
253 | 567 } |
1 | 568 }// class |
569 | |
570 class QCryptographicHash___ extends QCryptographicHash { | |
571 | |
572 public final void addData(byte data[]) { | |
573 QNativePointer np = qt.internal.QtJambiInternal.byteArrayToNativePointer(data); | |
574 addData(np, data.length); | |
575 } | |
576 | |
577 }// class | |
578 | |
579 class QTextCodec___ extends QTextCodec { | |
580 /* | |
581 static { | |
582 setCodecForTr(QTextCodec.codecForName("UTF-8")); | |
583 } | |
584 | |
585 public static QTextCodec codecForName(String name) { | |
586 return codecForName(qt.QNativePointer.createCharPointer(name)); | |
587 } | |
588 */ | |
589 }// class | |
590 | |
591 class QBuffer___ extends QBuffer { | |
592 | |
593 // retain a reference to avoid gc | |
594 private Object strongDataReference = null; | |
595 public final void setBuffer(QByteArray byteArray) { | |
90 | 596 setBuffer_private(byteArray); |
1 | 597 strongDataReference = byteArray; |
598 } | |
599 | |
600 public final void setData(byte data[]) { | |
402 | 601 setData(cast(char*)data.ptr, cast(int)data.length); |
1 | 602 } |
603 | |
604 }// class | |
605 | |
606 class QSignalMapper___ extends QSignalMapper { | |
607 | |
608 private java.util.Hashtable<QObject, QObject> __rcObjectForObject = new java.util.Hashtable<QObject, QObject>(); | |
609 | |
610 private java.util.Hashtable<QObject, Object> __rcWidgetForObject = new java.util.Hashtable<QObject, Object>(); | |
611 | |
612 }// class | |
613 | |
614 class QAbstractFileEngine_MapExtensionReturn___ extends QAbstractFileEngine_MapExtensionReturn { | |
615 /* private QNativePointer currentAddressNativePointer; // don't garbage collect while in use | |
616 public final void setAddress(String address) { | |
617 currentAddressNativePointer = address != null ? QNativePointer.createCharPointer(address) : null; | |
618 address_private(currentAddressNativePointer); | |
619 } | |
620 | |
621 public final String address() { | |
622 QNativePointer np = address_private(); | |
623 return np != null ? qt.internal.QtJambiInternal.charPointerToString(np) : null; | |
624 }*/ | |
625 }// class | |
626 | |
627 class QAbstractFileEngine___ extends QAbstractFileEngine { | |
628 /** | |
629 * Adds <tt>path</tt> to the set of paths in which Qt Jambi should search for resources. Resources | |
630 * can be accessed using the "classpath:" scheme. | |
631 */ | |
632 /* public static void addSearchPathForResourceEngine(String path) | |
633 { | |
634 qt.internal.QClassPathEngine.addSearchPath(path); | |
635 } | |
636 */ | |
637 /** | |
638 * Removes <tt>path</tt> from the set of paths in which Qt Jambi searches | |
639 * for resources. | |
640 */ | |
641 /* public static void removeSearchPathForResourceEngine(String path) | |
642 { | |
643 qt.internal.QClassPathEngine.removeSearchPath(path); | |
644 } | |
645 */ | |
646 }// class | |
647 | |
648 class QAbstractFileEngine_UnMapExtensionOption___ extends QAbstractFileEngine_UnMapExtensionOption { | |
649 private QNativePointer currentAddressNativePointer; // don't garbage collect while in use | |
650 public final void setAddress(String address) { | |
651 currentAddressNativePointer = address != null ? QNativePointer.createCharPointer(address) : null; | |
652 address_private(currentAddressNativePointer); | |
653 } | |
654 | |
655 public final String address() { | |
656 QNativePointer np = address_private(); | |
657 return np != null ? qt.internal.QtJambiInternal.charPointerToString(np) : null; | |
658 } | |
659 }// class | |
660 | |
661 class QFutureWatcher___ extends QFutureWatcher { | |
662 | |
663 public final QFuture<T> future() { | |
664 if (nativeId() == 0) | |
665 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
666 return __qt_future(nativeId()); | |
667 } | |
668 private native QFuture<T> __qt_future(long nativeId); | |
669 | |
670 }// class | |
671 | |
672 class QFutureWatcherVoid___ extends QFutureWatcherVoid { | |
673 | |
674 public final QFutureVoid future() { | |
675 if (nativeId() == 0) | |
676 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
677 return __qt_future(nativeId()); | |
678 } | |
679 | |
680 private native QFutureVoid __qt_future(long nativeId); | |
681 | |
682 }// class | |
683 | |
684 class QFutureSynchronizer___ extends QFutureSynchronizer { | |
685 | |
686 public final java.util.List<QFuture<T>> futures() { | |
687 if (nativeId() == 0) | |
688 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
689 return __qt_futures(nativeId()); | |
690 } | |
691 private native java.util.List<QFuture<T>> __qt_futures(long nativeId); | |
692 | |
693 }// class | |
694 | |
695 class QFutureSynchronizerVoid___ extends QFutureSynchronizerVoid { | |
696 | |
697 public final java.util.List<QFutureVoid> futures() { | |
698 if (nativeId() == 0) | |
699 throw new QNoNativeResourcesException("Function call on incomplete object of type: " +getClass().getName()); | |
700 return __qt_futures(nativeId()); | |
701 } | |
702 private native java.util.List<QFutureVoid> __qt_futures(long nativeId); | |
703 | |
704 }// class | |
705 | |
706 class QLineF___ extends QLineF { | |
707 /* | |
708 public final QLineF.IntersectType intersect(QLineF line, qt.core.QPointF intersectionPoint) { | |
709 return intersect(line, intersectionPoint != null ? intersectionPoint.nativePointer() : null); | |
710 } | |
711 */ | |
712 }// class | |
713 | |
714 /** | |
715 The QtConcurrent class contains static methods for running computations in parallel (using separate threads) | |
716 on the items in a java.util.Collection, such as a Vector or LinkedList. We will now describe these methods. | |
717 | |
718 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. | |
719 Concurrent Map | |
720 <p> | |
721 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. | |
722 <p> | |
723 The map function must be of the form: | |
724 <pre> | |
725 U function(const T &t); | |
726 </pre> | |
727 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. | |
728 <p> | |
729 This example shows how to apply a scale function to all the items in a sequence: | |
730 <pre> | |
731 QImage scaled(const QImage &image) | |
732 { | |
733 return image.scaled(100, 100); | |
734 } | |
735 | |
736 QList <QImage> images = ...; | |
737 QFuture<QImage> thumbnails = QtConcurrent::mapped(images, scaled); | |
738 </pre> | |
739 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. | |
740 <p> | |
741 If you want to modify a sequence in-place, use QtConcurrent::map(). The map function must then be of the form: | |
742 <pre> | |
743 U function(T &t); | |
744 </pre> | |
745 Note that the return value and return type of the map function are not used. | |
746 <p> | |
747 Using QtConcurrent::map() is similar to using QtConcurrent::mapped(): | |
748 <pre> | |
749 void scale(QImage &image) | |
750 { | |
751 image = image.scaled(100, 100); | |
752 } | |
753 | |
754 QList<QImage> images = ...; | |
755 QFuture<void> future = QtConcurrent::map(images, scale); | |
756 </pre> | |
757 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. | |
758 Concurrent Map-Reduce | |
759 <p> | |
760 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. | |
761 <p> | |
762 The reduce function must be of the form: | |
763 <pre> | |
764 V function(T &result, const U &intermediate) | |
765 </pre> | |
766 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. | |
767 <p> | |
768 Call QtConcurrent::mappedReduced() like this: | |
769 <pre> | |
770 void addToCollage(QImage &collage, const QImage &thumbnail) | |
771 { | |
772 QPainter p(&collage); | |
773 static QPoint offset = QPoint(0, 0); | |
774 p.drawImage(offset, thumbnail); | |
775 offset += ...; | |
776 } | |
777 | |
778 QList<QImage> images = ...; | |
779 QFuture<QImage> collage = QtConcurrent::mappedReduced(images, scaled, addToCollage); | |
780 </pre> | |
781 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. | |
782 Additional API Features | |
783 Using Iterators instead of Sequence | |
784 <p> | |
785 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: | |
786 <pre> | |
787 QList<QImage> images = ...; | |
788 | |
789 QFuture<QImage> thumbnails = QtConcurrent::mapped(images.constBegin(), images.constEnd(), scaled); | |
790 | |
791 // map in-place only works on non-const iterators | |
792 QFuture<void> future = QtConcurrent::map(images.begin(), images.end(), scale); | |
793 | |
794 QFuture<QImage> collage = QtConcurrent::mappedReduced(images.constBegin(), images.constEnd(), scaled, addToCollage); | |
795 </pre> | |
796 Blocking Variants | |
797 <p> | |
798 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. | |
799 <pre> | |
800 QList<QImage> images = ...; | |
801 | |
802 // each call blocks until the entire operation is finished | |
803 QList<QImage> future = QtConcurrent::blockingMapped(images, scaled); | |
804 | |
805 QtConcurrent::blockingMap(images, scale); | |
806 | |
807 QImage collage = QtConcurrent::blockingMappedReduced(images, scaled, addToCollage); | |
808 </pre> | |
809 Note that the result types above are not QFuture objects, but real result types (in this case, QList<QImage> and QImage). | |
810 Using Member Functions | |
811 <p> | |
812 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: | |
813 <pre> | |
814 // squeeze all strings in a QStringList | |
815 QStringList strings = ...; | |
816 QFuture<void> squeezedStrings = QtConcurrent::map(strings, &QString::squeeze); | |
817 | |
818 // swap the rgb values of all pixels on a list of images | |
819 QList<QImage> images = ...; | |
820 QFuture<QImage> bgrImages = QtConcurrent::mapped(images, &QImage::rgbSwapped); | |
821 | |
822 // create a set of the lengths of all strings in a list | |
823 QStringList strings = ...; | |
824 QFuture<QSet<int> > wordLengths = QtConcurrent::mappedReduced(string, &QString::length, &QSet<int>::insert); | |
825 </pre> | |
826 Note that when using QtConcurrent::mappedReduced(), you can mix the use of normal and member functions freely: | |
827 <p> | |
828 <pre> | |
829 // can mix normal functions and member functions with QtConcurrent::mappedReduced() | |
830 | |
831 // compute the average length of a list of strings | |
832 extern void computeAverage(int &average, int length); | |
833 QStringList strings = ...; | |
834 QFuture<int> averageWordLength = QtConcurrent::mappedReduced(strings, &QString::length, computeAverage); | |
835 | |
836 // create a set of the color distribution of all images in a list | |
837 extern int colorDistribution(const QImage &string); | |
838 QList<QImage> images = ...; | |
839 QFuture<QSet<int> > totalColorDistribution = QtConcurrent::mappedReduced(images, colorDistribution, QSet<int>::insert); | |
840 </pre> | |
841 Using Function Objects | |
842 <p> | |
843 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: | |
844 <pre> | |
845 struct Scaled | |
846 { | |
847 Scaled(int size) | |
848 : m_size(size) { } | |
849 | |
850 typedef QImage result_type; | |
851 | |
852 QImage operator()(const QImage &image) | |
853 { | |
854 return image.scaled(m_size, m_size); | |
855 } | |
856 | |
857 int m_size; | |
858 }; | |
859 | |
860 QList<QImage> images = ...; | |
861 QFuture<QImage> thumbnails = QtConcurrent::mapped(images, Scaled(100)); | |
862 </pre> | |
863 Using Bound Function Arguments | |
864 <p> | |
865 Note that Qt does not provide support for bound functions. This is provided by 3rd party libraries like Boost or C++ TR1 Library Extensions. | |
866 <p> | |
867 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. | |
868 <p> | |
869 As an example, we'll use QImage::scaledToWidth(): | |
870 <pre> | |
871 QImage QImage::scaledToWidth(int width, Qt::TransformationMode) const; | |
872 </pre> | |
873 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: | |
874 <pre> | |
875 boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation) | |
876 </pre> | |
877 The return value from boost::bind() is a function object (functor) with the following signature: | |
878 <pre> | |
879 QImage scaledToWith(const QImage &image) | |
880 </pre> | |
881 This matches what QtConcurrent::mapped() expects, and the complete example becomes: | |
882 <pre> | |
883 QList>QImage< images = ...; | |
884 QFuture>QImage< thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation)); | |
885 </pre> | |
886 */ | |
887 class QtConcurrent___ extends QtConcurrent { | |
888 | |
889 static { | |
890 qt.QtJambi_LibraryInitializer.init(); | |
891 qt.core.QtJambi_LibraryInitializer.init(); | |
892 } | |
893 | |
894 /** | |
895 * An implemetation of this interface is given one to QtConcurrent's map() methods. | |
896 * The map() method of this interface is called for each object in a java.util.Collection. | |
897 * | |
898 */ | |
899 public interface MapFunctor<T> { | |
900 | |
901 /** | |
902 * This function is called for each item in the Collection. The function is then free to alter <tt>object</tt> as it see fit. | |
903 */ | |
904 public void map(T object); | |
905 } | |
906 /** | |
907 * 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. | |
908 */ | |
909 public static native <T> QFutureVoid map(java.util.Collection<T> sequence, MapFunctor<T> functor); | |
910 | |
911 /** | |
912 * 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. | |
913 */ | |
914 public static native <T> void blockingMap(java.util.Collection<T> sequence, MapFunctor<T> functor); | |
915 | |
916 /** | |
917 * Implement this interface to perform a mapped operation. An implementation of the interface is sendt | |
918 * to ome of the mapped methods of QtConcurrent, which applies the MappedFunctor.map() method to all elements in a collection, | |
919 * and returns the result. | |
920 */ | |
921 public interface MappedFunctor<U, T> { | |
922 | |
923 /** | |
924 * This method is called for each object in a collection. It should returned a new altered | |
925 * object. | |
926 */ | |
927 public U map(T object); | |
928 } | |
929 | |
930 /** | |
931 * 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. | |
932 * | |
933 */ | |
934 public static native <U, T> QFuture<U> mapped(java.util.Collection<T> sequence, MappedFunctor<U, T> functor); | |
935 | |
936 /** | |
937 * 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. | |
938 */ | |
939 public static native <U, T> java.util.List<U> blockingMapped(java.util.Collection<T> sequence, MappedFunctor<U, T> functor); | |
940 | |
941 /** | |
942 * Implement this interface in order to perform a reduce operation. | |
943 * <p> | |
944 * The reduce method will be called once per intermediate result (the result of the mapping of the data) | |
945 * and the very first time the reduce() method is called for the particular data set, the result is set to | |
946 * the returned value of the defaultResult() method. | |
947 */ | |
948 public interface ReducedFunctor<U, T> { | |
949 public U defaultResult(); | |
950 | |
951 /** | |
952 * Performs a reduce operation on <tt>intermediate</tt>. <tt>result</tt> is the result of the reduction. | |
953 */ | |
954 public void reduce(U result, T intermediate); | |
955 } | |
956 | |
957 /** | |
958 * This is an overloaded method provided for convenience. | |
959 * <p> | |
960 * It is equivalent of mappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
961 */ | |
962 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor) { | |
963 return mappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
964 } | |
965 | |
966 | |
967 /** | |
968 * This is an overloaded method provided for convenience. | |
969 * <p> | |
970 * 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. | |
971 * | |
972 */ | |
973 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOption ... options) { | |
974 return mappedReduced(sequence, functor, reducedFunctor, new ReduceOptions(options)); | |
975 } | |
976 | |
977 /** | |
978 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
979 * <p> | |
980 * 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. | |
981 * | |
982 */ | |
983 public static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOptions options) { | |
984 return mappedReduced(sequence, functor, reducedFunctor, options.value()); | |
985 } | |
986 | |
987 private native static <U, V, T> QFuture<U> mappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, int options); | |
988 | |
989 | |
990 /** | |
991 * This is an overloaded method provided for convenience. | |
992 * <p> | |
993 * It is equivalent of calling blockingMappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
994 * | |
995 */ | |
996 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor) { | |
997 return blockingMappedReduced(sequence, functor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
998 } | |
999 | |
1000 /** | |
1001 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
1002 * <p> | |
1003 * 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. | |
1004 * <p> | |
1005 * Note: This function will block until all items in the sequence have been processed. | |
1006 */ | |
1007 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOption ... options) { | |
1008 return blockingMappedReduced(sequence, functor, reducedFunctor, new ReduceOptions(options)); | |
1009 } | |
1010 | |
1011 /** | |
1012 * Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to reduceFunction. | |
1013 * <p> | |
1014 * 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. | |
1015 * <p> | |
1016 * Note: This function will block until all items in the sequence have been processed. | |
1017 */ | |
1018 public static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, ReduceOptions options) { | |
1019 return blockingMappedReduced(sequence, functor, reducedFunctor, options.value()); | |
1020 } | |
1021 | |
1022 private native static <U, V, T> U blockingMappedReduced(java.util.Collection<T> sequence, MappedFunctor<V, T> functor, ReducedFunctor<U, V> reducedFunctor, int options); | |
1023 | |
1024 /** | |
1025 * An implementation of this interface is given to one of QtConcurrent's filtered() methods. | |
1026 * The filter method if this interface is called for each item in a java.util.Collection. | |
1027 * | |
1028 */ | |
1029 public interface FilteredFunctor<T> { | |
1030 | |
1031 /** | |
1032 * This method is called for each item in a java.util.Collection. The items for which | |
1033 * this method returns true are removed from the collection. | |
1034 */ | |
1035 public boolean filter(T object); | |
1036 } | |
1037 | |
1038 /** | |
1039 * 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. | |
1040 */ | |
1041 public native static <T> QFuture<T> filtered(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor); | |
1042 | |
1043 /** | |
1044 * 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. | |
1045 */ | |
1046 public native static <T> java.util.List<T> blockingFiltered(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor); | |
1047 | |
1048 | |
1049 /** | |
1050 * 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) | |
1051 */ | |
1052 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor) { | |
1053 return filteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
1054 } | |
1055 | |
1056 /** | |
1057 * 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. | |
1058 * <p> | |
1059 * 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. | |
1060 */ | |
1061 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOption ... options) { | |
1062 return filteredReduced(sequence, filteredFunctor, reducedFunctor, new ReduceOptions(options)); | |
1063 } | |
1064 | |
1065 /** | |
1066 * 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. | |
1067 * <p> | |
1068 * 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. | |
1069 */ | |
1070 public static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOptions options) { | |
1071 return filteredReduced(sequence, filteredFunctor, reducedFunctor, options.value()); | |
1072 } | |
1073 private native static <U, T> QFuture<U> filteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, int options); | |
1074 | |
1075 /** | |
1076 * This is an overloaded method provided for convenience. It is the equivalent of calling blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce) | |
1077 */ | |
1078 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor) { | |
1079 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, ReduceOption.UnorderedReduce, ReduceOption.SequentialReduce); | |
1080 } | |
1081 | |
1082 /** | |
1083 * 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. | |
1084 * <p> | |
1085 * 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. | |
1086 */ | |
1087 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOption ... options) { | |
1088 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, new ReduceOptions(options)); | |
1089 } | |
1090 | |
1091 /** | |
1092 * 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. | |
1093 * <p> | |
1094 * 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. | |
1095 */ | |
1096 public static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, ReduceOptions options) { | |
1097 return blockingFilteredReduced(sequence, filteredFunctor, reducedFunctor, options.value()); | |
1098 } | |
1099 | |
1100 private native static <U, T> U blockingFilteredReduced(java.util.Collection<T> sequence, FilteredFunctor<T> filteredFunctor, ReducedFunctor<U, T> reducedFunctor, int options); | |
1101 | |
1102 /** | |
1103 * Executes the method <tt>m</tt> through the QtConcurrent framework with the given arguments. The returned QFuture object's result wil be the | |
1104 * return value of <tt>m</tt>. Note that this method does not accept function that return void. use runVoidMethod() for this. | |
1105 */ | |
1106 public static <T> QFuture<T> run(Object _this, java.lang.reflect.Method m, Object ... args) { | |
1107 if (m.getReturnType() == null || m.getReturnType().equals(Void.TYPE)) | |
1108 throw new IllegalArgumentException("Cannot call run on method returning void. Use 'runVoidMethod' instead."); | |
1109 | |
1110 return runPrivate(_this, m.getDeclaringClass(), m, args, qt.internal.QtJambiInternal.resolveConversionSchema(m.getParameterTypes(), m.getParameterTypes()), qt.internal.QtJambiInternal.typeConversionCode(m.getReturnType())); | |
1111 } | |
1112 private native static <T> QFuture<T> runPrivate(Object _this, Class<?> declaringClass, java.lang.reflect.Method m, Object args[], int conversionScheme[], byte returnType); | |
1113 | |
1114 /** | |
1115 * Executes the method <tt>m</tt> with the given arguments using the QtConcurrent framework. Notice that runVoidMethod() does not | |
1116 * accept methods that has a return value. Use the run() method for this purpose. | |
1117 */ | |
1118 public static QFutureVoid runVoidMethod(Object _this, java.lang.reflect.Method m, Object ... args) { | |
1119 if (m.getReturnType() != null && !m.getReturnType().equals(Void.TYPE)) | |
1120 throw new IllegalArgumentException("Cannot call runVoidMethod on method returning non-void type. Use 'run' instead."); | |
1121 | |
1122 return runVoidMethodPrivate(_this, m.getDeclaringClass(), m, args, qt.internal.QtJambiInternal.resolveConversionSchema(m.getParameterTypes(), m.getParameterTypes())); | |
1123 } | |
1124 private native static QFutureVoid runVoidMethodPrivate(Object _this, Class<?> declaringClass, java.lang.reflect.Method m, Object args[], int conversionScheme[]); | |
1125 | |
1126 | |
1127 }// class |