RefleX
Build DDS Applications in Modern C++ without IDL
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
reflex.h
Go to the documentation of this file.
1 /*********************************************************************************************
2 (c) 2005-2014 Copyright, Real-Time Innovations, Inc. All rights reserved.
3 RTI grants Licensee a license to use, modify, compile, and create derivative works
4 of the Software. Licensee has the right to distribute object form only for use with RTI
5 products. The Software is provided "as is", with no warranty of any type, including
6 any warranty for fitness for any purpose. RTI is under no obligation to maintain or
7 support the Software. RTI shall not be liable for any incidental or consequential
8 damages arising out of the use or inability to use the software.
9 **********************************************************************************************/
10 
11 #ifndef RTIREFLEX_H
12 #define RTIREFLEX_H
13 
14 #include <ndds/ndds_cpp.h>
15 #include <tuple>
16 #include <vector>
17 
18 #include "reflex/sample.h"
19 #include "reflex/auto_dd.h"
20 #include "reflex/dllexport.h"
21 #include "reflex/dd_manip.h"
22 #include "reflex/typecode_manip.h"
23 #include "reflex/member_names.h"
24 #include "reflex/memberwise.h"
25 #include "reflex/bounded.h"
26 #include "reflex/generic_dr.h"
27 #include "reflex/generic_dw.h"
29 #include "reflex/type_manager.h"
30 #include "reflex/reflex_fwd.h"
31 
32 #include <boost/fusion/sequence/intrinsic/size.hpp>
33 #include <boost/fusion/include/size.hpp>
34 
39 namespace reflex {
40 
41  namespace detail {
42 
43  template <class T, class U>
44  struct MembersInBasesImpl;
45 
46  template <class T>
47  struct MembersInBasesImpl<T, reflex::meta::false_type>
48  {
49  enum { value = 0 };
50  };
51 
52  template <class T>
53  struct MembersInBasesImpl<T, reflex::meta::true_type>
54  {
57 
58  enum {
59  value = MembersInBasesImpl<Base, BaseHasBase>::value +
61  };
62  };
63 
64  template <class T>
65  struct MembersInBases
66  {
68  enum { value = MembersInBasesImpl<T, HasBase>::value };
69  };
70 
71 
72  template <class T>
73  void write_dynamicdata_impl(
74  const T & data,
75  DDS_DynamicData &instance,
76  reflex::meta::false_type /* T has no base */)
77  {
78  typedef detail::TypelistIterator<
79  T,
80  0,
82 
83  TIter::set(
84  instance,
85  detail::MemberAccess::BY_ID(1),
86  data);
87  }
88 
89  template <class T>
90  void write_dynamicdata_impl(
91  const T & data,
92  DDS_DynamicData &instance,
93  reflex::meta::true_type /* T has a base */)
94  {
96 
97  write_dynamicdata_impl(
98  static_cast<const Base &>(data),
99  instance,
101 
102  typedef detail::TypelistIterator<
103  T,
104  0,
105  reflex::meta::size<T>::value - 1> TIter;
106 
107  TIter::set(
108  instance,
109  detail::MemberAccess::BY_ID(MembersInBases<T>::value + 1),
110  data);
111  }
112 
113  template <class T>
114  void read_dynamicdata_impl(
115  const DDS_DynamicData & instance,
116  T & data,
117  reflex::meta::false_type /* T has no base*/)
118  {
119  typedef detail::TypelistIterator<
120  T,
121  0,
122  reflex::meta::size<T>::value - 1> TIter;
123 
124  TIter::get(
125  instance,
126  detail::MemberAccess::BY_ID(1),
127  data);
128  }
129 
130  template <class T>
131  void read_dynamicdata_impl(
132  const DDS_DynamicData & instance,
133  T & data,
134  reflex::meta::true_type /* T has a base*/)
135  {
137 
138  read_dynamicdata_impl(
139  instance,
140  static_cast<Base &>(data),
142 
143  typedef detail::TypelistIterator<
144  T,
145  0,
146  reflex::meta::size<T>::value - 1> TIter;
147 
148  TIter::get(
149  instance,
150  detail::MemberAccess::BY_ID(MembersInBases<T>::value + 1),
151  data);
152  }
153 
154  } // namespace detail
155 
156  template <class T>
157  void write_dynamicdata(DDS_DynamicData &dest, const T & src)
158  {
159  detail::write_dynamicdata_impl(
160  src,
161  dest,
163  }
164 
165  template <class T>
166  void write_dynamicdata(AutoDynamicData &dest, const T & src)
167  {
168  detail::write_dynamicdata_impl(
169  src,
170  *dest.get(),
172  }
173 
174  template <class T>
175  SafeTypeCode<T> make_typecode(const char * name /* default 0 */)
176  {
177  SafeTypeCode<T> aggregateTc =
178  detail::Struct_TC_Helper::get_typecode_struct<T>(
179  name,
181 
182  return aggregateTc;
183  }
184 
185  template <class T>
186  void read_dynamicdata(T & dest, const DDS_DynamicData & src)
187  {
188  detail::read_dynamicdata_impl(
189  src,
190  dest,
192  }
193 
194  template <class T>
195  void read_dynamicdata(T & dest, const AutoDynamicData & src)
196  {
197  detail::read_dynamicdata_impl(
198  *src.get(),
199  dest,
201  }
202 
203 } // namespace reflex
204 
205 
206 
207 #ifndef REFLEX_NO_HEADER_ONLY
208 #include "reflex/../../src/reflex.cxx"
209 #endif
210 
211 
212 #endif // RTIREFLEX_H
213 
void write_dynamicdata(DDS_DynamicData &dest, const T &src)
Copies source data into the destination DDS_DynamicData instance.
Definition: reflex.h:157
SafeTypeCode< T > make_typecode(const char *name)
Creates a TypeCode for structured type T.
Definition: reflex.h:175
Definition: enable_if.h:115
Definition: enable_if.h:679
DDS_DynamicData * get()
Return the underlying DynamicData instance.
Definition: auto_dd.cxx:98
Automatically manages the memory of a DynamicData instance.
Definition: auto_dd.h:33
disable_if_lazy< reflex::type_traits::is_tuple< FusionSeq >::value, at< FusionSeq, I > >::type get(FusionSeq &seq)
Definition: enable_if.h:714
void read_dynamicdata(T &dest, const DDS_DynamicData &src)
Extracts data out from the source DDS_DynamicData instance and copies into the destination object of ...
Definition: reflex.h:186
Definition: enable_if.h:466
reflex::meta::false_type has_base
Definition: enable_if.h:467
A type-safe, exception-safe wrapper for DDS TypeCode.
Definition: reflex_fwd.h:27
Definition: enable_if.h:119