Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
conditional.cpp
Go to the documentation of this file.
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#include "conditional.h"
6
8
9namespace Tasking {
10
11static Group conditionRecipe(const Storage<bool> &bodyExecutedStorage, const ConditionData &condition)
12{
13 const auto onSetup = [bodyExecutedStorage] {
14 return *bodyExecutedStorage ? SetupResult::StopWithSuccess : SetupResult::Continue;
15 };
16
17 const auto onBodyDone = [bodyExecutedStorage] { *bodyExecutedStorage = true; };
18
19 const Group bodyTask { condition.m_body, onGroupDone(onBodyDone) };
20
21 return {
22 onGroupSetup(onSetup),
23 condition.m_condition ? Group{ !*condition.m_condition || bodyTask } : bodyTask
24 };
25}
26
27static ExecutableItem conditionsRecipe(const QList<ConditionData> &conditions)
28{
29 Storage<bool> bodyExecutedStorage;
30
31 GroupItems recipes;
32 for (const ConditionData &condition : conditions)
33 recipes << conditionRecipe(bodyExecutedStorage, condition);
34
35 return Group { bodyExecutedStorage, recipes };
36}
37
39{
40 return conditionsRecipe(m_conditions);
41}
42
43ThenItem::ThenItem(const If &ifItem, const Then &thenItem)
44 : m_conditions{{ifItem.m_condition, thenItem.m_body}}
45{}
46
47ThenItem::ThenItem(const ElseIfItem &elseIfItem, const Then &thenItem)
48 : m_conditions(elseIfItem.m_conditions)
49{
50 m_conditions.append({elseIfItem.m_nextCondition, thenItem.m_body});
51}
52
54{
55 return conditionsRecipe(m_conditions);
56}
57
58ElseItem::ElseItem(const ThenItem &thenItem, const Else &elseItem)
59 : m_conditions(thenItem.m_conditions)
60{
61 m_conditions.append({{}, elseItem.m_body});
62}
63
64ElseIfItem::ElseIfItem(const ThenItem &thenItem, const ElseIf &elseIfItem)
65 : m_conditions(thenItem.m_conditions)
66 , m_nextCondition(elseIfItem.m_condition)
67{}
68
69ThenItem operator>>(const If &ifItem, const Then &thenItem)
70{
71 return {ifItem, thenItem};
72}
73
74ThenItem operator>>(const ElseIfItem &elseIfItem, const Then &thenItem)
75{
76 return {elseIfItem, thenItem};
77}
78
79ElseIfItem operator>>(const ThenItem &thenItem, const ElseIf &elseIfItem)
80{
81 return {thenItem, elseIfItem};
82}
83
84ElseItem operator>>(const ThenItem &thenItem, const Else &elseItem)
85{
86 return {thenItem, elseItem};
87}
88
89} // namespace Tasking
90
91QT_END_NAMESPACE
operator ExecutableItem() const
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
Definition tasktree.h:317
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
Definition tasktree.h:348
friend class Storage
Definition tasktree.h:188
operator ExecutableItem() const
\inmodule TaskingSolution
static ExecutableItem conditionsRecipe(const QList< ConditionData > &conditions)
ElseItem operator>>(const ThenItem &thenItem, const Else &elseItem)
ElseIfItem operator>>(const ThenItem &thenItem, const ElseIf &elseIfItem)
static Group conditionRecipe(const Storage< bool > &bodyExecutedStorage, const ConditionData &condition)
ThenItem operator>>(const If &ifItem, const Then &thenItem)
ThenItem operator>>(const ElseIfItem &elseIfItem, const Then &thenItem)