6.0.0-rc4Source

QFutureInterfaceBase Class

The QFutureInterfaceBase class is the non-template base of QFutureInterface. More…

Header#include <QFutureInterfaceBase>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Inherited byQFutureInterface

List of all members, including inherited members

Public Types

enumState

Public Functions

QFutureInterfaceBase(State initialState = NoState)
QFutureInterfaceBase(const QFutureInterfaceBase &other)
QFutureInterfaceBase(QFutureInterfaceBase &&other)
QFutureInterfaceBase &operator=(const QFutureInterfaceBase &other)
QFutureInterfaceBase &operator=(QFutureInterfaceBase &&other)
virtual ~QFutureInterfaceBase()
boolisValid() const
boolisStarted() const
boolisRunning() const
boolisFinished() const
boolisCanceled() const
boolisSuspending() const
boolisSuspended() const
boolisPaused() const
boolisThrottled() const
boolhasException() const
boolqueryState(State state) const
voidreportStarted()
voidreportFinished()
voidreportCanceled()
voidreportException(std::exception_ptr exception)
voidreportException(const QException &exception)
voidreportSuspended() const
voidcancel()
voidcancelChain()
voidsetSuspended(bool suspend)
voidtoggleSuspended()
voidsetPaused(bool paused)
voidtogglePaused()
voidsetThrottled(bool enable)
voidwaitForFinished() const
voidwaitForResult(int resultIndex) const
voidwaitForResume() const
intresultCount() const
boolisResultReadyAt(int index) const
voidsetExpectedResultCount(int resultCount)
intexpectedResultCount() const
intprogressMinimum() const
intprogressMaximum() const
intprogressValue() const
QStringprogressText() const
voidsetProgressRange(int minimum, int maximum)
voidsetProgressValue(int progressValue)
voidsetProgressValueAndText(int progressValue, const QString &progressText)
voidsetThreadPool(QThreadPool *pool)
QThreadPool *threadPool() const
booloperator==(const QFutureInterfaceBase &other) const
booloperator!=(const QFutureInterfaceBase &other) const

Detailed Description

It holds the state that a QFuture and the QPromise or QFutureInterface that produces it share: the state flags, the progress, the exception and the bookkeeping of the results. The state is reference counted, so copies of the object refer to the same computation, and every function is thread-safe.

There is rarely a reason to use the class directly; see QFutureInterface, QPromise and QFuture.

See also QFutureInterface, QFuture and QPromise.

Differences from Qt

There is no mutex(), no setRunnable(), no setFilterMode() and no reportResultsReady(); the results are stored by the functions of QFutureInterface. Waiting functions are const, and progress changes are not limited to 25 per second. Results that arrive out of order are available through isResultReadyAt() at once, but resultCount() and the notification of a QFutureWatcher wait for the results before them.

Member Type Documentation

enum QFutureInterfaceBase::State

This enum describes the state of a computation. A future is in a combination of these.

ConstantDescription
QFutureInterfaceBase::NoStateNo flag is set; the state of a default-constructed interface.
QFutureInterfaceBase::RunningThe computation has been started and has not finished.
QFutureInterfaceBase::StartedThe computation has been started. The flag stays set.
QFutureInterfaceBase::FinishedThe computation has finished.
QFutureInterfaceBase::CanceledThe computation was canceled, or ended with an exception.
QFutureInterfaceBase::SuspendingA suspension was requested, and the computation has not acted on it yet.
QFutureInterfaceBase::SuspendedThe computation has acted on a suspension request and waits to be resumed.
QFutureInterfaceBase::ThrottledThe consumer cannot keep up with the results and asks the computation to slow down.
QFutureInterfaceBase::PendingThe computation has not started, but is expected to; waiting for it blocks.

Member Function Documentation

QFutureInterfaceBase::QFutureInterfaceBase(State initialState = NoState)

Constructs an interface in the state initialState.

QFutureInterfaceBase::QFutureInterfaceBase(const QFutureInterfaceBase &other)

