OSSIA
Open Scenario System for Interactive Application
dataspace_convert.hpp
1 #pragma once
2 #include <ossia/network/dataspace/dataspace_variant_visitors.hpp>
4 #include <ossia/network/dataspace/value_with_unit.hpp>
6 namespace ossia::detail
7 {
8 
9 template <typename T, typename U>
10 struct convert_unit_helper
11 {
12  OSSIA_INLINE ossia::value_with_unit
13  operator()(const strong_value<T>& value, const U& unit)
14  {
15  return strong_value<U>(value);
16  }
17 };
18 
19 struct convert_unit_visitor
20 {
21  template <typename T, typename U>
22  OSSIA_INLINE ossia::value_with_unit
23  operator()(const strong_value<T>& value, const U& unit)
24  {
25  return convert_unit_helper<T, U>{}(value, unit);
26  }
27 
28  template <typename T, typename U>
29  OSSIA_INLINE ossia::value_with_unit operator()(const T& d1, const U& d2)
30  {
31  return {};
32  }
33 
34  OSSIA_INLINE ossia::value_with_unit operator()(const angle& d1, const angle_u& d2)
35  {
36  return ossia::apply(*this, d1, d2);
37  }
38  OSSIA_INLINE ossia::value_with_unit operator()(const color& d1, const color_u& d2)
39  {
40  return ossia::apply(*this, d1, d2);
41  }
42  OSSIA_INLINE ossia::value_with_unit
43  operator()(const distance& d1, const distance_u& d2)
44  {
45  return ossia::apply(*this, d1, d2);
46  }
47  OSSIA_INLINE ossia::value_with_unit
48  operator()(const orientation& d1, const orientation_u& d2)
49  {
50  return ossia::apply(*this, d1, d2);
51  }
52  OSSIA_INLINE ossia::value_with_unit operator()(const gain& d1, const gain_u& d2)
53  {
54  return ossia::apply(*this, d1, d2);
55  }
56  OSSIA_INLINE ossia::value_with_unit
57  operator()(const position& d1, const position_u& d2)
58  {
59  return ossia::apply(*this, d1, d2);
60  }
61  OSSIA_INLINE ossia::value_with_unit operator()(const speed& d1, const speed_u& d2)
62  {
63  return ossia::apply(*this, d1, d2);
64  }
65  OSSIA_INLINE ossia::value_with_unit operator()(const timing& d1, const timing_u& d2)
66  {
67  return ossia::apply(*this, d1, d2);
68  }
69 };
70 
71 struct convert_to_value_visitor
72 {
73  OSSIA_INLINE ossia::value operator()(const angle& d1)
74  {
75  return ossia::apply(*this, d1);
76  }
77  OSSIA_INLINE ossia::value operator()(const color& d1)
78  {
79  return ossia::apply(*this, d1);
80  }
81  OSSIA_INLINE ossia::value operator()(const distance& d1)
82  {
83  return ossia::apply(*this, d1);
84  }
85  OSSIA_INLINE ossia::value operator()(const orientation& d1)
86  {
87  return ossia::apply(*this, d1);
88  }
89  OSSIA_INLINE ossia::value operator()(const gain& d1)
90  {
91  return ossia::apply(*this, d1);
92  }
93  OSSIA_INLINE ossia::value operator()(const position& d1)
94  {
95  return ossia::apply(*this, d1);
96  }
97  OSSIA_INLINE ossia::value operator()(const speed& d1)
98  {
99  return ossia::apply(*this, d1);
100  }
101  OSSIA_INLINE ossia::value operator()(const timing& d1)
102  {
103  return ossia::apply(*this, d1);
104  }
105 
106  template <typename T>
107  OSSIA_INLINE ossia::value operator()(const strong_value<T>& val)
108  {
109  return val.dataspace_value;
110  }
111 
112  OSSIA_INLINE ossia::value operator()(ossia::value val) { return val; }
113 
114  OSSIA_INLINE ossia::value operator()() { return {}; }
115 };
116 
117 struct convert_to_unit_visitor
118 {
119  OSSIA_INLINE ossia::unit_t operator()(const angle& d1)
120  {
121  return ossia::apply(*this, d1);
122  }
123  OSSIA_INLINE ossia::unit_t operator()(const color& d1)
124  {
125  return ossia::apply(*this, d1);
126  }
127  OSSIA_INLINE ossia::unit_t operator()(const distance& d1)
128  {
129  return ossia::apply(*this, d1);
130  }
131  OSSIA_INLINE ossia::unit_t operator()(const orientation& d1)
132  {
133  return ossia::apply(*this, d1);
134  }
135  OSSIA_INLINE ossia::unit_t operator()(const gain& d1)
136  {
137  return ossia::apply(*this, d1);
138  }
139  OSSIA_INLINE ossia::unit_t operator()(const position& d1)
140  {
141  return ossia::apply(*this, d1);
142  }
143  OSSIA_INLINE ossia::unit_t operator()(const speed& d1)
144  {
145  return ossia::apply(*this, d1);
146  }
147  OSSIA_INLINE ossia::unit_t operator()(const timing& d1)
148  {
149  return ossia::apply(*this, d1);
150  }
151 
152  template <typename T>
153  OSSIA_INLINE ossia::unit_t operator()(const T&)
154  {
155  return typename T::unit_type{};
156  }
157 
158  OSSIA_INLINE ossia::unit_t operator()(ossia::value val) { return {}; }
159 
160  OSSIA_INLINE ossia::unit_t operator()() { return {}; }
161 };
162 }
The value class.
Definition: value.hpp:173
Definition: transitive_closure.hpp:27
Definition: dataspace.hpp:24
Definition: value_with_unit.hpp:13