3 #include <ossia/network/dataspace/value_with_unit.hpp>
21 static const constexpr
bool value = value_trait<std::remove_const_t<T>>
::is_array;
24 template <
typename T,
typename U,
typename =
void>
25 struct whole_value_merger_helper;
28 using strong_value_impl_t = decltype(T::dataspace_value);
30 template <
typename T,
typename U>
31 const constexpr
bool both_iterable
32 = is_array<strong_value_impl_t<T>>::value&& is_array<U>::value&&
33 ossia::value_trait<U>::ossia_enum
35 template <
typename T,
typename U>
36 const constexpr
bool first_iterable
37 = is_array<strong_value_impl_t<T>>::value && !is_array<U>::value;
38 template <
typename T,
typename U>
39 const constexpr
bool second_iterable
40 = !is_array<strong_value_impl_t<T>>::value && is_array<U>::value
42 template <
typename T,
typename U>
43 const constexpr
bool neither_iterable
44 = !is_array<strong_value_impl_t<T>>::value && !is_array<U>::value;
46 template <
typename T,
typename U>
47 using enable_if_both_iterable = std::enable_if_t<both_iterable<T, U>>;
48 template <
typename T,
typename U>
49 using enable_if_first_iterable = std::enable_if_t<first_iterable<T, U>>;
50 template <
typename T,
typename U>
51 using enable_if_second_iterable = std::enable_if_t<second_iterable<T, U>>;
52 template <
typename T,
typename U>
53 using enable_if_neither_iterable = std::enable_if_t<neither_iterable<T, U>>;
57 template <
typename T,
typename U>
58 struct whole_value_merger_helper<T, U, enable_if_both_iterable<T, U>>
63 const auto n =
std::min(value_unit.dataspace_value.size(), value.size());
64 for(std::size_t i = 0; i < n; i++)
66 value_unit.dataspace_value[i] = ossia::convert<
67 std::remove_reference_t<decltype(value_unit.dataspace_value[i])>>(value[i]);
74 template <
typename T,
typename U>
75 struct whole_value_merger_helper<T, U, enable_if_first_iterable<T, U>>
84 template <
typename T,
typename U>
85 struct whole_value_merger_helper<T, U, enable_if_second_iterable<T, U>>
94 template <
typename T,
typename U>
95 struct whole_value_merger_helper<T, U, enable_if_neither_iterable<T, U>>
99 value_unit.dataspace_value = value;
104 template <
typename T,
typename U,
typename =
void>
105 struct partial_value_merger_helper;
112 template <
typename T,
typename U>
113 struct partial_value_merger_helper<T, U, enable_if_both_iterable<T, U>>
119 if((int64_t)value_unit.dataspace_value.size() > i && (int64_t)value.size() > i)
121 value_unit.dataspace_value[i] = ossia::convert<
122 std::remove_reference_t<decltype(value_unit.dataspace_value[i])>>(value[i]);
128 template <std::
size_t N>
130 operator()(T value_unit,
const U& value,
const std::bitset<N>& idx)
132 if(handle_vec(value_unit.dataspace_value, value, idx))
137 template <std::
size_t N>
139 std::array<float, N>& src,
const std::array<float, N>& incoming,
140 const std::bitset<N>& idx)
142 for(std::size_t i = 0; i < N; i++)
146 src[i] = incoming[i];
152 template <
typename... Args>
153 OSSIA_INLINE
bool handle_vec(Args&&...)
159 template <
typename T,
typename U>
160 struct partial_value_merger_helper<T, U, enable_if_first_iterable<T, U>>
166 value_unit.dataspace_value[i] = ossia::convert<
167 std::remove_reference_t<decltype(value_unit.dataspace_value[i])>>(value);
171 template <std::
size_t N>
173 operator()(T value_unit,
const U& value,
const std::bitset<N>& idx)
179 template <
typename T,
typename U>
180 struct partial_value_merger_helper<T, U, enable_if_second_iterable<T, U>>
188 template <std::
size_t N>
190 operator()(T value_unit,
const U& value,
const std::bitset<N>& idx)
196 template <
typename T,
typename U>
197 struct partial_value_merger_helper<T, U, enable_if_neither_iterable<T, U>>
205 template <std::
size_t N>
207 operator()(T value_unit,
const U& value,
const std::bitset<N>& idx)
217 template <
typename T,
typename U>
220 auto n = index.size();
224 return whole_value_merger_helper<strong_value<T>, U>{}(value_unit, value);
227 return partial_value_merger_helper<strong_value<T>, U>{}(
228 value_unit, value, index);
235 template <
typename T>
237 operator()(
const strong_value<T>& value_unit, impulse value)
241 template <
typename T>
243 operator()(
const strong_value<T>& value_unit,
const value_map_type& value)
247 template <
typename T>
249 operator()(
const strong_value<T>& value_unit,
const std::string& value)
255 template <std::
size_t N>
256 struct vec_value_merger
258 const std::bitset<N>& index;
260 template <
typename T,
typename U>
262 operator()(
const strong_value<T>& value_unit,
const U& value)
267 template <
typename T>
269 operator()(
const strong_value<T>& value_unit,
const std::array<float, N>& value)
272 return whole_value_merger_helper<strong_value<T>, std::array<float, N>>{}(
275 return partial_value_merger_helper<strong_value<T>, std::array<float, N>>{}(
276 value_unit, value, index);
bool is_array(const ossia::value &val)
is_numeric True if the value is of an array type (list, vec...)
Definition: value.cpp:631
constexpr OSSIA_INLINE auto min(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
min function tailored for values
Definition: math.hpp:125
ossia::small_vector< int32_t, 2 > destination_index
Definition: destination_index.hpp:40
Definition: value_with_unit.hpp:13