22 #ifndef CTKCMDLINEMODULEFUTUREINTERFACE_H 23 #define CTKCMDLINEMODULEFUTUREINTERFACE_H 25 #include <ctkCommandLineModulesCoreExport.h> 29 #include <QFutureInterface> 30 #if (QT_VERSION < 0x50000) 33 #include <QtConcurrent> 34 #include <qresultstore.h> 39 class ctkCmdLineModuleFutureInterfacePrivate;
55 QFutureInterface(
State initialState = NoState);
57 QFutureInterface(
const QFutureInterface &other);
61 static QFutureInterface canceledResult();
63 QFutureInterface& operator=(
const QFutureInterface& other);
67 bool canCancel()
const;
68 void setCanCancel(
bool canCancel);
69 bool canPause()
const;
70 void setCanPause(
bool canPause);
74 inline void reportResults(
const QVector<ctkCmdLineModuleResult> &results,
int beginIndex = -1,
int count = -1);
77 void reportOutputData(
const QByteArray& outputData);
78 void reportErrorData(
const QByteArray& errorData);
84 QByteArray outputData(
int position = 0,
int size = -1)
const;
85 QByteArray errorData(
int position = 0,
int size = -1)
const;
89 friend struct ctkCmdLineModuleFutureWatcherPrivate;
91 #if (QT_VERSION < 0x50000) 92 QtConcurrent::ResultStore<ctkCmdLineModuleResult> &resultStore()
93 {
return static_cast<QtConcurrent::ResultStore<ctkCmdLineModuleResult> &
>(resultStoreBase()); }
94 const QtConcurrent::ResultStore<ctkCmdLineModuleResult> &resultStore()
const 95 {
return static_cast<const QtConcurrent::ResultStore<ctkCmdLineModuleResult> &
>(resultStoreBase()); }
97 QtPrivate::ResultStore<ctkCmdLineModuleResult> &resultStore()
98 {
return static_cast<QtPrivate::ResultStore<ctkCmdLineModuleResult> &
>(resultStoreBase()); }
99 const QtPrivate::ResultStore<ctkCmdLineModuleResult> &resultStore()
const 100 {
return static_cast<const QtPrivate::ResultStore<ctkCmdLineModuleResult> &
>(resultStoreBase()); }
103 ctkCmdLineModuleFutureInterfacePrivate* d;
108 QMutexLocker locker(mutex());
109 if (this->queryState(Canceled) || this->queryState(Finished)) {
113 #if (QT_VERSION < 0x50000) 114 QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
116 QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
119 if (store.filterMode()) {
120 const int resultCountBefore = store.count();
121 store.addResult(index, result);
122 this->reportResultsReady(resultCountBefore, resultCountBefore + store.count());
124 const int insertIndex = store.addResult(index, result);
125 this->reportResultsReady(insertIndex, insertIndex + 1);
131 reportResult(&result, index);
136 QMutexLocker locker(mutex());
137 if (this->queryState(Canceled) || this->queryState(Finished)) {
141 #if (QT_VERSION < 0x50000) 142 QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
144 QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
147 if (store.filterMode()) {
148 const int resultCountBefore = store.count();
149 store.addResults(beginIndex, &_results, count);
150 this->reportResultsReady(resultCountBefore, store.count());
152 const int insertIndex = store.addResults(beginIndex, &_results, count);
153 this->reportResultsReady(insertIndex, insertIndex + _results.count());
160 reportResult(result);
161 QFutureInterfaceBase::reportFinished();
166 QMutexLocker lock(mutex());
167 return resultStore().resultAt(index).value();
172 QMutexLocker lock(mutex());
173 return resultStore().resultAt(index).pointer();
178 if (this->isCanceled()) {
179 exceptionStore().throwPossibleException();
182 QFutureInterfaceBase::waitForResult(-1);
185 QMutexLocker lock(mutex());
187 #if (QT_VERSION <= 0x50000) 188 QtConcurrent::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
190 QtPrivate::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
192 while (it != resultStore().end()) {
193 res.append(it.value());
202 #endif // CTKCMDLINEMODULEFUTUREINTERFACE_H Describes a reported result of a command line module.
void reportResult(const ctkCmdLineModuleResult *result, int index=-1)
void reportResults(const QVector< ctkCmdLineModuleResult > &results, int beginIndex=-1, int count=-1)
const ctkCmdLineModuleResult * resultPointer(int index) const
const ctkCmdLineModuleResult & resultReference(int index) const
QList< ctkCmdLineModuleResult > results()
QFuture sub-class for enhanced communication with running modules.Please see the QFuture documentatio...
QFutureInterface< ctkCmdLineModuleResult > ctkCmdLineModuleFutureInterface
A QFutureInterface specialization.
void reportFinished(const ctkCmdLineModuleResult *result=0)