Differential D18758 Diff 58398 kdevplatform/3rdparty/qtpromise/qtpromise-0.5.0/src/qtpromise/qpromisehelpers_p.h
Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/3rdparty/qtpromise/qtpromise-0.5.0/src/qtpromise/qpromisehelpers_p.h
- This file was added.
1 | #ifndef QTPROMISE_QPROMISEHELPERS_P_H | ||||
---|---|---|---|---|---|
2 | #define QTPROMISE_QPROMISEHELPERS_P_H | ||||
3 | | ||||
4 | #include "qpromiseconnections.h" | ||||
5 | #include "qpromiseexceptions.h" | ||||
6 | | ||||
7 | namespace QtPromisePrivate { | ||||
8 | | ||||
9 | // TODO: Suppress QPrivateSignal trailing private signal args | ||||
10 | // TODO: Support deducing tuple from args (might require MSVC2017) | ||||
11 | | ||||
12 | template <typename Signal> | ||||
13 | using PromiseFromSignal = typename QtPromise::QPromise<Unqualified<typename ArgsOf<Signal>::first>>; | ||||
14 | | ||||
15 | // Connect signal() to QPromiseResolve | ||||
16 | template <typename Sender, typename Signal> | ||||
17 | typename std::enable_if<(ArgsOf<Signal>::count == 0)>::type | ||||
18 | connectSignalToResolver( | ||||
19 | const QtPromise::QPromiseConnections& connections, | ||||
20 | const QtPromise::QPromiseResolve<void>& resolve, | ||||
21 | const Sender* sender, | ||||
22 | Signal signal) | ||||
23 | { | ||||
24 | connections << QObject::connect(sender, signal, [=]() { | ||||
25 | connections.disconnect(); | ||||
26 | resolve(); | ||||
27 | }); | ||||
28 | } | ||||
29 | | ||||
30 | // Connect signal() to QPromiseReject | ||||
31 | template <typename T, typename Sender, typename Signal> | ||||
32 | typename std::enable_if<(ArgsOf<Signal>::count == 0)>::type | ||||
33 | connectSignalToResolver( | ||||
34 | const QtPromise::QPromiseConnections& connections, | ||||
35 | const QtPromise::QPromiseReject<T>& reject, | ||||
36 | const Sender* sender, | ||||
37 | Signal signal) | ||||
38 | { | ||||
39 | connections << QObject::connect(sender, signal, [=]() { | ||||
40 | connections.disconnect(); | ||||
41 | reject(QtPromise::QPromiseUndefinedException()); | ||||
42 | }); | ||||
43 | } | ||||
44 | | ||||
45 | // Connect signal(args...) to QPromiseResolve | ||||
46 | template <typename T, typename Sender, typename Signal> | ||||
47 | typename std::enable_if<(ArgsOf<Signal>::count >= 1)>::type | ||||
48 | connectSignalToResolver( | ||||
49 | const QtPromise::QPromiseConnections& connections, | ||||
50 | const QtPromise::QPromiseResolve<T>& resolve, | ||||
51 | const Sender* sender, | ||||
52 | Signal signal) | ||||
53 | { | ||||
54 | connections << QObject::connect(sender, signal, [=](const T& value) { | ||||
55 | connections.disconnect(); | ||||
56 | resolve(value); | ||||
57 | }); | ||||
58 | } | ||||
59 | | ||||
60 | // Connect signal(args...) to QPromiseReject | ||||
61 | template <typename T, typename Sender, typename Signal> | ||||
62 | typename std::enable_if<(ArgsOf<Signal>::count >= 1)>::type | ||||
63 | connectSignalToResolver( | ||||
64 | const QtPromise::QPromiseConnections& connections, | ||||
65 | const QtPromise::QPromiseReject<T>& reject, | ||||
66 | const Sender* sender, | ||||
67 | Signal signal) | ||||
68 | { | ||||
69 | using V = Unqualified<typename ArgsOf<Signal>::first>; | ||||
70 | connections << QObject::connect(sender, signal, [=](const V& value) { | ||||
71 | connections.disconnect(); | ||||
72 | reject(value); | ||||
73 | }); | ||||
74 | } | ||||
75 | | ||||
76 | // Connect QObject::destroyed signal to QPromiseReject | ||||
77 | template <typename T, typename Sender> | ||||
78 | void connectDestroyedToReject( | ||||
79 | const QtPromise::QPromiseConnections& connections, | ||||
80 | const QtPromise::QPromiseReject<T>& reject, | ||||
81 | const Sender* sender) | ||||
82 | { | ||||
83 | connections << QObject::connect(sender, &QObject::destroyed, [=]() { | ||||
84 | connections.disconnect(); | ||||
85 | reject(QtPromise::QPromiseContextException()); | ||||
86 | }); | ||||
87 | } | ||||
88 | | ||||
89 | } // namespace QtPromisePrivate | ||||
90 | | ||||
91 | #endif // QTPROMISE_QPROMISEHELPERS_P_H |