22 #ifndef CTKCMDLINEMODULEFUTUREINTERFACE_H
23 #define CTKCMDLINEMODULEFUTUREINTERFACE_H
25 #include <ctkCommandLineModulesCoreExport.h>
29 #include <QFutureInterface>
30 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
33 #include <QtConcurrent>
34 #include <qresultstore.h>
39 class ctkCmdLineModuleFutureInterfacePrivate;
63 QFutureInterface&
operator=(
const QFutureInterface& other);
74 inline void reportResults(
const QVector<ctkCmdLineModuleResult> &results,
int beginIndex = -1,
int count = -1);
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 < QT_VERSION_CHECK(5, 0, 0))
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()); }
96 #elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
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()); }
102 QtPrivate::ResultStoreBase &resultStore()
103 {
return static_cast<QtPrivate::ResultStoreBase &
>(resultStoreBase()); }
104 const QtPrivate::ResultStoreBase &resultStore()
const
105 {
return static_cast<const QtPrivate::ResultStoreBase &
>(resultStoreBase()); }
108 ctkCmdLineModuleFutureInterfacePrivate* d;
113 QMutexLocker locker(mutex());
114 if (this->queryState(Canceled) || this->queryState(Finished)) {
118 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
119 QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
120 #elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
121 QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
123 QtPrivate::ResultStoreBase &store = resultStore();
126 if (store.filterMode()) {
127 const int resultCountBefore = store.count();
128 store.addResult(index, result);
129 this->reportResultsReady(resultCountBefore, resultCountBefore + store.count());
131 const int insertIndex = store.addResult(index, result);
132 this->reportResultsReady(insertIndex, insertIndex + 1);
138 reportResult(&result, index);
143 QMutexLocker locker(mutex());
144 if (this->queryState(Canceled) || this->queryState(Finished)) {
148 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
149 QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
150 #elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
151 QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
153 QtPrivate::ResultStoreBase &store = resultStore();
156 if (store.filterMode()) {
157 const int resultCountBefore = store.count();
158 store.addResults(beginIndex, &_results, count);
159 this->reportResultsReady(resultCountBefore, store.count());
161 const int insertIndex = store.addResults(beginIndex, &_results, count);
162 this->reportResultsReady(insertIndex, insertIndex + _results.count());
169 reportResult(result);
170 QFutureInterfaceBase::reportFinished();
175 QMutexLocker lock(mutex());
176 #if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
177 return resultStore().resultAt(index).value();
185 QMutexLocker lock(mutex());
186 #if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
187 return resultStore().resultAt(index).pointer();
195 if (this->isCanceled()) {
196 exceptionStore().throwPossibleException();
199 QFutureInterfaceBase::waitForResult(-1);
202 QMutexLocker lock(mutex());
204 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
205 QtConcurrent::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
206 #elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
207 QtPrivate::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
209 QtPrivate::ResultIteratorBase it = resultStore().begin();
211 while (it != resultStore().end()) {
212 #if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
213 res.append(it.value());
A QFutureInterface specialization.
void reportFinished(const ctkCmdLineModuleResult *result=0)
QFutureInterface(State initialState=NoState)
QByteArray outputData(int position=0, int size=-1) const
void setCanCancel(bool canCancel)
void setCanPause(bool canPause)
void reportErrorData(const QByteArray &errorData)
void reportOutputData(const QByteArray &outputData)
QByteArray errorData(int position=0, int size=-1) const
QFutureInterface & operator=(const QFutureInterface &other)
QFutureInterface(const QFutureInterface &other)
void reportResult(const ctkCmdLineModuleResult *result, int index=-1)
const ctkCmdLineModuleResult * resultPointer(int index) const
static QFutureInterface canceledResult()
const ctkCmdLineModuleResult & resultReference(int index) const
void reportResults(const QVector< ctkCmdLineModuleResult > &results, int beginIndex=-1, int count=-1)
QList< ctkCmdLineModuleResult > results()
QFuture sub-class for enhanced communication with running modules.
Describes a reported result of a command line module.
QFutureInterface< ctkCmdLineModuleResult > ctkCmdLineModuleFutureInterface