File indexing completed on 2024-05-12 17:08:32

0001 /*
0002  *   SPDX-FileCopyrightText: 2016 Ivan Cukic <ivan.cukic(at)kde.org>
0003  *
0004  *   SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 //
0008 // W A R N I N G
0009 // -------------
0010 //
0011 // This file is not part of the AsynQt API. It exists purely as an
0012 // implementation detail. This header file may change from version to
0013 // version without notice, or even be removed.
0014 //
0015 // We mean it.
0016 //
0017 
0018 namespace AsynQt
0019 {
0020 namespace detail
0021 {
0022 template<typename _Result>
0023 QFuture<_Result> makeCanceledFuture()
0024 {
0025     QFutureInterface<_Result> interface;
0026     auto future = interface.future();
0027 
0028     interface.reportStarted();
0029     interface.reportCanceled();
0030     interface.reportFinished();
0031 
0032     return future;
0033 }
0034 
0035 #ifndef QT_NO_EXCEPTIONS
0036 template<typename _Result>
0037 QFuture<_Result> makeCanceledFuture(const QException &exception)
0038 {
0039     QFutureInterface<_Result> interface;
0040     auto future = interface.future();
0041 
0042     interface.reportStarted();
0043     interface.reportException(exception);
0044     interface.reportFinished();
0045 
0046     return future;
0047 }
0048 #endif
0049 
0050 } // namespace detail
0051 } // namespace AsynQt
0052 
0053 #ifdef ENABLE_EVIL_QFUTURE_HACKS_THAT_SHOULD_BE_IN_QT
0054 
0055 class AsynQt_QFuturePrivacyHack_hasException;
0056 template<>
0057 inline bool QFuture<AsynQt_QFuturePrivacyHack_hasException>::isCanceled() const
0058 {
0059     return d.exceptionStore().hasException();
0060 }
0061 
0062 class AsynQt_QFuturePrivacyHack_throwPossibleException;
0063 template<>
0064 inline void QFuture<AsynQt_QFuturePrivacyHack_throwPossibleException>::cancel()
0065 {
0066     return d.exceptionStore().throwPossibleException();
0067 }
0068 
0069 #endif