From b91a5d053d48b90a2cf56429d432cdfcb1098efd Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 10 Jul 2020 13:07:42 +0200 Subject: QtConcurrent: Get rid of code repetition for RunFunctionTask::run() Change-Id: If270982e54d2b11be00c71b9d012af629d181dfe Reviewed-by: Sona Kurazyan Reviewed-by: Andrei Golubev --- src/concurrent/qtconcurrentrunbase.h | 53 +++++++++++++----------------------- 1 file changed, 19 insertions(+), 34 deletions(-) (limited to 'src/concurrent/qtconcurrentrunbase.h') diff --git a/src/concurrent/qtconcurrentrunbase.h b/src/concurrent/qtconcurrentrunbase.h index 5e9fa0aa00..176097c04f 100644 --- a/src/concurrent/qtconcurrentrunbase.h +++ b/src/concurrent/qtconcurrentrunbase.h @@ -100,14 +100,6 @@ public: // For backward compatibility QFuture start(QThreadPool *pool) { return start({pool, 0}); } - void run() override {} - virtual void runFunctor() = 0; -}; - -template -class RunFunctionTask : public RunFunctionTaskBase -{ -public: void run() override { if (this->isCanceled()) { @@ -117,7 +109,7 @@ public: #ifndef QT_NO_EXCEPTIONS try { #endif - this->runFunctor(); + runFunctor(); #ifndef QT_NO_EXCEPTIONS } catch (QException &e) { QFutureInterface::reportException(e); @@ -126,41 +118,34 @@ public: } #endif - if constexpr (std::is_move_constructible_v) - this->reportAndMoveResult(std::move(result)); - else if constexpr (std::is_copy_constructible_v) - this->reportResult(result); + reportResult(); this->reportFinished(); } - T result; + +protected: + virtual void runFunctor() = 0; + virtual void reportResult() {} }; -template <> -class RunFunctionTask : public RunFunctionTaskBase +template +class RunFunctionTask : public RunFunctionTaskBase { -public: - void run() override +protected: + void reportResult() override { - if (this->isCanceled()) { - this->reportFinished(); - return; - } -#ifndef QT_NO_EXCEPTIONS - try { -#endif - this->runFunctor(); -#ifndef QT_NO_EXCEPTIONS - } catch (QException &e) { - QFutureInterface::reportException(e); - } catch (...) { - QFutureInterface::reportException(QUnhandledException()); - } -#endif - this->reportFinished(); + if constexpr (std::is_move_constructible_v) + this->reportAndMoveResult(std::move(result)); + else if constexpr (std::is_copy_constructible_v) + this->reportResult(result); } + + T result; }; +template <> +class RunFunctionTask : public RunFunctionTaskBase {}; + } //namespace QtConcurrent #endif //Q_QDOC -- cgit v1.2.3