Loading...
Searching...
No Matches
Address.hpp
1#pragma once
2#include <score/serialization/DataStreamFwd.hpp>
3#include <score/tools/std/Optional.hpp>
4
5#include <ossia/detail/destination_index.hpp>
6#include <ossia/detail/optional.hpp>
7
8#include <QString>
9#include <QStringList>
10
11#include <score_lib_state_export.h>
12
13#include <memory>
14#include <verdigris>
15namespace ossia
16{
17struct destination_qualifiers;
18struct unit_t;
19}
20
21namespace State
22{
23struct SCORE_LIB_STATE_EXPORT DestinationQualifiers
24{
25 W_GADGET(DestinationQualifiers)
26public:
27 DestinationQualifiers() noexcept;
30 DestinationQualifiers& operator=(const DestinationQualifiers& other);
31 DestinationQualifiers& operator=(DestinationQualifiers&& other) noexcept;
33
34 DestinationQualifiers(const ossia::destination_qualifiers&);
35 DestinationQualifiers& operator=(const ossia::destination_qualifiers&);
36
37 operator const ossia::destination_qualifiers&() const noexcept;
38 operator ossia::destination_qualifiers&() noexcept;
39
40 bool operator==(const State::DestinationQualifiers& other) const noexcept;
41 bool operator!=(const State::DestinationQualifiers& other) const noexcept;
42
43 const ossia::destination_qualifiers& get() const noexcept;
44 ossia::destination_qualifiers& get() noexcept;
45
46private:
47 std::unique_ptr<ossia::destination_qualifiers> qualifiers;
48};
57struct SCORE_LIB_STATE_EXPORT Address
58{
59 Address() noexcept;
60 Address(const Address& other) noexcept;
61 Address(Address&&) noexcept;
62 Address& operator=(const Address& other) noexcept;
63 Address& operator=(Address&& other) noexcept;
64 Address(QString d, QStringList p) noexcept;
65
66 // Data
67 QString device; // No device means that this is the invisible root node.
68
69 QStringList path; // Note : path is empty if address is root: "device:/"
70 // In terms of Device::Node, this means that the node is the device node.
71
72 // Check that the given string is a valid address
73 // Note: a "maybe" concept would help here.
74 static bool validateString(const QString& str);
75 static bool validateFragment(const QString& s);
76
77 // Make an address from a valid address string
78 static std::optional<Address> fromString(const QString& str);
79
84 QString toString() const;
85
86 QString toString_unsafe() const;
87
92 QString toShortString() const;
93
97 bool isSet() const noexcept;
98
99 bool operator==(const Address& a) const;
100 bool operator!=(const Address& a) const;
101};
102
103using AccessorVector = ossia::destination_index;
104SCORE_LIB_STATE_EXPORT
105QString toString(const ossia::destination_qualifiers& d);
106
107struct SCORE_LIB_STATE_EXPORT AddressAccessor
108{
109 AddressAccessor() noexcept;
110 AddressAccessor(const AddressAccessor& other) noexcept;
111 AddressAccessor(AddressAccessor&& other) noexcept;
112 AddressAccessor& operator=(const AddressAccessor& other) noexcept;
113 AddressAccessor& operator=(AddressAccessor&& other) noexcept;
114
115 explicit AddressAccessor(State::Address a) noexcept;
116 AddressAccessor(State::Address a, const AccessorVector& v) noexcept;
118 State::Address a, const AccessorVector& v, const ossia::unit_t&) noexcept;
119
120 AddressAccessor& operator=(const Address& a);
121 AddressAccessor& operator=(Address&& a);
122
123 State::Address address;
124 DestinationQualifiers qualifiers;
125
126 // Utility
127 QString toString_unsafe() const;
128 QString toString() const;
129 QString toShortString() const;
130
134 bool isSet() const noexcept;
135
136 bool operator==(const AddressAccessor& other) const;
137 bool operator!=(const AddressAccessor& a) const;
138};
139
146struct SCORE_LIB_STATE_EXPORT AddressAccessorHead
147{
148 QString name;
149 DestinationQualifiers qualifiers;
150
151 QString toString() const;
152};
153
154SCORE_LIB_STATE_EXPORT
155bool addressIsChildOf(
156 const State::Address& root, const State::Address& maybe_child) noexcept;
157
158SCORE_LIB_STATE_EXPORT
159State::Address replaceAddressPart(
160 const State::Address& old, const State::Address& replacement) noexcept;
161
162SCORE_LIB_STATE_EXPORT
163State::AddressAccessor replaceAddressPart(
164 const State::AddressAccessor& old, const State::Address& replacement) noexcept;
165
166SCORE_LIB_STATE_EXPORT
167void rerootAddress(
168 State::Address& current, const State::Address& oldRoot,
169 const State::Address& newRoot);
170
171SCORE_LIB_STATE_EXPORT std::optional<State::Address> parseAddress(const QString& str);
172SCORE_LIB_STATE_EXPORT std::optional<State::AddressAccessor>
173parseAddressAccessor(const QString& str);
174
175SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const State::Address& a);
176SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const DestinationQualifiers& a);
177SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const State::AccessorVector& a);
178SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const State::AddressAccessorHead& a);
179SCORE_LIB_STATE_EXPORT QDebug operator<<(QDebug d, const State::AddressAccessor& a);
180SCORE_LIB_STATE_EXPORT QStringList stringList(const State::Address& addr);
181}
182
183namespace std
184{
185template <>
186struct SCORE_LIB_STATE_EXPORT hash<State::Address>
187{
188 std::size_t operator()(const State::Address& k) const;
189};
190
191template <>
192struct SCORE_LIB_STATE_EXPORT hash<State::AddressAccessor>
193{
194 std::size_t operator()(const State::AddressAccessor& k) const;
195};
196}
197
198SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_STATE_EXPORT, State::DestinationQualifiers)
199SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_STATE_EXPORT, State::Address)
200SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_STATE_EXPORT, State::AddressAccessor)
201
202Q_DECLARE_METATYPE(State::DestinationQualifiers)
203Q_DECLARE_METATYPE(State::Address)
204Q_DECLARE_METATYPE(State::AddressAccessor)
205
206W_REGISTER_ARGTYPE(State::DestinationQualifiers)
207W_REGISTER_ARGTYPE(State::Address)
208W_REGISTER_ARGTYPE(State::AddressAccessor)
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:33
STL namespace.
The AddressAccessorHead struct.
Definition Address.hpp:147
Definition Address.hpp:108
The Address struct.
Definition Address.hpp:58
Definition Address.hpp:24