11 #ifndef RTIREFLEX_MEMBERWISE_H
12 #define RTIREFLEX_MEMBERWISE_H
15 #include <type_traits>
17 #include "ndds/ndds_cpp.h"
27 struct Too_Many_Indices;
29 template <
class T,
class Indices>
32 typedef Too_Many_Indices
type;
35 template <
class... Args,
int Head,
int... Tail>
38 typedef typename std::tuple_element<Head, std::tuple<Args...>>
::type TE;
42 template <
class... Args,
int Head>
45 typedef typename std::tuple_element<Head, std::tuple<Args...>>
::type type;
48 template <
class TagType,
class... Args,
int Head,
int... Tail>
52 typedef typename std::tuple_element<Head, CaseTuple>::type
Case;
56 template <
class TagType,
class... Args,
int Head>
60 typedef typename std::tuple_element<Head, CaseTuple>::type
Case;
61 typedef typename Case::type
type;
64 template <
class... Args,
int Head,
int... Tail>
68 typedef typename std::tuple_element<Head, RawTuple>::type
Raw;
72 template <
class... Args,
int Head>
76 typedef typename std::tuple_element<Head, RawTuple>::type
type;
79 template <
class T,
int Head,
int... Tail>
85 template <
class T,
int Head>
99 void set_member_by_index(DDS_DynamicData &instance,
107 void set_member_by_name(DDS_DynamicData &instance,
115 void recurse_and_set(DDS_DynamicData &outer,
116 const std::vector<int> & bind_points,
120 if (i < bind_points.size() - 1)
122 DDS_DynamicData inner(NULL, DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);
123 SafeBinder binder(outer, inner, MemberAccess::BY_ID(bind_points[i] + 1));
124 recurse_and_set(inner, bind_points, i + 1, val);
127 set_member_by_index(outer, bind_points[i], val);
131 void recurse_and_set(DDS_DynamicData &outer,
132 const std::vector<const char *> & bind_points,
136 if (i < bind_points.size() - 1)
138 DDS_DynamicData inner(NULL, DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);
139 SafeBinder binder(outer, inner, MemberAccess::BY_NAME(bind_points[i]));
140 recurse_and_set(inner, bind_points, i + 1, val);
143 set_member_by_name(outer, bind_points[i], val);
147 void set_member_by_indices(DDS_DynamicData &instance,
148 std::vector<int> indices,
151 recurse_and_set(instance, indices, 0, val);
155 void set_member_by_names(DDS_DynamicData &instance,
156 std::vector<const char *> names,
159 recurse_and_set(instance, names, 0, val);
163 void set_member(DDS_DynamicData &instance,
170 template <
class T,
class Tuple,
class Indices>
171 struct TraverseTupleByIndices;
173 template <
class T,
class Tuple,
int Head,
int... Tail>
174 struct TraverseTupleByIndices<T, Tuple, meta::indices<Head, Tail...>>
176 static void exec(DDS_DynamicData & outer,
const T & val)
178 std::cerr <<
"binding " << Head <<
"\n";
179 DDS_DynamicData inner(NULL, DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);
180 SafeBinder binder(outer, inner, MemberAccess::BY_ID(Head + 1));
181 TraverseTupleByIndices<T, Tuple, meta::indices<Tail...>>::exec(inner, val);
182 std::cerr <<
"unbinding\n";
186 template <
class T,
class Tuple,
int Last>
187 struct TraverseTupleByIndices<T, Tuple, meta::indices<Last>>
189 static void exec(DDS_DynamicData & outer,
const T & val)
191 std::cerr <<
"set_member_by_index Last = " << Last;
192 set_member_by_index(outer, Last, val);
193 std::cerr <<
"set_member_by_index Last = " << Last;
197 template <
class T,
class Tuple,
int Head,
int... I>
198 void set_member_by_indices(DDS_DynamicData &instance,
202 typedef typename meta::get_nested_type<Tuple, meta::indices<Head, I...>>::type Nested;
203 static_assert(std::is_same<Nested, T>::value,
"The types don't match");
204 TraverseTupleByIndices<T, Tuple, meta::indices<Head, I...>>::exec(instance, val);
211 #endif // RTIREFLEX_MEMBERWISE_H
Definition: disc_union.h:139
Definition: disc_union.h:27