Constructs an interface that shares its state with other.

QFutureInterfaceBase::QFutureInterfaceBase(QFutureInterfaceBase &&other)

Moves the state of other into this interface. other can only be destroyed or assigned to afterwards.

[virtual] QFutureInterfaceBase::~QFutureInterfaceBase()

Destroys the interface. The results are freed when the last interface or future that shares the state is destroyed.

void QFutureInterfaceBase::cancel()

Cancels the computation. The computation is not stopped: it has to look at isCanceled() and finish. Threads that are waiting for results or for a suspension are woken up.

See also cancelChain() and isCanceled().

void QFutureInterfaceBase::cancelChain()

Cancels the computation and the computations that it continues, that is the futures that this one was created from with QFuture::then() and its relatives, as long as they still exist.

See also cancel().

int QFutureInterfaceBase::expectedResultCount() const

Returns the number of results that the computation announced, or 0.

See also setExpectedResultCount().

bool QFutureInterfaceBase::hasException() const

Returns true if the computation ended with an exception.

See also reportException().

bool QFutureInterfaceBase::isCanceled() const

Returns true if the computation was canceled or ended with an exception.

See also cancel() and reportException().

bool QFutureInterfaceBase::isFinished() const

Returns true if the computation has finished.

See also reportFinished().

bool QFutureInterfaceBase::isPaused() const

Returns true if the computation is suspended or about to be. It is the same as isSuspending() || isSuspended().

bool QFutureInterfaceBase::isResultReadyAt(int index) const

Returns true if the result at index is available.

See also waitForResult() and resultCount().

bool QFutureInterfaceBase::isRunning() const

Returns true if the computation has started and not finished.

See also isStarted() and isFinished().

bool QFutureInterfaceBase::isStarted() const

Returns true if the computation has been started. The answer stays true after it has finished.

See also reportStarted() and isRunning().

bool QFutureInterfaceBase::isSuspended() const

Returns true if the computation acted on a suspension request and waits to be resumed.

See also isSuspending() and waitForResume().

bool QFutureInterfaceBase::isSuspending() const

Returns true if a suspension was requested and the computation has not acted on it yet.

See also isSuspended() and setSuspended().

bool QFutureInterfaceBase::isThrottled() const

Returns true if the consumer asked the computation to slow down because it has more results than it can handle.

See also setThrottled().

bool QFutureInterfaceBase::isValid() const

Returns true if the interface refers to a computation; returns false for the interface of a default-constructed QFuture and for an interface that was moved from.

bool QFutureInterfaceBase::operator!=(const QFutureInterfaceBase &other) const

Returns true if other does not refer to the same computation as this interface.

QFutureInterfaceBase & QFutureInterfaceBase::operator=(const QFutureInterfaceBase &other)

Shares the state of other with this interface and returns a reference to it.

QFutureInterfaceBase & QFutureInterfaceBase::operator=(QFutureInterfaceBase &&other)

Moves the state of other into this interface and returns a reference to it.

bool QFutureInterfaceBase::operator==(const QFutureInterfaceBase &other) const

Returns true if other refers to the same computation as this interface.

int QFutureInterfaceBase::progressMaximum() const

Returns the highest progress value. It is 0 unless setProgressRange() was called.

See also progressMinimum() and progressValue().

int QFutureInterfaceBase::progressMinimum() const

Returns the lowest progress value. It is 0 unless setProgressRange() was called.

See also progressMaximum() and progressValue().

QString QFutureInterfaceBase::progressText() const

Returns the current progress text, which is empty unless setProgressValueAndText() was called.

See also progressValue().

int QFutureInterfaceBase::progressValue() const

Returns the current progress value.

See also setProgressValue() and progressText().

bool QFutureInterfaceBase::queryState(State state) const

Returns true if at least one of the flags in state is set.

void QFutureInterfaceBase::reportCanceled()

Cancels the computation. This is the same as cancel().

void QFutureInterfaceBase::reportException(std::exception_ptr exception)

