OSSIA
Open Scenario System for Interactive Application
dataspace.hpp
1 #pragma once
2 #include <ossia/detail/hash.hpp>
3 #include <ossia/network/dataspace/angle.hpp>
4 #include <ossia/network/dataspace/color.hpp>
5 #include <ossia/network/dataspace/dataspace_fwd.hpp>
6 #include <ossia/network/dataspace/distance.hpp>
7 #include <ossia/network/dataspace/gain.hpp>
8 #include <ossia/network/dataspace/orientation.hpp>
9 #include <ossia/network/dataspace/position.hpp>
10 #include <ossia/network/dataspace/speed.hpp>
11 #include <ossia/network/dataspace/time.hpp>
12 
13 #include <functional>
14 namespace ossia
15 {
16 #include <ossia/network/dataspace/dataspace_base_variants.hpp>
22 
23 struct OSSIA_EXPORT unit_t final
24 {
25  unit_variant v;
26 
27  unit_t() noexcept = default;
28  unit_t(const unit_t&) noexcept = default;
29  unit_t(unit_t&&) noexcept = default;
30  unit_t& operator=(const unit_t&) noexcept = default;
31  unit_t& operator=(unit_t&&) noexcept = default;
32 
33  unit_t(angle_u t) noexcept
34  : v{t}
35  {
36  }
37  unit_t(degree_u t) noexcept
38  : v{angle_u{t}}
39  {
40  }
41  unit_t(radian_u t) noexcept
42  : v{angle_u{t}}
43  {
44  }
45 
46  unit_t(color_u t) noexcept
47  : v{t}
48  {
49  }
50  unit_t(argb_u t) noexcept
51  : v{color_u{t}}
52  {
53  }
54  unit_t(rgba_u t) noexcept
55  : v{color_u{t}}
56  {
57  }
58  unit_t(rgba8_u t) noexcept
59  : v{color_u{t}}
60  {
61  }
62  unit_t(rgb_u t) noexcept
63  : v{color_u{t}}
64  {
65  }
66  unit_t(bgr_u t) noexcept
67  : v{color_u{t}}
68  {
69  }
70  unit_t(argb8_u t) noexcept
71  : v{color_u{t}}
72  {
73  }
74  unit_t(hsv_u t) noexcept
75  : v{color_u{t}}
76  {
77  }
78  unit_t(cmy8_u t) noexcept
79  : v{color_u{t}}
80  {
81  }
82  unit_t(xyz_u t) noexcept
83  : v{color_u{t}}
84  {
85  }
86 
87  unit_t(distance_u t) noexcept
88  : v{t}
89  {
90  }
91  unit_t(meter_u t) noexcept
92  : v{distance_u{t}}
93  {
94  }
95  unit_t(kilometer_u t) noexcept
96  : v{distance_u{t}}
97  {
98  }
99  unit_t(decimeter_u t) noexcept
100  : v{distance_u{t}}
101  {
102  }
103  unit_t(centimeter_u t) noexcept
104  : v{distance_u{t}}
105  {
106  }
107  unit_t(millimeter_u t) noexcept
108  : v{distance_u{t}}
109  {
110  }
111  unit_t(micrometer_u t) noexcept
112  : v{distance_u{t}}
113  {
114  }
115  unit_t(nanometer_u t) noexcept
116  : v{distance_u{t}}
117  {
118  }
119  unit_t(picometer_u t) noexcept
120  : v{distance_u{t}}
121  {
122  }
123  unit_t(inch_u t) noexcept
124  : v{distance_u{t}}
125  {
126  }
127  unit_t(foot_u t) noexcept
128  : v{distance_u{t}}
129  {
130  }
131  unit_t(mile_u t) noexcept
132  : v{distance_u{t}}
133  {
134  }
135 
136  unit_t(gain_u t) noexcept
137  : v{t}
138  {
139  }
140  unit_t(linear_u t) noexcept
141  : v{gain_u{t}}
142  {
143  }
144  unit_t(midigain_u t) noexcept
145  : v{gain_u{t}}
146  {
147  }
148  unit_t(decibel_u t) noexcept
149  : v{gain_u{t}}
150  {
151  }
152  unit_t(decibel_raw_u t) noexcept
153  : v{gain_u{t}}
154  {
155  }
156 
157  unit_t(orientation_u t) noexcept
158  : v{t}
159  {
160  }
161  unit_t(quaternion_u t) noexcept
162  : v{orientation_u{t}}
163  {
164  }
165  unit_t(euler_u t) noexcept
166  : v{orientation_u{t}}
167  {
168  }
169  unit_t(axis_u t) noexcept
170  : v{orientation_u{t}}
171  {
172  }
173 
174  unit_t(position_u t) noexcept
175  : v{t}
176  {
177  }
178  unit_t(cartesian_3d_u t) noexcept
179  : v{position_u{t}}
180  {
181  }
182  unit_t(cartesian_2d_u t) noexcept
183  : v{position_u{t}}
184  {
185  }
186  unit_t(spherical_u t) noexcept
187  : v{position_u{t}}
188  {
189  }
190  unit_t(polar_u t) noexcept
191  : v{position_u{t}}
192  {
193  }
194  unit_t(aed_u t) noexcept
195  : v{position_u{t}}
196  {
197  }
198  unit_t(ad_u t) noexcept
199  : v{position_u{t}}
200  {
201  }
202  unit_t(opengl_u t) noexcept
203  : v{position_u{t}}
204  {
205  }
206  unit_t(cylindrical_u t) noexcept
207  : v{position_u{t}}
208  {
209  }
210  unit_t(azd_u t) noexcept
211  : v{position_u{t}}
212  {
213  }
214 
215  unit_t(speed_u t) noexcept
216  : v{t}
217  {
218  }
219  unit_t(meter_per_second_u t) noexcept
220  : v{speed_u{t}}
221  {
222  }
223  unit_t(miles_per_hour_u t) noexcept
224  : v{speed_u{t}}
225  {
226  }
227  unit_t(kilometer_per_hour_u t) noexcept
228  : v{speed_u{t}}
229  {
230  }
231  unit_t(knot_u t) noexcept
232  : v{speed_u{t}}
233  {
234  }
235  unit_t(foot_per_hour_u t) noexcept
236  : v{speed_u{t}}
237  {
238  }
239  unit_t(foot_per_second_u t) noexcept
240  : v{speed_u{t}}
241  {
242  }
243 
244  unit_t(timing_u t) noexcept
245  : v{t}
246  {
247  }
248  unit_t(second_u t) noexcept
249  : v{timing_u{t}}
250  {
251  }
252  unit_t(bark_u t) noexcept
253  : v{timing_u{t}}
254  {
255  }
256  unit_t(bpm_u t) noexcept
257  : v{timing_u{t}}
258  {
259  }
260  unit_t(cent_u t) noexcept
261  : v{timing_u{t}}
262  {
263  }
264  unit_t(frequency_u t) noexcept
265  : v{timing_u{t}}
266  {
267  }
268  unit_t(mel_u t) noexcept
269  : v{timing_u{t}}
270  {
271  }
272  unit_t(midi_pitch_u t) noexcept
273  : v{timing_u{t}}
274  {
275  }
276  unit_t(millisecond_u t) noexcept
277  : v{timing_u{t}}
278  {
279  }
280  unit_t(playback_speed_u t) noexcept
281  : v{timing_u{t}}
282  {
283  }
284 
285  template <typename T>
286  unit_t(T unit, typename T::is_unit* = nullptr) noexcept
287  : v{unit}
288  {
289  }
290 
291  auto which() const noexcept { return v.which(); }
292 
293  explicit operator bool() const noexcept { return bool(v); }
294 
295  friend bool operator==(const ossia::unit_t& unit, const ossia::unit_t& other) noexcept
296  {
297  return unit.v == other.v;
298  }
299 
300  friend bool operator!=(const ossia::unit_t& unit, const ossia::unit_t& other) noexcept
301  {
302  return unit.v != other.v;
303  }
304 };
305 
306 template <typename T>
307 struct is_unit
308 {
309  template <typename U>
310  static char test(typename U::is_unit* x);
311 
312  template <typename U>
313  static long test(U* x);
314 
315  static const bool value = sizeof(test<T>(0)) == 1;
316 };
317 
318 template <typename T, typename U>
319 typename std::enable_if_t<is_unit<T>::value && is_unit<U>::value, bool> operator==(T, U)
320 {
321  return false;
322 }
323 template <typename T, typename U>
324 typename std::enable_if_t<is_unit<T>::value && is_unit<U>::value, bool> operator!=(T, U)
325 {
326  return true;
327 }
328 
329 template <typename T>
330 typename std::enable_if_t<is_unit<T>::value, bool> operator==(T, T)
331 {
332  return true;
333 }
334 template <typename T>
335 typename std::enable_if_t<is_unit<T>::value, bool> operator!=(T, T)
336 {
337  return false;
338 }
339 
340 template <typename T, typename = void>
341 struct is_array_unit : public std::false_type
342 {
343 };
344 
345 template <typename T>
346 struct is_array_unit<T, decltype(T{}.array_parameters())> : public std::true_type
347 {
348 };
349 
350 static const constexpr int dataspace_count = 8;
351 static const constexpr int unit_count = 2 + 9 + 11 + 4 + 3 + 9 + 6 + 9;
352 }
353 namespace std
354 {
355 template <>
356 struct hash<ossia::distance_u>
357 {
358  std::size_t operator()(const ossia::distance_u& k) const { return k.which(); }
359 };
360 template <>
361 struct hash<ossia::position_u>
362 {
363  std::size_t operator()(const ossia::position_u& k) const { return k.which(); }
364 };
365 template <>
366 struct hash<ossia::speed_u>
367 {
368  std::size_t operator()(const ossia::speed_u& k) const { return k.which(); }
369 };
370 template <>
371 struct hash<ossia::orientation_u>
372 {
373  std::size_t operator()(const ossia::orientation_u& k) const { return k.which(); }
374 };
375 template <>
376 struct hash<ossia::angle_u>
377 {
378  std::size_t operator()(const ossia::angle_u& k) const { return k.which(); }
379 };
380 template <>
381 struct hash<ossia::color_u>
382 {
383  std::size_t operator()(const ossia::color_u& k) const { return k.which(); }
384 };
385 template <>
386 struct hash<ossia::gain_u>
387 {
388  std::size_t operator()(const ossia::gain_u& k) const { return k.which(); }
389 };
390 template <>
391 struct hash<ossia::timing_u>
392 {
393  std::size_t operator()(const ossia::timing_u& k) const { return k.which(); }
394 };
395 
396 template <>
397 struct hash<ossia::unit_t>
398 {
399  std::size_t operator()(const ossia::unit_t& v) const
400  {
401  std::size_t seed = 0;
402  if(v.v.which() != v.v.npos)
403  {
404  ossia::hash_combine(seed, v.v.which());
405  ossia::apply_nonnull([&](auto& d) { ossia::hash_combine(seed, d.which()); }, v.v);
406  }
407  return seed;
408  }
409 };
410 }
The value class.
Definition: value.hpp:173
Definition: git_info.h:7
Definition: dataspace.hpp:24