File indexing completed on 2024-05-05 05:37:15
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 #ifndef ASYNQT_CONS_CANCELED_FUTURE_H 0008 #define ASYNQT_CONS_CANCELED_FUTURE_H 0009 0010 #include <QFuture> 0011 #include <QFutureInterface> 0012 #include <QObject> 0013 #include <QTimer> 0014 0015 #ifndef QT_NO_EXCEPTIONS 0016 #include <QException> 0017 #endif 0018 0019 #include "../private/basic/canceledfuture_p.h" 0020 0021 namespace AsynQt 0022 { 0023 /** 0024 * Creates a canceled future. 0025 */ 0026 template<typename _Result = void> 0027 QFuture<_Result> makeCanceledFuture() 0028 { 0029 // No need to decay the type, expecting the user not to try 0030 // and make a future of ref-to-type or anything that funny 0031 return detail::makeCanceledFuture<_Result>(); 0032 } 0033 0034 #ifndef QT_NO_EXCEPTIONS 0035 /** 0036 * Creates a canceled future. 0037 */ 0038 template<typename _Result = void> 0039 QFuture<_Result> makeCanceledFuture(const QException &exception) 0040 { 0041 // No need to decay the type, expecting the user not to try 0042 // and make a future of ref-to-type or anything that funny 0043 return detail::makeCanceledFuture<_Result>(exception); 0044 } 0045 0046 #ifdef ENABLE_EVIL_QFUTURE_HACKS_THAT_SHOULD_BE_IN_QT 0047 0048 namespace evil 0049 { 0050 // TODO: Remove these 0051 0052 template<typename T> 0053 bool hasException(const QFuture<T> &future) 0054 { 0055 return reinterpret_cast<const QFuture<AsynQt_QFuturePrivacyHack_hasException> *>(&future)->isCanceled(); 0056 } 0057 0058 template<typename T> 0059 void throwPossibleException(QFuture<T> &future) 0060 { 0061 reinterpret_cast<QFuture<AsynQt_QFuturePrivacyHack_throwPossibleException> *>(&future)->cancel(); 0062 } 0063 0064 } // namespace evil 0065 0066 #endif 0067 0068 #else 0069 #warning "Exceptions are disabled. If you enable them, you'll open a whole new world" 0070 #endif 0071 0072 } // namespace AsynQt 0073 0074 #endif // ASYNQT_CONS_CANCELED_FUTURE_H