Go to
the documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QFUTRUESYNCHRONIZER_H
00043 #define QFUTRUESYNCHRONIZER_H
00044
00045 #include <QtCore/qfuture.h>
00046
00047 #ifndef QT_NO_CONCURRENT
00048
00049 QT_BEGIN_HEADER
00050 QT_BEGIN_NAMESPACE
00051
00052 QT_MODULE(Core)
00053
00054 template <typename T>
00055 class QFutureSynchronizer
00056 {
00057 Q_DISABLE_COPY(QFutureSynchronizer)
00058
00059 public:
00060 QFutureSynchronizer() : m_cancelOnWait(false) { }
00061 explicit QFutureSynchronizer(const QFuture<T> &future)
00062 : m_cancelOnWait(false)
00063 { addFuture(future); }
00064 ~QFutureSynchronizer() { waitForFinished(); }
00065
00066 void setFuture(const QFuture<T> &future)
00067 {
00068 waitForFinished();
00069 m_futures.clear();
00070 addFuture(future);
00071 }
00072
00073 void addFuture(const QFuture<T> &future)
00074 {
00075 m_futures.append(future);
00076 }
00077
00078 void waitForFinished()
00079 {
00080 if (m_cancelOnWait) {
00081 for (int i = 0; i < m_futures.count(); ++i) {
00082 m_futures[i].cancel();
00083 }
00084 }
00085
00086 for (int i = 0; i < m_futures.count(); ++i) {
00087 m_futures[i].waitForFinished();
00088 }
00089 }
00090
00091 void clearFutures()
00092 {
00093 m_futures.clear();
00094 }
00095
00096 QList<QFuture<T> > futures() const
00097 {
00098 return m_futures;
00099 }
00100
00101 void setCancelOnWait(bool enabled)
00102 {
00103 m_cancelOnWait = enabled;
00104 }
00105
00106 bool cancelOnWait() const
00107 {
00108 return m_cancelOnWait;
00109 }
00110
00111 protected:
00112 QList<QFuture<T> > m_futures;
00113 bool m_cancelOnWait;
00114 };
00115
00116 QT_END_NAMESPACE
00117 QT_END_HEADER
00118
00119 #endif // QT_NO_CONCURRENT
00120
00121 #endif // QFUTRUESYNCHRONIZER_H