2#include <ossia/detail/fmt.hpp>
3#include <ossia/detail/hash_map.hpp>
4#include <ossia/detail/small_vector.hpp>
5#include <ossia/network/dataspace/dataspace_variant_visitors.hpp>
7#include <ossia/network/oscquery/detail/json_writer_detail.hpp>
12struct hash<
ossia::small_vector<std::string, 4>>
14 std::size_t operator()(
const ossia::small_vector<std::string, 4>& v)
const noexcept
18 ossia::hash_combine(seed, std::hash<std::string>{}(str));
23namespace ossia::oscquery::detail
28 const json_writer_impl& writer;
31 void operator()(
const ossia::degree_u& u) { write_unit(u); }
32 void operator()(
const ossia::radian_u& u) { write_unit(u); }
34 void operator()(
const ossia::argb_u&)
36 writer.writeKey(
"EXTENDED_TYPE");
37 writer.writer.StartArray();
38 writer.writer.String(
"color.rgb.a");
39 writer.writer.String(
"color.rgb.r");
40 writer.writer.String(
"color.rgb.g");
41 writer.writer.String(
"color.rgb.b");
42 writer.writer.EndArray();
45 void operator()(
const ossia::rgba_u&)
47 writer.writeKey(
"EXTENDED_TYPE");
48 writer.writer.StartArray();
49 writer.writer.String(
"color.rgb.r");
50 writer.writer.String(
"color.rgb.g");
51 writer.writer.String(
"color.rgb.b");
52 writer.writer.String(
"color.rgb.a");
53 writer.writer.EndArray();
56 void operator()(
const ossia::rgba8_u&)
61 void operator()(
const ossia::rgb_u&)
63 writer.writeKey(
"EXTENDED_TYPE");
64 writer.writer.StartArray();
65 writer.writer.String(
"color.rgb.r");
66 writer.writer.String(
"color.rgb.g");
67 writer.writer.String(
"color.rgb.b");
68 writer.writer.EndArray();
71 void operator()(
const ossia::bgr_u&)
73 writer.writeKey(
"EXTENDED_TYPE");
74 writer.writer.StartArray();
75 writer.writer.String(
"color.rgb.b");
76 writer.writer.String(
"color.rgb.g");
77 writer.writer.String(
"color.rgb.r");
78 writer.writer.EndArray();
81 void operator()(
const ossia::argb8_u&)
83 writer.writeKey(
"EXTENDED_TYPE");
84 writer.writer.StartArray();
85 writer.writer.String(
"color.rgb8.a");
86 writer.writer.String(
"color.rgb8.r");
87 writer.writer.String(
"color.rgb8.g");
88 writer.writer.String(
"color.rgb8.b");
89 writer.writer.EndArray();
92 void operator()(
const ossia::hsv_u&)
94 writer.writeKey(
"EXTENDED_TYPE");
95 writer.writer.StartArray();
96 writer.writer.String(
"color.hsv.h");
97 writer.writer.String(
"color.hsv.s");
98 writer.writer.String(
"color.hsv.v");
99 writer.writer.EndArray();
102 void operator()(
const ossia::cmy8_u&)
104 writer.writeKey(
"EXTENDED_TYPE");
105 writer.writer.StartArray();
106 writer.writer.String(
"color.cmyk8.c");
107 writer.writer.String(
"color.cmyk8.m");
108 writer.writer.String(
"color.cmyk8.y");
109 writer.writer.EndArray();
112 void operator()(
const ossia::xyz_u&)
114 writer.writeKey(
"EXTENDED_TYPE");
115 writer.writer.StartArray();
116 writer.writer.String(
"color.ciexyz.x");
117 writer.writer.String(
"color.ciexyz.y");
118 writer.writer.String(
"color.ciexyz.z");
119 writer.writer.EndArray();
122 void operator()(
const ossia::hsl_u&)
124 writer.writeKey(
"EXTENDED_TYPE");
125 writer.writer.StartArray();
126 writer.writer.String(
"color.hsl.h");
127 writer.writer.String(
"color.hsl.s");
128 writer.writer.String(
"color.hsl.l");
129 writer.writer.EndArray();
132 void operator()(
const ossia::cmyk8_u&)
134 writer.writeKey(
"EXTENDED_TYPE");
135 writer.writer.StartArray();
136 writer.writer.String(
"color.cmyk8.c");
137 writer.writer.String(
"color.cmyk8.m");
138 writer.writer.String(
"color.cmyk8.y");
139 writer.writer.String(
"color.cmyk8.k");
140 writer.writer.EndArray();
143 void operator()(
const ossia::yxy_u&)
145 writer.writeKey(
"EXTENDED_TYPE");
146 writer.writer.StartArray();
147 writer.writer.String(
"color.cieYxy.Y");
148 writer.writer.String(
"color.cieYxy.x");
149 writer.writer.String(
"color.cieYxy.y");
150 writer.writer.EndArray();
153 void operator()(
const ossia::hunter_lab_u&)
155 writer.writeKey(
"EXTENDED_TYPE");
156 writer.writer.StartArray();
157 writer.writer.String(
"color.hunterLab.l");
158 writer.writer.String(
"color.hunterLab.a");
159 writer.writer.String(
"color.hunterLab.b");
160 writer.writer.EndArray();
162 void operator()(
const ossia::cie_lab_u&)
164 writer.writeKey(
"EXTENDED_TYPE");
165 writer.writer.StartArray();
166 writer.writer.String(
"color.cieLab.l");
167 writer.writer.String(
"color.cieLab.a");
168 writer.writer.String(
"color.cieLab.b");
169 writer.writer.EndArray();
171 void operator()(
const ossia::cie_luv_u&)
173 writer.writeKey(
"EXTENDED_TYPE");
174 writer.writer.StartArray();
175 writer.writer.String(
"color.cieLuv.l");
176 writer.writer.String(
"color.cieLuv.u");
177 writer.writer.String(
"color.cieLuv.v");
178 writer.writer.EndArray();
181 void operator()(
const ossia::meter_u& u) { write_unit(u); }
182 void operator()(
const ossia::kilometer_u& u) { write_unit(u); }
183 void operator()(
const ossia::decimeter_u& u) { write_unit(u); }
184 void operator()(
const centimeter_u& u) { write_unit(u); }
185 void operator()(
const millimeter_u& u) { write_unit(u); }
186 void operator()(
const micrometer_u& u) { write_unit(u); }
187 void operator()(
const nanometer_u& u) { write_unit(u); }
188 void operator()(
const picometer_u& u) { write_unit(u); }
189 void operator()(
const inch_u& u) { write_unit(u); }
190 void operator()(
const foot_u& u) { write_unit(u); }
191 void operator()(
const mile_u& u) { write_unit(u); }
193 void operator()(
const linear_u& u) { write_unit(u); }
194 void operator()(
const midigain_u& u) { write_unit(u); }
195 void operator()(
const decibel_u& u) { write_unit(u); }
196 void operator()(
const decibel_raw_u& u) { write_unit(u); }
198 void operator()(
const quaternion_u& u) { write_extended(u); }
199 void operator()(
const euler_u& u) { write_extended(u); }
200 void operator()(
const axis_u& u) { write_extended(u); }
202 void operator()(
const spherical_u& u) { write_extended(u); }
203 void operator()(
const polar_u& u) { write_extended(u); }
204 void operator()(
const aed_u& u) { write_extended(u); }
205 void operator()(
const ad_u& u) { write_extended(u); }
206 void operator()(
const opengl_u& u) { write_extended(u); }
207 void operator()(
const cylindrical_u& u) { write_extended(u); }
208 void operator()(
const azd_u& u) { write_extended(u); }
210 void operator()(
const cartesian_3d_u&)
212 writer.writeKey(
"EXTENDED_TYPE");
213 writer.writer.StartArray();
214 writer.writer.String(
"position.cartesian.x");
215 writer.writer.String(
"position.cartesian.y");
216 writer.writer.String(
"position.cartesian.z");
217 writer.writer.EndArray();
220 void operator()(
const cartesian_2d_u&)
222 writer.writeKey(
"EXTENDED_TYPE");
223 writer.writer.StartArray();
224 writer.writer.String(
"position.cartesian.x");
225 writer.writer.String(
"position.cartesian.y");
226 writer.writer.EndArray();
229 void operator()(
const ossia::meter_per_second_u& u) { write_unit(u); }
230 void operator()(
const ossia::miles_per_hour_u& u) { write_unit(u); }
231 void operator()(
const ossia::kilometer_per_hour_u& u) { write_unit(u); }
232 void operator()(
const ossia::knot_u& u) { write_unit(u); }
233 void operator()(
const ossia::foot_per_hour_u& u) { write_unit(u); }
234 void operator()(
const ossia::foot_per_second_u& u) { write_unit(u); }
236 void operator()(
const ossia::second_u& u) { write_unit(u); }
237 void operator()(
const ossia::bark_u& u) { write_unit(u); }
238 void operator()(
const ossia::bpm_u& u) { write_unit(u); }
239 void operator()(
const ossia::cent_u& u) { write_unit(u); }
240 void operator()(
const ossia::frequency_u& u) { write_unit(u); }
241 void operator()(
const ossia::mel_u& u) { write_unit(u); }
242 void operator()(
const ossia::midi_pitch_u& u) { write_unit(u); }
243 void operator()(
const ossia::millisecond_u& u) { write_unit(u); }
244 void operator()(
const ossia::playback_speed_u& u) { write_unit(u); }
246 template <
typename T>
247 void write_unit(
const T&)
249 writer.writeKey(
"UNIT");
250 writer.writer.StartArray();
251 writer.writer.String(fmt::format(
252 "{}.{}", dataspace_traits<typename T::dataspace_type>::text()[0],
253 unit_traits<T>::text()[0]));
254 writer.writer.EndArray();
257 template <
typename T>
258 void write_extended(
const T&)
260 writer.writeKey(
"EXTENDED_TYPE");
262 writer.writer.StartArray();
263 if constexpr(is_array_unit<T>::value)
265 for(
char val : T::array_parameters())
267 writer.writer.String(fmt::format(
268 "{}.{}.{}", dataspace_traits<typename T::dataspace_type>::text()[0],
269 unit_traits<T>::text()[0], val));
274 writer.writer.String(fmt::format(
275 "{}.{}", dataspace_traits<typename T::dataspace_type>::text()[0],
276 unit_traits<T>::text()[0]));
278 writer.writer.EndArray();
284 ossia::hash_map<ossia::small_vector<std::string, 4>,
ossia::unit_t> map{
285 unit_matcher(degree_u{}),
286 unit_matcher(radian_u{}),
288 {{
"color.rgb.a",
"color.rgb.r",
"color.rgb.g",
"color.rgb.b"}, ossia::argb_u{}},
289 {{
"color.rgb.r",
"color.rgb.g",
"color.rgb.b",
"color.rgb.a"}, ossia::rgba_u{}},
293 {{
"color.rgb.r",
"color.rgb.g",
"color.rgb.b"}, ossia::rgb_u{}},
294 {{
"color.rgb.b",
"color.rgb.g",
"color.rgb.r"}, ossia::bgr_u{}},
295 {{
"color.rgb8.a",
"color.rgb8.r",
"color.rgb8.g",
"color.rgb8.b"},
297 {{
"color.hsv.h",
"color.hsv.s",
"color.hsv.v"}, ossia::hsv_u{}},
298 {{
"color.cmyk8.c",
"color.cmyk8.m",
"color.cmyk8.y"}, ossia::cmy8_u{}},
299 {{
"color.ciexyz.x",
"color.ciexyz.y",
"color.ciexyz.z"}, ossia::xyz_u{}},
309 unit_matcher(meter_u{}),
310 unit_matcher(kilometer_u{}),
311 unit_matcher(decimeter_u{}),
312 unit_matcher(centimeter_u{}),
313 unit_matcher(millimeter_u{}),
314 unit_matcher(micrometer_u{}),
315 unit_matcher(nanometer_u{}),
316 unit_matcher(picometer_u{}),
317 unit_matcher(inch_u{}),
318 unit_matcher(foot_u{}),
319 unit_matcher(mile_u{}),
321 unit_matcher(linear_u{}),
322 unit_matcher(midigain_u{}),
323 unit_matcher(decibel_u{}),
324 unit_matcher(decibel_raw_u{}),
326 unit_matcher(quaternion_u{}),
327 unit_matcher(euler_u{}),
328 unit_matcher(axis_u{}),
330 unit_matcher(spherical_u{}),
331 unit_matcher(polar_u{}),
332 unit_matcher(aed_u{}),
333 unit_matcher(ad_u{}),
334 unit_matcher(opengl_u{}),
335 unit_matcher(cylindrical_u{}),
336 unit_matcher(azd_u{}),
338 {{
"position.cartesian.x",
"position.cartesian.y",
"position.cartesian.z"},
339 ossia::cartesian_3d_u{}},
340 {{
"position.cartesian.x",
"position.cartesian.y"}, ossia::cartesian_2d_u{}},
342 unit_matcher(meter_per_second_u{}),
343 unit_matcher(miles_per_hour_u{}),
344 unit_matcher(kilometer_per_hour_u{}),
345 unit_matcher(knot_u{}),
346 unit_matcher(foot_per_hour_u{}),
347 unit_matcher(foot_per_second_u{}),
349 unit_matcher(second_u{}),
350 unit_matcher(bark_u{}),
351 unit_matcher(bpm_u{}),
352 unit_matcher(cent_u{}),
353 unit_matcher(frequency_u{}),
354 unit_matcher(mel_u{}),
355 unit_matcher(midi_pitch_u{}),
356 unit_matcher(millisecond_u{}),
357 unit_matcher(playback_speed_u{})};
359 template <
typename T>
360 static std::pair<ossia::small_vector<std::string, 4>,
ossia::unit_t>
361 unit_matcher(
const T&)
363 ossia::small_vector<std::string, 4> vec;
364 if constexpr(is_array_unit<T>::value)
366 for(
char val : T::array_parameters())
368 vec.push_back(fmt::format(
369 "{}.{}.{}", dataspace_traits<typename T::dataspace_type>::text()[0],
370 unit_traits<T>::text()[0], val));
375 vec.push_back(fmt::format(
376 "{}.{}", dataspace_traits<typename T::dataspace_type>::text()[0],
377 unit_traits<T>::text()[0]));
380 return {std::move(vec), T{}};
Definition dataspace.hpp:24