Debian Codegraph @

src/assets/downloader/tasking/conditional.h

raw
1 // Copyright (C) 2024 Jarek Kobus
2 // Copyright (C) 2024 The Qt Company Ltd.
3 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5 #ifndef TASKING_CONDITIONAL_H
6 #define TASKING_CONDITIONAL_H
7
8 //
9 // W A R N I N G
10 // -------------
11 //
12 // This file is not part of the Qt API. It exists purely as an
13 // implementation detail. This header file may change from version to
14 // version without notice, or even be removed.
15 //
16 // We mean it.
17 //
18
19 #include "tasking_global.h"
20
21 #include "tasktree.h"
22
23 QT_BEGIN_NAMESPACE
24
25 namespace Tasking {
26
27 class Then;
28 class ThenItem;
29 class ElseItem;
30 class ElseIfItem;
31
32 class TASKING_EXPORT If
33 {
34 public:
35 explicit If(const ExecutableItem &condition) : m_condition(condition) {}
36
37 template <typename Handler,
38 std::enable_if_t<!std::is_base_of_v<ExecutableItem, std::decay_t<Handler>>, bool> = true>
39 explicit If(Handler &&handler) : m_condition(Sync(std::forward<Handler>(handler))) {}
40
41 private:
42 TASKING_EXPORT friend ThenItem operator>>(const If &ifItem, const Then &thenItem);
43
44 friend class ThenItem;
45 ExecutableItem m_condition;
46 };
47
48 class TASKING_EXPORT ElseIf
49 {
50 public:
51 explicit ElseIf(const ExecutableItem &condition) : m_condition(condition) {}
52
53 template <typename Handler,
54 std::enable_if_t<!std::is_base_of_v<ExecutableItem, std::decay_t<Handler>>, bool> = true>
55 explicit ElseIf(Handler &&handler) : m_condition(Sync(std::forward<Handler>(handler))) {}
56
57 private:
58 friend class ElseIfItem;
59 ExecutableItem m_condition;
60 };
61
62 class TASKING_EXPORT Else
63 {
64 public:
65 explicit Else(const GroupItems &children) : m_body({children}) {}
66 explicit Else(std::initializer_list<GroupItem> children) : m_body({children}) {}
67
68 private:
69 friend class ElseItem;
70 Group m_body;
71 };
72
73 class TASKING_EXPORT Then
74 {
75 public:
76 explicit Then(const GroupItems &children) : m_body({children}) {}
77 explicit Then(std::initializer_list<GroupItem> children) : m_body({children}) {}
78
79 private:
80 friend class ThenItem;
81 Group m_body;
82 };
83
84 class ConditionData
85 {
86 public:
87 std::optional<ExecutableItem> m_condition;
88 Group m_body;
89 };
90
91 class ElseIfItem;
92
93 class TASKING_EXPORT ThenItem
94 {
95 public:
96 operator ExecutableItem() const;
97
98 private:
99 ThenItem(const If &ifItem, const Then &thenItem);
100 ThenItem(const ElseIfItem &elseIfItem, const Then &thenItem);
101
102 TASKING_EXPORT friend ElseItem operator>>(const ThenItem &thenItem, const Else &elseItem);
103 TASKING_EXPORT friend ElseIfItem operator>>(const ThenItem &thenItem, const ElseIf &elseIfItem);
104 TASKING_EXPORT friend ThenItem operator>>(const If &ifItem, const Then &thenItem);
105 TASKING_EXPORT friend ThenItem operator>>(const ElseIfItem &elseIfItem, const Then &thenItem);
106
107 friend class ElseItem;
108 friend class ElseIfItem;
109 QList<ConditionData> m_conditions;
110 };
111
112 class TASKING_EXPORT ElseItem
113 {
114 public:
115 operator ExecutableItem() const;
116
117 private:
118 ElseItem(const ThenItem &thenItem, const Else &elseItem);
119
120 TASKING_EXPORT friend ElseItem operator>>(const ThenItem &thenItem, const Else &elseItem);
121
122 QList<ConditionData> m_conditions;
123 };
124
125 class TASKING_EXPORT ElseIfItem
126 {
127 private:
128 ElseIfItem(const ThenItem &thenItem, const ElseIf &elseIfItem);
129
130 TASKING_EXPORT friend ThenItem operator>>(const ElseIfItem &elseIfItem, const Then &thenItem);
131 TASKING_EXPORT friend ElseIfItem operator>>(const ThenItem &thenItem, const ElseIf &elseIfItem);
132
133 friend class ThenItem;
134 QList<ConditionData> m_conditions;
135 ExecutableItem m_nextCondition;
136 };
137
138 } // namespace Tasking
139
140 QT_END_NAMESPACE
141
142 #endif // TASKING_CONDITIONAL_H