Stores exception and cancels the computation. Waiting for the result or for the end of the computation throws it. Does nothing if the computation has finished or was canceled, or if an exception was stored already.

See also hasException().

void QFutureInterfaceBase::reportException(const QException &exception)

This is an overloaded function.

Stores what exception.clone()->raise() throws, so that a class derived from QException that reimplements raise() and clone() keeps its type.

void QFutureInterfaceBase::reportFinished()

Reports that the computation has finished, wakes the threads that wait for it and runs the continuation that was attached to the future, in the calling thread. Does nothing if the computation has finished already.

See also reportStarted() and QFuture::then().

void QFutureInterfaceBase::reportStarted()

Reports that the computation has started. Does nothing if it has started or finished already.

See also reportFinished().

void QFutureInterfaceBase::reportSuspended() const

Reports that the computation acted on a suspension request. Does nothing unless a suspension was requested. waitForResume() calls it.

See also waitForResume() and isSuspended().

int QFutureInterfaceBase::resultCount() const

Returns the number of results that are available from the first one on, without a gap.

See also isResultReadyAt().

void QFutureInterfaceBase::setExpectedResultCount(int resultCount)

Sets the number of results that the computation is going to produce to resultCount. The number is informative.

See also expectedResultCount().

void QFutureInterfaceBase::setPaused(bool paused)

Suspends the computation if paused is true, and resumes it otherwise. This is the same as setSuspended().

void QFutureInterfaceBase::setProgressRange(int minimum, int maximum)

Sets the range of progress values to minimum to maximum.

See also setProgressValue().

void QFutureInterfaceBase::setProgressValue(int progressValue)

Sets the progress value to progressValue and clears the progress text.

See also setProgressValueAndText() and setProgressRange().

void QFutureInterfaceBase::setProgressValueAndText(int progressValue, const QString &progressText)

Sets the progress value to progressValue and the progress text to progressText. Does nothing if the computation is finished or canceled, or if neither changes.

See also setProgressValue().

void QFutureInterfaceBase::setSuspended(bool suspend)

Asks the computation to suspend, if suspend is true, or to resume otherwise. A computation that is suspended acts on the request in waitForResume(). Does nothing if the computation has finished.

See also isSuspending() and isSuspended().

void QFutureInterfaceBase::setThreadPool(QThreadPool *pool)

Sets the thread pool that the computation runs in to pool. Continuations that inherit the launch policy of the computation run in that pool. The pool must outlive the future.

See also threadPool() and QtFuture::Launch.

void QFutureInterfaceBase::setThrottled(bool enable)

Tells the computation, if enable is true, that the consumer has more results than it can handle, or that it caught up otherwise. QFutureWatcher does so according to its pending results limit. The flag is informative: waitForResume() does not wait for it.

See also isThrottled() and QFutureWatcher::setPendingResultsLimit().

QThreadPool * QFutureInterfaceBase::threadPool() const

Returns the thread pool set with setThreadPool(), or nullptr.

void QFutureInterfaceBase::togglePaused()

Suspends the computation if it is not suspended, and resumes it otherwise. This is the same as toggleSuspended().

void QFutureInterfaceBase::toggleSuspended()

Suspends the computation if it is not suspended, and resumes it otherwise.

See also setSuspended().

void QFutureInterfaceBase::waitForFinished() const

Waits until the computation has finished, and throws the exception that it ended with, if any. Returns at once for a computation that is not running or pending.

See also isFinished() and reportFinished().

void QFutureInterfaceBase::waitForResult(int resultIndex) const

Waits until the result at resultIndex is available, or the computation has finished or ended with an exception, which this function throws.

See also isResultReadyAt().

void QFutureInterfaceBase::waitForResume() const

Blocks while a suspension is requested, until the computation is resumed or canceled. The computation that calls it becomes suspended, which isSuspended() reports. Returns at once otherwise. QPromise::suspendIfRequested() calls it.

See also reportSuspended() and setSuspended().