42 #ifndef QFUTUREINTERFACE_H 43 #define QFUTUREINTERFACE_H 45 #include <QtCore/qglobal.h> 46 #include <QtCore/qrunnable.h> 50 #include <QtCore/qmutex.h> 51 #include <QtCore/qtconcurrentexception.h> 52 #include <QtCore/qtconcurrentresultstore.h> 59 template <
typename T>
class QFuture;
83 void reportFinished();
84 void reportCanceled();
85 #ifndef QT_NO_EXCEPTIONS 88 void reportResultsReady(
int beginIndex,
int endIndex);
91 void setFilterMode(
bool enable);
92 void setProgressRange(
int minimum,
int maximum);
93 int progressMinimum()
const;
94 int progressMaximum()
const;
95 bool isProgressUpdateNeeded()
const;
96 void setProgressValue(
int progressValue);
97 int progressValue()
const;
98 void setProgressValueAndText(
int progressValue,
const QString &progressText);
101 void setExpectedResultCount(
int resultCount);
102 int expectedResultCount();
103 int resultCount()
const;
105 bool queryState(
State state)
const;
106 bool isRunning()
const;
107 bool isStarted()
const;
108 bool isCanceled()
const;
109 bool isFinished()
const;
110 bool isPaused()
const;
111 bool isThrottled()
const;
112 bool isResultReadyAt(
int index)
const;
115 void setPaused(
bool paused);
117 void setThrottled(
bool enable);
119 void waitForFinished();
120 bool waitForNextResult();
121 void waitForResult(
int resultIndex);
122 void waitForResume();
126 QtConcurrent::ResultStoreBase &resultStoreBase();
127 const QtConcurrent::ResultStoreBase &resultStoreBase()
const;
134 bool referenceCountIsOne()
const;
147 template <
typename T>
159 if (referenceCountIsOne())
160 resultStore().clear();
168 if (referenceCountIsOne())
169 resultStore().clear();
176 inline void reportResult(
const T *result,
int index = -1);
177 inline void reportResult(
const T &result,
int index = -1);
178 inline void reportResults(
const QVector<T> &results,
int beginIndex = -1,
int count = -1);
179 inline void reportFinished(
const T *result = 0);
181 inline const T &resultReference(
int index)
const;
182 inline const T *resultPointer(
int index)
const;
186 {
return static_cast<QtConcurrent::ResultStore<T> &
>(resultStoreBase()); }
188 {
return static_cast<const QtConcurrent::ResultStore<T> &
>(resultStoreBase()); }
191 template <
typename T>
195 if (this->queryState(Canceled) || this->queryState(Finished)) {
199 QtConcurrent::ResultStore<T> &
store = resultStore();
202 if (store.filterMode()) {
203 const int resultCountBefore = store.count();
204 store.addResult(index, result);
205 this->reportResultsReady(resultCountBefore, resultCountBefore + store.count());
207 const int insertIndex = store.addResult(index, result);
208 this->reportResultsReady(insertIndex, insertIndex + 1);
212 template <
typename T>
215 reportResult(&result, index);
218 template <
typename T>
222 if (this->queryState(Canceled) || this->queryState(Finished)) {
226 QtConcurrent::ResultStore<T> &
store = resultStore();
228 if (store.filterMode()) {
229 const int resultCountBefore = store.count();
230 store.addResults(beginIndex, &_results, count);
231 this->reportResultsReady(resultCountBefore, store.count());
233 const int insertIndex = store.addResults(beginIndex, &_results, count);
234 this->reportResultsReady(insertIndex, insertIndex + _results.
count());
238 template <
typename T>
242 reportResult(result);
246 template <
typename T>
250 return resultStore().resultAt(index).value();
253 template <
typename T>
257 return resultStore().resultAt(index).pointer();
260 template <
typename T>
263 if (this->isCanceled()) {
264 exceptionStore().throwPossibleException();
272 QtConcurrent::ResultIterator<T>
it = resultStore().begin();
273 while (it != resultStore().
end()) {
303 void reportResult(
const void *,
int) { }
311 #endif // QT_NO_CONCURRENT 313 #endif // QFUTUREINTERFACE_H
bool operator==(const QFutureInterfaceBase &other) const
#define QT_END_NAMESPACE
This macro expands to.
The QMutex class provides access serialization between threads.
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
void reportResult(const T *result, int index=-1)
bool operator!=(const QFutureInterfaceBase &other) const
QFutureInterfaceBasePrivate * d
The QString class provides a Unicode character string.
const T & resultReference(int index) const
The QVector class is a template class that provides a dynamic array.
The QRunnable class is the base class for all runnable objects.
static QFutureInterface canceledResult()
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QFutureInterface(State initialState=NoState)
The State element defines configurations of objects and properties.
The QFuture class represents the result of an asynchronous computation.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
const QtConcurrent::ResultStore< T > & resultStore() const
The Exception class provides a base class for exceptions that can transferred across threads...
QtConcurrent::ResultStore< T > & resultStore()
static QReadWriteLock lock
QFutureInterfaceBase & operator=(const QFutureInterfaceBase &other)
void waitForResult(int resultIndex)
QFutureInterface(const QFutureInterface &other)
QFutureInterface & operator=(const QFutureInterface &other)
static const KeyPair *const end
void reportResults(const QVector< T > &results, int beginIndex=-1, int count=-1)
const T * resultPointer(int index) const
The QList class is a template class that provides lists.