MessageItemModelAlgorithms.hpp
1 #pragma once
2 #include <State/Message.hpp>
3 
4 #include <Process/State/MessageNode.hpp>
5 
6 namespace Process
7 {
8 class ProcessModel;
9 }
10 #include <score/model/Identifier.hpp>
11 
12 namespace Scenario
13 {
14 // An enum that says if a process is before or after the state.
15 enum class ProcessPosition
16 {
17  Previous,
18  Following
19 };
20 
21 // User messages
22 void updateTreeWithMessageList(Process::MessageNode& rootNode, State::MessageList lst);
23 void renameAddress(
24  Process::MessageNode& rootNode, const State::AddressAccessor& oldAddr,
25  const State::AddressAccessor& newAddr);
26 void findAndReplaceAddresses(
27  Process::MessageNode& rootNode, const State::Address& oldAddr,
28  const State::Address& newAddr);
29 
30 // Messages from a process
31 void updateTreeWithMessageList(
32  Process::MessageNode& rootNode, State::MessageList lst,
33  const Id<Process::ProcessModel>& proc, ProcessPosition pos);
34 
35 void updateTreeWithRemovedProcess(
36  Process::MessageNode& rootNode, const Id<Process::ProcessModel>& proc,
37  ProcessPosition pos);
38 
39 void updateTreeWithRemovedInterval(Process::MessageNode& rootNode, ProcessPosition pos);
40 
41 void updateTreeWithRemovedUserMessage(
43 
44 void updateTreeWithRemovedNode(
45  Process::MessageNode& rootNode, const State::AddressAccessor& addr);
46 
47 void removeAllUserMessages(Process::MessageNode& rootNode);
48 
49 int countNodes(Process::MessageNode& rootNode);
50 Process::MessageNode* getNthChild(Process::MessageNode& rootNode, int n);
51 int getChildIndex(Process::MessageNode& rootNode, Process::MessageNode* n);
52 }
53 
54 #include <Scenario/Document/State/ItemModel/MessageItemModel.hpp>
55 namespace Scenario
56 {
57 // User messages
58 inline void updateModelWithMessageList(MessageItemModel& model, State::MessageList lst)
59 {
60  model.beginResetModel();
61  updateTreeWithMessageList(model.rootNode(), std::move(lst));
62  model.endResetModel();
63 }
64 
65 inline void renameAddress(
66  MessageItemModel& model, const State::AddressAccessor& oldAddr,
67  const State::AddressAccessor& newAddr)
68 {
69  model.beginResetModel();
70  renameAddress(model.rootNode(), oldAddr, newAddr);
71  model.endResetModel();
72 }
73 
74 // Messages from a process
75 inline void updateModelWithMessageList(
76  MessageItemModel& model, State::MessageList lst,
77  const Id<Process::ProcessModel>& proc, ProcessPosition pos)
78 {
79  model.beginResetModel();
80  updateTreeWithMessageList(model.rootNode(), std::move(lst), proc, pos);
81  model.endResetModel();
82 }
83 
84 inline void updateModelWithRemovedProcess(
85  MessageItemModel& model, const Id<Process::ProcessModel>& proc, ProcessPosition pos)
86 {
87  model.beginResetModel();
88  updateTreeWithRemovedProcess(model.rootNode(), proc, pos);
89  model.endResetModel();
90 }
91 
92 inline void updateModelWithRemovedInterval(MessageItemModel& model, ProcessPosition pos)
93 {
94  model.beginResetModel();
95  updateTreeWithRemovedInterval(model.rootNode(), pos);
96  model.endResetModel();
97 }
98 
99 inline void updateModelWithRemovedUserMessage(
100  MessageItemModel& model, const State::AddressAccessor& addr)
101 {
102  model.beginResetModel();
103  updateTreeWithRemovedUserMessage(model.rootNode(), addr);
104  model.endResetModel();
105 }
106 
107 inline void
108 updateModelWithRemovedNode(MessageItemModel& model, const State::AddressAccessor& addr)
109 {
110  model.beginResetModel();
111  updateTreeWithRemovedNode(model.rootNode(), addr);
112  model.endResetModel();
113 }
114 
115 inline void removeAllUserMessages(MessageItemModel& model)
116 {
117  model.beginResetModel();
118  removeAllUserMessages(model.rootNode());
119  model.endResetModel();
120 }
121 }
The id_base_t class.
Definition: Identifier.hpp:57
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: Address.hpp:108
The Address struct.
Definition: Address.hpp:58