io.qt.core.QtFuture Maven / Gradle / Ivy
Show all versions of qtjambi Show documentation
package io.qt.core;
import io.qt.*;
/**
* Contains miscellaneous identifiers used by the QFuture class
* Java wrapper for Qt header file QtFuture
*/
public final class QtFuture
{
static {
QtJambi_LibraryUtilities.initialize();
}
private QtFuture() throws java.lang.InstantiationError { throw new java.lang.InstantiationError("Cannot instantiate namespace QtFuture."); }
/**
* Java wrapper for Qt enum QtFuture::Launch
* This enum was introduced in Qt 6.0.
*/
public enum Launch implements QtEnumerator {
/**
* Representing QtFuture:: Launch:: Sync
*/
Sync(0),
/**
* Representing QtFuture:: Launch:: Async
*/
Async(1),
/**
* Representing QtFuture:: Launch:: Inherit
*/
Inherit(2);
static {
QtJambi_LibraryUtilities.initialize();
}
private Launch(int value) {
this.value = value;
}
/**
* {@inheritDoc}
*/
@Override
public int value() {
return value;
}
/**
* Returns the corresponding enum entry for the given value.
* @param value
* @return enum entry
*/
public static @NonNull Launch resolve(int value) {
switch (value) {
case 0: return Sync;
case 1: return Async;
case 2: return Inherit;
default: throw new QNoSuchEnumValueException(value);
}
}
private final int value;
}
/**
* See QtFuture:: makeReadyVoidFuture()
* This function was introduced in Qt 6.6.
*/
public native static io.qt.core.@NonNull QFuture makeReadyVoidFuture();
/**
* See QtFuture::connect(Sender *, Signal)
*/
@QtUninvokable
public static @NonNull QFuture connect(QMetaObject.@StrictNonNull AbstractPrivateSignal0 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface promise = QFutureInterface.createVoidFutureInterface();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect(()->{
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* See QtFuture::connect(Sender *, Signal)
*/
@QtUninvokable
public static @NonNull QFuture connect(QMetaObject.@StrictNonNull AbstractPrivateSignal1 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect(value->{
promise.reportResult(value);
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
*
*/
@QtUninvokable
public static @NonNull QFuture> connect(QMetaObject.@StrictNonNull AbstractPrivateSignal2 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface> promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect((a,b)->{
promise.reportResult(new QPair<>(a,b));
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* Tuple for three arguments.
*/
public static class Tuple3{
Tuple3(A arg1, B arg2, C arg3){
this.arg1 = arg1;
this.arg2 = arg2;
this.arg3 = arg3;
}
public final A arg1;
public final B arg2;
public final C arg3;
}
/**
*
*/
@QtUninvokable
public static @NonNull QFuture> connect(QMetaObject.@StrictNonNull AbstractPrivateSignal3 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface> promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect((a,b,c)->{
promise.reportResult(new Tuple3<>(a,b,c));
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* Tuple for four arguments.
*/
public static class Tuple4 extends Tuple3{
Tuple4(A arg1, B arg2, C arg3, D arg4){
super(arg1, arg2, arg3);
this.arg4 = arg4;
}
public final D arg4;
}
/**
*
*/
@QtUninvokable
public static @NonNull QFuture> connect(QMetaObject.@StrictNonNull AbstractPrivateSignal4 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface> promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect((a,b,c,d)->{
promise.reportResult(new Tuple4<>(a,b,c,d));
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* Tuple for five arguments.
*/
public static class Tuple5 extends Tuple4{
Tuple5(A arg1, B arg2, C arg3, D arg4, E arg5){
super(arg1, arg2, arg3, arg4);
this.arg5 = arg5;
}
public final E arg5;
}
/**
*
*/
@QtUninvokable
public static @NonNull QFuture> connect(QMetaObject.@StrictNonNull AbstractPrivateSignal5 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface> promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect((a,b,c,d,e)->{
promise.reportResult(new Tuple5<>(a,b,c,d,e));
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* Tuple for six arguments.
*/
public static class Tuple6 extends Tuple5{
Tuple6(A arg1, B arg2, C arg3, D arg4, E arg5, F arg6){
super(arg1, arg2, arg3, arg4, arg5);
this.arg6 = arg6;
}
public final F arg6;
}
/**
*
*/
@QtUninvokable
public static @NonNull QFuture> connect(QMetaObject.@StrictNonNull AbstractPrivateSignal6 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface> promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect((a,b,c,d,e,f)->{
promise.reportResult(new Tuple6<>(a,b,c,d,e,f));
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* Tuple for seven arguments.
*/
public static class Tuple7 extends Tuple6{
Tuple7(A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7){
super(arg1, arg2, arg3, arg4, arg5, arg6);
this.arg7 = arg7;
}
public final G arg7;
}
/**
*
*/
@QtUninvokable
public static @NonNull QFuture> connect(QMetaObject.@StrictNonNull AbstractPrivateSignal7 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface> promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect((a,b,c,d,e,f,g)->{
promise.reportResult(new Tuple7<>(a,b,c,d,e,f,g));
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* Tuple for eight arguments.
*/
public static class Tuple8 extends Tuple7{
Tuple8(A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8){
super(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
this.arg8 = arg8;
}
public final H arg8;
}
/**
*
*/
@QtUninvokable
public static @NonNull QFuture> connect(QMetaObject.@StrictNonNull AbstractPrivateSignal8 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface> promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect((a,b,c,d,e,f,g,h)->{
promise.reportResult(new Tuple8<>(a,b,c,d,e,f,g,h));
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* Tuple for nine arguments.
*/
public static class Tuple9 extends Tuple8{
Tuple9(A arg1, B arg2, C arg3, D arg4, E arg5, F arg6, G arg7, H arg8, I arg9){
super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
this.arg9 = arg9;
}
public final I arg9;
}
/**
*
*/
@QtUninvokable
public static @NonNull QFuture> connect(QMetaObject.@StrictNonNull AbstractPrivateSignal9 signal) {
if(signal.containingObject() instanceof QObject) {
QObject sender = (QObject)signal.containingObject();
QFutureInterface> promise = new QFutureInterface<>();
promise.reportStarted();
QMetaObject.Connection[] connections = {null, null};
connections[0] = signal.connect((a,b,c,d,e,f,g,h,i)->{
promise.reportResult(new Tuple9<>(a,b,c,d,e,f,g,h,i));
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
connections[1] = sender.destroyed.connect(()->{
promise.reportCanceled();
promise.reportFinished();
QObject.disconnect(connections[0]);
QObject.disconnect(connections[1]);
});
return promise.future();
}
return null;
}
/**
* See QtFuture::makeExceptionalFuture(QException)
*/
@QtUninvokable
public static @NonNull QFuture makeExceptionalFuture(@StrictNonNull Throwable exception)
{
QFutureInterface promise = QFutureInterface.createVoidFutureInterface();
promise.reportStarted();
promise.reportException(exception);
promise.reportFinished();
return promise.future();
}
/**
* See QtFuture::whenAny(Futures)
*/
@QtUninvokable
public static @NonNull QFuture> whenAny(@NonNull QFuture> @NonNull... futures) {
return whenAny(java.util.Arrays.asList(futures));
}
/**
* See QtFuture::whenAny(Futures)
*/
@QtUninvokable
public static @NonNull QFuture> whenAny(java.util.@NonNull Collection<@NonNull QFuture>> futures) {
if(futures==null || futures.size()==0)
return makeReadyFuture(java.util.Collections.emptyList());
QPromise> promise = new QPromise<>();
promise.start();
java.util.concurrent.atomic.AtomicBoolean ab = new java.util.concurrent.atomic.AtomicBoolean();
for (QFuture> qFuture : futures) {
qFuture.then(f->{
if(ab.compareAndExchange(false, true)) {
promise.addResult(f);
promise.finish();
}
});
}
return promise.future();
}
/**
* See QtFuture::whenAll(Futures)
*/
@QtUninvokable
public static @NonNull QFuture<@NonNull QList<@NonNull QFuture>>> whenAll(@NonNull QFuture> @NonNull... futures) {
return whenAll(java.util.Arrays.asList(futures));
}
/**
* See QtFuture::whenAll(Futures)
*/
@QtUninvokable
public static @NonNull QFuture<@NonNull QList<@NonNull QFuture>>> whenAll(java.util.@NonNull Collection<@NonNull QFuture>> futures) {
if(futures==null || futures.size()==0)
return makeReadyFuture(java.util.Collections.emptyList());
QPromise>> promise = new QPromise<>();
promise.start();
QList> list = new QList<>(QMetaType.Type.QVariant);
list.resize(futures.size());
java.util.concurrent.atomic.AtomicInteger ai = new java.util.concurrent.atomic.AtomicInteger(futures.size());
int i=0;
for (QFuture> qFuture : futures) {
int _i = i++;
qFuture.then(f->{
list.set(_i, f);
if(ai.incrementAndGet()==0) {
promise.addResult(list);
promise.finish();
}
});
}
return promise.future();
}
/**
* Use makeReadyValueFuture() instead
*/
@QtUninvokable
@Deprecated
public static @NonNull QFuture makeReadyFuture(T value){
return makeReadyValueFuture(value);
}
/**
* Use makeReadyRangeFuture() instead
*/
@QtUninvokable
@Deprecated
public static @NonNull QFuture makeReadyFuture(java.util.@NonNull Collection values){
return makeReadyRangeFuture(values);
}
/**
* Use makeReadyVoidFuture() instead
*/
@QtUninvokable
@Deprecated
public static @NonNull QFuture makeReadyFuture(){
return makeReadyVoidFuture();
}
/**
* See QtFuture::makeReadyValueFuture(T)
*/
@QtUninvokable
public static @NonNull QFuture makeReadyValueFuture(T value)
{
QFutureInterface promise = new QFutureInterface<>();
promise.reportStarted();
promise.reportResult(value);
promise.reportFinished();
return promise.future();
}
/**
* See QtFuture::makeReadyRangeFuture(QList<T>)
*/
@QtUninvokable
public static @NonNull QFuture makeReadyRangeFuture(java.util.@NonNull Collection values)
{
QFutureInterface promise = new QFutureInterface<>();
promise.reportStarted();
promise.reportResults(values);
promise.reportFinished();
return promise.future();
}
/**
* See QtFuture::makeReadyRangeFuture(std::initializer_list<T>)
*/
@SafeVarargs
@QtUninvokable
public static @NonNull QFuture makeReadyRangeFuture(T value0, T @NonNull... valuesN)
{
QFutureInterface promise = new QFutureInterface<>();
promise.reportStarted();
promise.reportResults(QList.of(value0, valuesN));
promise.reportFinished();
return promise.future();
}
}