OSSIA
Open Scenario System for Interactive Application
make_value.hpp
1 #pragma once
2 #include <ossia/network/dataspace/dataspace.hpp>
4 
5 namespace ossia
6 {
7 
8 template <typename U, typename V>
9 struct make_value_helper;
10 
11 template <typename U>
12 struct make_value_helper<U, float>
13 {
14 
15  template <typename T>
16  OSSIA_INLINE ossia::value_with_unit operator()(const T& t)
17  {
18  // TODO maybe return first value for list or vecNf ?
19  // throw std::runtime_error("mismatching value type and unit");
20  return {};
21  }
22 
23  OSSIA_INLINE ossia::value_with_unit operator()(int32_t t)
24  {
25  return strong_value<U>(float(t));
26  }
27  OSSIA_INLINE ossia::value_with_unit operator()(float t)
28  {
29  return strong_value<U>(float(t));
30  }
31  OSSIA_INLINE ossia::value_with_unit operator()(char t)
32  {
33  return strong_value<U>(float(t));
34  }
35  OSSIA_INLINE ossia::value_with_unit operator()(bool t)
36  {
37  return strong_value<U>(float(t));
38  }
39 };
40 
41 template <typename U>
42 struct make_value_helper<U, ossia::vec2f>
43 {
44 
45  template <typename T>
46  OSSIA_INLINE ossia::value_with_unit operator()(const T& t)
47  {
48  // throw std::runtime_error("mismatching value type and unit");
49  return {};
50  }
51 
52  OSSIA_INLINE ossia::value_with_unit operator()(const std::vector<ossia::value>& t)
53  {
54  return strong_value<U>{ossia::convert<std::array<float, 2>>(t)};
55  }
56 
57  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec2f t)
58  {
59  return strong_value<U>{t};
60  }
61  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec3f t)
62  {
63  return strong_value<U>{ossia::make_vec(t[0], t[1])};
64  }
65  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec4f t)
66  {
67  return strong_value<U>{ossia::make_vec(t[0], t[1])};
68  }
69 };
70 
71 template <typename U>
72 struct make_value_helper<U, ossia::vec3f>
73 {
74 
75  template <typename T>
76  OSSIA_INLINE ossia::value_with_unit operator()(const T& t)
77  {
78  // throw std::runtime_error("mismatching value type and unit");
79  return {};
80  }
81 
82  OSSIA_INLINE ossia::value_with_unit operator()(const std::vector<ossia::value>& t)
83  {
84  return strong_value<U>{ossia::convert<std::array<float, 3>>(t)};
85  }
86 
87  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec2f t)
88  {
89  return strong_value<U>{ossia::make_vec(t[0], t[1], 0.)};
90  }
91  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec3f t)
92  {
93  return strong_value<U>{t};
94  }
95  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec4f t)
96  {
97  return strong_value<U>{ossia::make_vec(t[0], t[1], t[2])};
98  }
99 };
100 
101 template <typename U>
102 struct make_value_helper<U, ossia::vec4f>
103 {
104 
105  template <typename T>
106  OSSIA_INLINE ossia::value_with_unit operator()(const T& t)
107  {
108  // throw std::runtime_error("mismatching value type and unit");
109  return {};
110  }
111 
112  OSSIA_INLINE ossia::value_with_unit operator()(const std::vector<ossia::value>& t)
113  {
114  return strong_value<U>{ossia::convert<std::array<float, 4>>(t)};
115  }
116 
117  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec2f t)
118  {
119  return strong_value<U>{ossia::make_vec(t[0], t[1], 0., 0.)};
120  }
121  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec3f t)
122  {
123  return strong_value<U>{ossia::make_vec(t[0], t[1], t[2], 0.)};
124  }
125  OSSIA_INLINE ossia::value_with_unit operator()(ossia::vec4f t)
126  {
127  return strong_value<U>{t};
128  }
129 };
130 
131 struct make_value_with_unit_visitor
132 {
133  template <typename Val, typename Unit>
134  OSSIA_INLINE ossia::value_with_unit operator()(const Val& v, const Unit& u)
135  {
136  return make_value_helper<Unit, typename Unit::value_type>{}(v);
137  }
138 };
139 }
Definition: git_info.h:7
Definition: value_with_unit.hpp:13