MessageNode.hpp
1 #pragma once
2 #include <State/Address.hpp>
3 #include <State/Message.hpp>
4 #include <State/Value.hpp>
5 
6 #include <score/config.hpp>
7 #include <score/model/Identifier.hpp>
8 #include <score/model/tree/TreeNode.hpp>
9 #include <score/tools/std/Optional.hpp>
10 
11 #include <QString>
12 #include <QVector>
13 
14 #include <score_lib_process_export.h>
15 
16 #include <array>
17 
18 namespace Process
19 {
20 class ProcessModel;
21 
23 {
25  std::optional<ossia::value> value;
26 };
27 
28 enum class PriorityPolicy
29 {
30  User,
31  Previous,
32  Following
33 };
34 
35 struct SCORE_LIB_PROCESS_EXPORT StateNodeValues
36 {
37  bool empty() const;
38 
39  // TODO use lists or queues instead to manage the priorities
40  std::vector<ProcessStateData> previousProcessValues;
41  std::vector<ProcessStateData> followingProcessValues;
42  std::optional<ossia::value> userValue;
43 
44  std::array<PriorityPolicy, 3> priorities{
45  {PriorityPolicy::Previous, PriorityPolicy::Following, PriorityPolicy::User}};
46 
47  bool hasValue() const;
48 
49  static bool hasValue(const std::vector<ProcessStateData>& vec);
50  static std::vector<ProcessStateData>::const_iterator
51  value(const std::vector<ProcessStateData>& vec);
52 
53  // TODO here we have to choose a policy
54  // if we have both previous and following processes ?
55  std::optional<ossia::value> value() const;
56 
57  QString displayValue() const;
58 };
59 
60 struct SCORE_LIB_PROCESS_EXPORT StateNodeData
61 {
63  StateNodeValues values;
64 
65  QString displayName() const;
66  bool hasValue() const;
67  std::optional<ossia::value> value() const;
68 };
69 
70 SCORE_LIB_PROCESS_EXPORT QDebug operator<<(QDebug d, const ProcessStateData& mess);
71 SCORE_LIB_PROCESS_EXPORT QDebug operator<<(QDebug d, const StateNodeData& mess);
72 
74 
75 SCORE_LIB_PROCESS_EXPORT State::AddressAccessor address(const MessageNode& treeNode);
76 SCORE_LIB_PROCESS_EXPORT State::Message message(const MessageNode& node);
77 SCORE_LIB_PROCESS_EXPORT State::Message userMessage(const MessageNode& node);
78 
79 SCORE_LIB_PROCESS_EXPORT Process::MessageNode*
80 try_getNodeFromAddress(Process::MessageNode& root, const State::AddressAccessor& addr);
81 SCORE_LIB_PROCESS_EXPORT std::vector<Process::MessageNode*>
82 try_getNodesFromAddress(Process::MessageNode& root, const State::AddressAccessor& addr);
83 SCORE_LIB_PROCESS_EXPORT State::MessageList flatten(const MessageNode&);
84 SCORE_LIB_PROCESS_EXPORT State::MessageList getUserMessages(const MessageNode&);
85 SCORE_LIB_PROCESS_EXPORT bool hasMatchingAddress(
86  const MessageNode& root, const std::vector<State::AddressAccessor>& addr,
87  State::MessageList& msglist, std::vector<QString>& converted_addresses);
88 SCORE_LIB_PROCESS_EXPORT bool hasMatchingText(
89  const MessageNode& root, const QString& text, State::MessageList& msglist,
90  std::vector<QString>& converted_addresses);
91 }
92 
93 #if SCORE_EXTERN_TEMPLATES_IN_SHARED_LIBRARIES
94 extern template class SCORE_LIB_PROCESS_EXPORT TreeNode<Process::StateNodeData>;
95 #endif
The id_base_t class.
Definition: Identifier.hpp:57
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Definition: MessageNode.hpp:23
Definition: MessageNode.hpp:61
Definition: MessageNode.hpp:36
The AddressAccessorHead struct.
Definition: Address.hpp:147
Definition: Address.hpp:108
The Message struct.
Definition: Message.hpp:15