11 #ifndef RTIREFLEX_TUPLE_ITERATOR_H
12 #define RTIREFLEX_TUPLE_ITERATOR_H
15 #include <type_traits>
18 #include <ndds/ndds_cpp.h>
24 #define UNUSED_VAR(i) do { (void)(i); } while (0)
31 void set_member_forward(
32 DDS_DynamicData & instance,
33 const MemberAccess &ma,
37 void get_member_forward(
38 const DDS_DynamicData & instance,
39 const MemberAccess &ma,
43 void add_member_forward(
44 DDS_TypeCodeFactory * factory,
45 DDS_TypeCode * outerTc,
46 const char * member_name,
52 void case_add_forward(
53 DDS_TypeCodeFactory * factory,
54 const char * member_name,
55 DDS_UnionMember & umember);
58 void deleteTc_forward(
59 DDS_TypeCodeFactory * factory,
62 template <
class Typelist,
66 const DDS_DynamicData &instance,
67 const MemberAccess & ma,
68 int discriminator_value,
72 if (CaseI::matches(discriminator_value))
74 typename CaseI::type * data_ptr = reflex::meta::get<I>(val.get_caseptr_tuple());
75 bool data_in_case_ptr = data_ptr ?
true :
false;
77 if (data_in_case_ptr ==
false)
86 val.get_variant() = CaseI();
87 data_ptr = &(boost::get<CaseI>(val.get_variant()).
get());
90 if (ma.access_by_id())
93 MemberAccess::BY_ID(discriminator_value),
103 MemberAccess::BY_NAME(info.
name.c_str()),
106 if (data_in_case_ptr)
107 val.set_active_index(I);
114 template <
class Typelist,
118 DDS_DynamicData &instance,
119 const MemberAccess & ma,
123 if ((I == val.get_active_index()) ||
124 (I == val.get_variant().which() - 1))
127 typename CaseI::type
const * data_ptr =
128 reflex::meta::get<I>(val.get_caseptr_tuple()) ? :
129 &(boost::get<CaseI>(val.get_variant()).
get());
131 if (ma.access_by_id())
134 MemberAccess::BY_ID(CaseI::discriminator),
144 MemberAccess::BY_NAME(info.
name.c_str()),
153 template <
class Typelist,
155 unsigned int MAX_INDEX>
156 struct TypelistIterator
158 typedef TypelistIterator<
164 DDS_DynamicData & instance,
165 const MemberAccess &ma,
166 const Typelist & tuple)
171 std::string member_name =
175 if (ma.access_by_id())
177 set_member_forward(instance, ma, reflex::meta::get<I>(tuple));
178 Next::set(instance, ma + 1, tuple);
187 MemberAccess::BY_NAME(info.
name.c_str()),
188 reflex::meta::get<I>(tuple));
190 Next::set(instance, ma, tuple);
195 const DDS_DynamicData & instance,
196 const MemberAccess &ma,
202 std::string member_name =
205 if (ma.access_by_id())
207 get_member_forward(instance, ma, reflex::meta::get<I>(tuple));
218 MemberAccess::BY_NAME(info.
name.c_str()),
219 reflex::meta::get<I>(tuple));
225 DDS_TypeCodeFactory * factory,
226 DDS_TypeCode * outer_structTc)
231 std::string member_name =
243 add_member_forward(factory,
248 static_cast<InnerNoRef *
>(0));
250 Next::add(factory, outer_structTc);
253 static void add_union_member(
254 DDS_TypeCodeFactory * factory,
255 DDS_UnionMemberSeq & seq)
264 case_add_forward<CaseI>(factory, info.
name.c_str(), seq[I]);
266 Next::add_union_member(factory, seq);
269 static void delete_typecodes(
270 DDS_TypeCodeFactory * factory,
271 DDS_UnionMemberSeq & seq)
275 deleteTc_forward<CaseTypeNoRef>(
277 const_cast<DDS_TypeCode *
>(seq[I].type));
278 Next::delete_typecodes(factory, seq);
281 template <
class TUnion>
282 static void set_union(
283 DDS_DynamicData &instance,
284 const MemberAccess & ma,
287 if (!set_union_case<Typelist, I>(instance, ma, val))
288 Next::set_union(instance, ma, val);
291 template <
class TUnion>
292 static void get_union(
293 const DDS_DynamicData &instance,
294 const MemberAccess & ma,
295 int discriminator_value,
298 if (!get_union_case<Typelist, I>(instance, ma, discriminator_value, val))
299 Next::get_union(instance, ma, discriminator_value, val);
303 template <
class Typelist,
304 unsigned int MAX_INDEX>
305 struct TypelistIterator<Typelist, MAX_INDEX, MAX_INDEX>
308 DDS_DynamicData & instance,
309 const MemberAccess &ma,
310 const Typelist & tuple)
313 unsigned max = MAX_INDEX;
315 std::string member_name =
319 if (ma.access_by_id())
321 set_member_forward(instance, ma, reflex::meta::get<MAX_INDEX>(tuple));
327 MAX_INDEX>::member_info();
331 MemberAccess::BY_NAME(info.
name.c_str()),
332 reflex::meta::get<MAX_INDEX>(tuple));
336 static void get(
const DDS_DynamicData & instance,
337 const MemberAccess &ma,
341 unsigned max = MAX_INDEX;
343 std::string member_name =
347 if (ma.access_by_id())
349 get_member_forward(instance, ma, reflex::meta::get<MAX_INDEX>(tuple));
355 MAX_INDEX>::member_info();
359 MemberAccess::BY_NAME(info.
name.c_str()),
360 reflex::meta::get<MAX_INDEX>(tuple));
365 DDS_TypeCodeFactory * factory,
366 DDS_TypeCode * outer_structTc)
369 unsigned max = MAX_INDEX;
371 std::string member_name =
380 MAX_INDEX>::member_info();
382 add_member_forward(factory,
387 static_cast<InnerNoRef *
>(0));
390 static void add_union_member(
391 DDS_TypeCodeFactory * factory,
392 DDS_UnionMemberSeq & seq)
397 MAX_INDEX>::member_info();
399 case_add_forward<CaseI>(factory, info.
name.c_str(), seq[MAX_INDEX]);
402 static void delete_typecodes(
403 DDS_TypeCodeFactory * factory,
404 DDS_UnionMemberSeq & seq)
408 deleteTc_forward<CaseTypeNoRef>(
410 const_cast<DDS_TypeCode *
>(seq[MAX_INDEX].type));
413 template <
class TUnion>
414 static void set_union(
415 DDS_DynamicData &instance,
416 const MemberAccess & ma,
419 if (!set_union_case<Typelist, MAX_INDEX>(instance, ma, val))
421 throw std::runtime_error(
"set_union: Union was empty");
425 template <
class TUnion>
426 static void get_union(
427 const DDS_DynamicData &instance,
428 const MemberAccess & ma,
429 int discriminator_value,
432 if (!get_union_case<Typelist, MAX_INDEX>(
438 std::stringstream stream;
439 stream <<
"get_union: No match for the discriminator. "
440 <<
"Did you forget to set a union member? "
441 <<
"Discriminator value = "
442 << discriminator_value;
443 throw std::runtime_error(stream.str());
452 #endif // RTIREFLEX_TUPLE_ITERATOR_H
std::string name
Definition: member_names.h:49
unsigned char value
Definition: member_names.h:50
Definition: member_names.h:47
static MemberInfo member_info()
Definition: member_names.h:76
#define UNUSED_VAR(i)
Definition: tuple_iterator.h:24
Definition: member_names.h:74