Loading...
Searching...
No Matches
Address.hpp
1#pragma once
2#include <score/model/path/ObjectPath.hpp>
3#include <score/serialization/DataStreamFwd.hpp>
4#include <score/tools/std/Optional.hpp>
5
6#include <ossia/detail/destination_index.hpp>
7#include <ossia/detail/optional.hpp>
8
9#include <QString>
10#include <QStringList>
11
12#include <score_lib_state_export.h>
13
14#include <memory>
15#include <verdigris>
16namespace ossia
17{
18struct destination_qualifiers;
19struct unit_t;
20}
21namespace score
22{
23struct DocumentContext;
24}
27
28namespace State
29{
32struct SCORE_LIB_STATE_EXPORT Anchor
33{
34 ObjectPath target;
35 QString member;
36
37 QObject* resolve(const score::DocumentContext& ctx) const noexcept;
38};
39
40SCORE_LIB_STATE_EXPORT void
41readAnchor(DataStreamReader& r, const std::shared_ptr<const Anchor>& a);
43SCORE_LIB_STATE_EXPORT void
44writeAnchor(DataStreamWriter& w, std::shared_ptr<const Anchor>& a);
45
46struct SCORE_LIB_STATE_EXPORT DestinationQualifiers
47{
48 W_GADGET(DestinationQualifiers)
49public:
50 DestinationQualifiers() noexcept;
53 DestinationQualifiers& operator=(const DestinationQualifiers& other);
54 DestinationQualifiers& operator=(DestinationQualifiers&& other) noexcept;
56
57 DestinationQualifiers(const ossia::destination_qualifiers&);
58 DestinationQualifiers& operator=(const ossia::destination_qualifiers&);
59
60 operator const ossia::destination_qualifiers&() const noexcept;
61 operator ossia::destination_qualifiers&() noexcept;
62
63 bool operator==(const State::DestinationQualifiers& other) const noexcept;
64 bool operator!=(const State::DestinationQualifiers& other) const noexcept;
65
66 const ossia::destination_qualifiers& get() const noexcept;
67 ossia::destination_qualifiers& get() noexcept;
68
69private:
70 std::unique_ptr<ossia::destination_qualifiers> qualifiers;
71};
80struct SCORE_LIB_STATE_EXPORT Address
81{
82 Address() noexcept;
83 Address(const Address& other) noexcept;
84 Address(Address&&) noexcept;
85 Address& operator=(const Address& other) noexcept;
86 Address& operator=(Address&& other) noexcept;
87 Address(QString d, QStringList p) noexcept;
88
89 // Data
90 QString device; // No device means that this is the invisible root node.
91
92 QStringList path; // Note : path is empty if address is root: "device:/"
93 // In terms of Device::Node, this means that the node is the device node.
94
96 std::shared_ptr<const Anchor> anchor;
97
98 bool anchored() const noexcept { return bool(anchor); }
99
100 // Check that the given string is a valid address
101 // Note: a "maybe" concept would help here.
102 static bool validateString(const QString& str);
103 static bool validateFragment(const QString& s);
104
105 // Make an address from a valid address string
106 static std::optional<Address> fromString(const QString& str);
107
112 QString toString() const;
113
114 QString toString_unsafe() const;
115
120 QString toShortString() const;
121
125 bool isSet() const noexcept;
126
127 bool operator==(const Address& a) const;
128 bool operator!=(const Address& a) const;
129};
130
131using AccessorVector = ossia::destination_index;
132SCORE_LIB_STATE_EXPORT
133QString toString(const ossia::destination_qualifiers& d);
134
135struct SCORE_LIB_STATE_EXPORT AddressAccessor
136{
137 AddressAccessor() noexcept;
138 AddressAccessor(const AddressAccessor& other) noexcept;
139 AddressAccessor(AddressAccessor&& other) noexcept;
140 AddressAccessor& operator=(const AddressAccessor& other) noexcept;
141 AddressAccessor& operator=(AddressAccessor&& other) noexcept;
142
143 explicit AddressAccessor(State::Address a) noexcept;
144 AddressAccessor(State::Address a, const AccessorVector& v) noexcept;
146 State::Address a, const AccessorVector& v, const ossia::unit_t&) noexcept;
147
148 AddressAccessor& operator=(const Address& a);
149 AddressAccessor& operator=(Address&& a);
150
151 State::Address address;
152 DestinationQualifiers qualifiers;
153
154 // Utility
155 QString toString_unsafe() const;
156 QString toString() const;
157 QString toShortString() const;
158
162 bool isSet() const noexcept;
163
164 bool operator==(const AddressAccessor& other) const;
165 bool operator!=(const AddressAccessor& a) const;
166};
167
174struct SCORE_LIB_STATE_EXPORT AddressAccessorHead
175{
176 QString name;
177 DestinationQualifiers qualifiers;
178
179 QString toString() const;
180};
181
182SCORE_LIB_STATE_EXPORT
183bool addressIsChildOf(
184 const State::Address& root, const State::Address& maybe_child) noexcept;
185
186SCORE_LIB_STATE_EXPORT
187State::Address replaceAddressPart(
188 const State::Address& old, const State::Address& replacement) noexcept;
189
190SCORE_LIB_STATE_EXPORT
191State::AddressAccessor replaceAddressPart(
192 const State::AddressAccessor& old, const State::Address& replacement) noexcept;
193
194SCORE_LIB_STATE_EXPORT
195void rerootAddress(
196 State::Address& current, const State::Address& oldRoot,
197 const State::Address& newRoot);
198
199SCORE_LIB_STATE_EXPORT std::optional<State::Address> parseAddress(const QString& str);
200SCORE_LIB_STATE_EXPORT std::optional<State::AddressAccessor>
201parseAddressAccessor(const QString& str);
202
203SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const State::Address& a);
204SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const DestinationQualifiers& a);
205SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const State::AccessorVector& a);
206SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const State::AddressAccessorHead& a);
207SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const State::AddressAccessor& a);
208SCORE_LIB_STATE_EXPORT QStringList stringList(const State::Address& addr);
209}
210
211namespace std
212{
213template <>
214struct SCORE_LIB_STATE_EXPORT hash<State::Address>
215{
216 std::size_t operator()(const State::Address& k) const;
217};
218
219template <>
220struct SCORE_LIB_STATE_EXPORT hash<State::AddressAccessor>
221{
222 std::size_t operator()(const State::AddressAccessor& k) const;
223};
224}
225
226SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_STATE_EXPORT, State::DestinationQualifiers)
227SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_STATE_EXPORT, State::Address)
228SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_STATE_EXPORT, State::AddressAccessor)
229
230Q_DECLARE_METATYPE(State::DestinationQualifiers)
231Q_DECLARE_METATYPE(State::Address)
232Q_DECLARE_METATYPE(State::AddressAccessor)
233
234W_REGISTER_ARGTYPE(State::DestinationQualifiers)
235W_REGISTER_ARGTYPE(State::Address)
236W_REGISTER_ARGTYPE(State::AddressAccessor)
Definition DataStreamVisitor.hpp:27
Definition DataStreamVisitor.hpp:202
The ObjectPath class.
Definition ObjectPath.hpp:37
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:35
void writeAnchor(DataStreamWriter &w, std::shared_ptr< const Anchor > &a)
Leaves the anchor empty, and the stream marked corrupt, on invalid data.
Definition AddressSerialization.cpp:32
Base toolkit upon which the software is built.
Definition Application.cpp:83
STL namespace.
The AddressAccessorHead struct.
Definition Address.hpp:175
Definition Address.hpp:136
The Address struct.
Definition Address.hpp:81
std::shared_ptr< const Anchor > anchor
Set when the address names an object of this document.
Definition Address.hpp:96
Definition Address.hpp:33
Definition Address.hpp:47
Definition DocumentContext.hpp:18