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
23QT_BEGIN_NAMESPACE
24
25namespace Tasking {
26
27class Then;
28class ThenItem;
29class ElseItem;
30class ElseIfItem;
31
32class TASKING_EXPORT If
33{
34public:
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
41private:
42 TASKING_EXPORT friend ThenItem operator>>(const If &ifItem, const Then &thenItem);
43
44 friend class ThenItem;
45 ExecutableItem m_condition;
46};
47
48class TASKING_EXPORT ElseIf
49{
50public:
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
57private:
58 friend class ElseIfItem;
59 ExecutableItem m_condition;
60};
61
62class TASKING_EXPORT Else
63{
64public:
65 explicit Else(const QList<GroupItem> &children) : m_body({children}) {}
66 explicit Else(std::initializer_list<GroupItem> children) : m_body({children}) {}
67
68private:
69 friend class ElseItem;
70 Group m_body;
71};
72
73class TASKING_EXPORT Then
74{
75public:
76 explicit Then(const QList<GroupItem> &children) : m_body({children}) {}
77 explicit Then(std::initializer_list<GroupItem> children) : m_body({children}) {}
78
79private:
80 friend class ThenItem;
81 Group m_body;
82};
83
84class ConditionData
85{
86public:
87 std::optional<ExecutableItem> m_condition;
88 Group m_body;
89};
90
91class ElseIfItem;
92
93class TASKING_EXPORT ThenItem
94{
95public:
96 operator ExecutableItem() const;
97
98private:
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
112class TASKING_EXPORT ElseItem
113{
114public:
115 operator ExecutableItem() const;
116
117private:
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
125class TASKING_EXPORT ElseIfItem
126{
127private:
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
140QT_END_NAMESPACE
141
142#endif // TASKING_CONDITIONAL_H
143

source code of qtbase/src/assets/downloader/tasking/conditional.h