diff options
Diffstat (limited to 'async/src/future.h')
-rw-r--r-- | async/src/future.h | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/async/src/future.h b/async/src/future.h index ff199ef..b2b723e 100644 --- a/async/src/future.h +++ b/async/src/future.h | |||
@@ -18,6 +18,8 @@ | |||
18 | #ifndef FUTURE_H | 18 | #ifndef FUTURE_H |
19 | #define FUTURE_H | 19 | #define FUTURE_H |
20 | 20 | ||
21 | #include "kasync_export.h" | ||
22 | |||
21 | class QEventLoop; | 23 | class QEventLoop; |
22 | 24 | ||
23 | #include <type_traits> | 25 | #include <type_traits> |
@@ -27,7 +29,7 @@ class QEventLoop; | |||
27 | #include <QVector> | 29 | #include <QVector> |
28 | #include <QEventLoop> | 30 | #include <QEventLoop> |
29 | 31 | ||
30 | namespace Async { | 32 | namespace KAsync { |
31 | 33 | ||
32 | class FutureWatcherBase; | 34 | class FutureWatcherBase; |
33 | template<typename T> | 35 | template<typename T> |
@@ -40,9 +42,9 @@ class ExecutorBase; | |||
40 | typedef QSharedPointer<Execution> ExecutionPtr; | 42 | typedef QSharedPointer<Execution> ExecutionPtr; |
41 | } // namespace Private | 43 | } // namespace Private |
42 | 44 | ||
43 | class FutureBase | 45 | class KASYNC_EXPORT FutureBase |
44 | { | 46 | { |
45 | friend class Async::Private::Execution; | 47 | friend class KAsync::Private::Execution; |
46 | friend class FutureWatcherBase; | 48 | friend class FutureWatcherBase; |
47 | 49 | ||
48 | public: | 50 | public: |
@@ -61,7 +63,7 @@ protected: | |||
61 | class PrivateBase : public QSharedData | 63 | class PrivateBase : public QSharedData |
62 | { | 64 | { |
63 | public: | 65 | public: |
64 | PrivateBase(const Async::Private::ExecutionPtr &execution); | 66 | PrivateBase(const KAsync::Private::ExecutionPtr &execution); |
65 | virtual ~PrivateBase(); | 67 | virtual ~PrivateBase(); |
66 | 68 | ||
67 | void releaseExecution(); | 69 | void releaseExecution(); |
@@ -72,14 +74,14 @@ protected: | |||
72 | 74 | ||
73 | QVector<QPointer<FutureWatcherBase>> watchers; | 75 | QVector<QPointer<FutureWatcherBase>> watchers; |
74 | private: | 76 | private: |
75 | QWeakPointer<Async::Private::Execution> mExecution; | 77 | QWeakPointer<KAsync::Private::Execution> mExecution; |
76 | }; | 78 | }; |
77 | 79 | ||
78 | FutureBase(); | 80 | FutureBase(); |
79 | FutureBase(FutureBase::PrivateBase *dd); | 81 | FutureBase(FutureBase::PrivateBase *dd); |
80 | FutureBase(const FutureBase &other); | 82 | FutureBase(const FutureBase &other); |
81 | 83 | ||
82 | void addWatcher(Async::FutureWatcherBase *watcher); | 84 | void addWatcher(KAsync::FutureWatcherBase *watcher); |
83 | void releaseExecution(); | 85 | void releaseExecution(); |
84 | 86 | ||
85 | protected: | 87 | protected: |
@@ -105,14 +107,14 @@ public: | |||
105 | } | 107 | } |
106 | FutureWatcher<T> watcher; | 108 | FutureWatcher<T> watcher; |
107 | QEventLoop eventLoop; | 109 | QEventLoop eventLoop; |
108 | QObject::connect(&watcher, &Async::FutureWatcher<T>::futureReady, | 110 | QObject::connect(&watcher, &KAsync::FutureWatcher<T>::futureReady, |
109 | &eventLoop, &QEventLoop::quit); | 111 | &eventLoop, &QEventLoop::quit); |
110 | watcher.setFuture(*static_cast<const Async::Future<T>*>(this)); | 112 | watcher.setFuture(*static_cast<const KAsync::Future<T>*>(this)); |
111 | eventLoop.exec(); | 113 | eventLoop.exec(); |
112 | } | 114 | } |
113 | 115 | ||
114 | protected: | 116 | protected: |
115 | FutureGeneric(const Async::Private::ExecutionPtr &execution) | 117 | FutureGeneric(const KAsync::Private::ExecutionPtr &execution) |
116 | : FutureBase(new Private(execution)) | 118 | : FutureBase(new Private(execution)) |
117 | {} | 119 | {} |
118 | 120 | ||
@@ -124,7 +126,7 @@ protected: | |||
124 | class Private : public FutureBase::PrivateBase | 126 | class Private : public FutureBase::PrivateBase |
125 | { | 127 | { |
126 | public: | 128 | public: |
127 | Private(const Async::Private::ExecutionPtr &execution) | 129 | Private(const KAsync::Private::ExecutionPtr &execution) |
128 | : FutureBase::PrivateBase(execution) | 130 | : FutureBase::PrivateBase(execution) |
129 | {} | 131 | {} |
130 | 132 | ||
@@ -137,14 +139,14 @@ protected: | |||
137 | template<typename T> | 139 | template<typename T> |
138 | class Future : public FutureGeneric<T> | 140 | class Future : public FutureGeneric<T> |
139 | { | 141 | { |
140 | friend class Async::Private::ExecutorBase; | 142 | friend class KAsync::Private::ExecutorBase; |
141 | 143 | ||
142 | template<typename T_> | 144 | template<typename T_> |
143 | friend class Async::FutureWatcher; | 145 | friend class KAsync::FutureWatcher; |
144 | 146 | ||
145 | public: | 147 | public: |
146 | Future() | 148 | Future() |
147 | : FutureGeneric<T>(Async::Private::ExecutionPtr()) | 149 | : FutureGeneric<T>(KAsync::Private::ExecutionPtr()) |
148 | {} | 150 | {} |
149 | 151 | ||
150 | Future(const Future<T> &other) | 152 | Future(const Future<T> &other) |
@@ -162,7 +164,7 @@ public: | |||
162 | } | 164 | } |
163 | 165 | ||
164 | protected: | 166 | protected: |
165 | Future(const Async::Private::ExecutionPtr &execution) | 167 | Future(const KAsync::Private::ExecutionPtr &execution) |
166 | : FutureGeneric<T>(execution) | 168 | : FutureGeneric<T>(execution) |
167 | {} | 169 | {} |
168 | 170 | ||
@@ -171,11 +173,11 @@ protected: | |||
171 | template<> | 173 | template<> |
172 | class Future<void> : public FutureGeneric<void> | 174 | class Future<void> : public FutureGeneric<void> |
173 | { | 175 | { |
174 | friend class Async::Private::ExecutorBase; | 176 | friend class KAsync::Private::ExecutorBase; |
175 | 177 | ||
176 | public: | 178 | public: |
177 | Future() | 179 | Future() |
178 | : FutureGeneric<void>(Async::Private::ExecutionPtr()) | 180 | : FutureGeneric<void>(KAsync::Private::ExecutionPtr()) |
179 | {} | 181 | {} |
180 | 182 | ||
181 | Future(const Future<void> &other) | 183 | Future(const Future<void> &other) |
@@ -183,7 +185,7 @@ public: | |||
183 | {} | 185 | {} |
184 | 186 | ||
185 | protected: | 187 | protected: |
186 | Future(const Async::Private::ExecutionPtr &execution) | 188 | Future(const KAsync::Private::ExecutionPtr &execution) |
187 | : FutureGeneric<void>(execution) | 189 | : FutureGeneric<void>(execution) |
188 | {} | 190 | {} |
189 | }; | 191 | }; |
@@ -192,7 +194,7 @@ protected: | |||
192 | 194 | ||
193 | 195 | ||
194 | 196 | ||
195 | class FutureWatcherBase : public QObject | 197 | class KASYNC_EXPORT FutureWatcherBase : public QObject |
196 | { | 198 | { |
197 | Q_OBJECT | 199 | Q_OBJECT |
198 | 200 | ||
@@ -209,12 +211,12 @@ protected: | |||
209 | void futureReadyCallback(); | 211 | void futureReadyCallback(); |
210 | void futureProgressCallback(qreal progress); | 212 | void futureProgressCallback(qreal progress); |
211 | 213 | ||
212 | void setFutureImpl(const Async::FutureBase &future); | 214 | void setFutureImpl(const KAsync::FutureBase &future); |
213 | 215 | ||
214 | protected: | 216 | protected: |
215 | class Private { | 217 | class Private { |
216 | public: | 218 | public: |
217 | Async::FutureBase future; | 219 | KAsync::FutureBase future; |
218 | }; | 220 | }; |
219 | 221 | ||
220 | Private * const d; | 222 | Private * const d; |
@@ -226,7 +228,7 @@ private: | |||
226 | template<typename T> | 228 | template<typename T> |
227 | class FutureWatcher : public FutureWatcherBase | 229 | class FutureWatcher : public FutureWatcherBase |
228 | { | 230 | { |
229 | friend class Async::FutureGeneric<T>; | 231 | friend class KAsync::FutureGeneric<T>; |
230 | 232 | ||
231 | public: | 233 | public: |
232 | FutureWatcher(QObject *parent = nullptr) | 234 | FutureWatcher(QObject *parent = nullptr) |
@@ -236,14 +238,14 @@ public: | |||
236 | ~FutureWatcher() | 238 | ~FutureWatcher() |
237 | {} | 239 | {} |
238 | 240 | ||
239 | void setFuture(const Async::Future<T> &future) | 241 | void setFuture(const KAsync::Future<T> &future) |
240 | { | 242 | { |
241 | setFutureImpl(*static_cast<const Async::FutureBase*>(&future)); | 243 | setFutureImpl(*static_cast<const KAsync::FutureBase*>(&future)); |
242 | } | 244 | } |
243 | 245 | ||
244 | Async::Future<T> future() const | 246 | KAsync::Future<T> future() const |
245 | { | 247 | { |
246 | return *static_cast<Async::Future<T>*>(&d->future); | 248 | return *static_cast<KAsync::Future<T>*>(&d->future); |
247 | } | 249 | } |
248 | 250 | ||
249 | private: | 251 | private: |