RefleX
Build DDS Applications in Modern C++ without IDL
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
dd_extra.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_DD_EXTRA_H
12 #define RTIREFLEX_DD_EXTRA_H
13 
14 #include <string>
15 #include "ndds/ndds_cpp.h"
16 #include "reflex/dllexport.h"
17 
18 #ifdef RTI_WIN32
19 #include <stdint.h>
20 #endif
21 
22 #define SET_SEQUENCE_DECL(DDS_SEQ_TYPE) \
23 REFLEX_DLL_EXPORT DDS_ReturnCode_t set_sequence(DDS_DynamicData &instance, \
24  const MemberAccess & ma, \
25  const DDS_SEQ_TYPE &value);
26 
27 #define GET_SEQUENCE_DECL(DDS_SEQ_TYPE) \
28 REFLEX_DLL_EXPORT DDS_ReturnCode_t get_sequence(const DDS_DynamicData & instance, \
29  DDS_SEQ_TYPE &seq, \
30  const MemberAccess & ma);
31 
32 #define SET_ARRAY_DECL(BASIC_TYPE) \
33 REFLEX_DLL_EXPORT DDS_ReturnCode_t set_array(DDS_DynamicData &instance, \
34  const MemberAccess & ma, \
35  DDS_UnsignedLong length, \
36  const BASIC_TYPE *array);
37 
38 #define GET_ARRAY_DECL(BASIC_TYPE) \
39 REFLEX_DLL_EXPORT DDS_ReturnCode_t get_array(const DDS_DynamicData & instance, \
40  BASIC_TYPE *array, \
41  DDS_UnsignedLong *length, \
42  const MemberAccess & ma);
43 
44 namespace reflex {
45 
46  namespace match {
47 
48  typedef unsigned char octet_t;
49 
50  }
51 
52  namespace detail {
53 
54  REFLEX_DLL_EXPORT const char *get_readable_retcode(DDS_ReturnCode_t rc);
55  REFLEX_DLL_EXPORT const char *get_readable_ex_code(DDS_ExceptionCode_t ex);
56  REFLEX_DLL_EXPORT void check_retcode(const char * message, DDS_ReturnCode_t rc);
57  REFLEX_DLL_EXPORT void check_exception_code(const char * message, DDS_ExceptionCode_t ex);
58 
59  class REFLEX_DLL_EXPORT MemberAccess
60  {
61  bool is_valid_id_;
62  int id_;
63  const char *name_;
64 
65  MemberAccess(
66  bool is_valid_id,
67  int id,
68  const char *name);
69 
70  public:
71  bool access_by_id() const;
72  bool access_by_name() const;
73  int get_id() const;
74  const char * get_name() const;
75  MemberAccess operator + (int i) const;
76 
77  static MemberAccess BY_ID(int id);
78  static MemberAccess BY_NAME(const char *name = 0);
79  };
80 
81  class REFLEX_DLL_EXPORT SafeBinder
82  {
83  private:
84  struct proxy {
85  DDS_DynamicData *outer_;
86  DDS_DynamicData *inner_;
87  };
88 
89  DDS_DynamicData * outer_;
90  DDS_DynamicData * inner_;
91 
92  SafeBinder(SafeBinder &);
93  SafeBinder& operator = (SafeBinder &);
94 
95  public:
96  SafeBinder();
97 
98  SafeBinder(const DDS_DynamicData & outer,
99  DDS_DynamicData & inner,
100  const char * member_name,
101  DDS_Long member_id);
102 
103  SafeBinder(const DDS_DynamicData & outer,
104  DDS_DynamicData & inner,
105  const MemberAccess &ma);
106 
107  ~SafeBinder() throw();
108 
109  SafeBinder(proxy p) throw();
110 
111  void swap(SafeBinder & sb) throw();
112 
113  SafeBinder & operator = (proxy p) throw();
114 
115  operator proxy () throw();
116 
117  friend SafeBinder move(SafeBinder & sb) throw();
118  };
119 
120 
121  SET_SEQUENCE_DECL(DDS_LongSeq)
122  SET_SEQUENCE_DECL(DDS_ShortSeq)
123  SET_SEQUENCE_DECL(DDS_UnsignedLongSeq)
124  SET_SEQUENCE_DECL(DDS_UnsignedShortSeq)
125  SET_SEQUENCE_DECL(DDS_FloatSeq)
126  SET_SEQUENCE_DECL(DDS_DoubleSeq)
127  SET_SEQUENCE_DECL(DDS_LongDoubleSeq)
128  SET_SEQUENCE_DECL(DDS_BooleanSeq)
129  SET_SEQUENCE_DECL(DDS_CharSeq)
130  SET_SEQUENCE_DECL(DDS_WcharSeq)
131  SET_SEQUENCE_DECL(DDS_OctetSeq)
132  SET_SEQUENCE_DECL(DDS_LongLongSeq)
133  SET_SEQUENCE_DECL(DDS_UnsignedLongLongSeq)
134 
135  SET_ARRAY_DECL(match::octet_t) // also uint8_t
136  SET_ARRAY_DECL(bool)
137  SET_ARRAY_DECL(char)
138  SET_ARRAY_DECL(int8_t)
139  SET_ARRAY_DECL(char32_t)
140  SET_ARRAY_DECL(int16_t)
141  SET_ARRAY_DECL(uint16_t)
142  SET_ARRAY_DECL(int32_t)
143  SET_ARRAY_DECL(uint32_t)
144  SET_ARRAY_DECL(int64_t)
145  SET_ARRAY_DECL(uint64_t)
146  SET_ARRAY_DECL(float)
147  SET_ARRAY_DECL(double)
148 #ifdef __x86_64__
149  SET_ARRAY_DECL(long long int)
150 #endif
151 
152  GET_SEQUENCE_DECL(DDS_OctetSeq)
153  GET_SEQUENCE_DECL(DDS_BooleanSeq)
154  GET_SEQUENCE_DECL(DDS_CharSeq)
155  GET_SEQUENCE_DECL(DDS_WcharSeq)
156  GET_SEQUENCE_DECL(DDS_ShortSeq)
157  GET_SEQUENCE_DECL(DDS_UnsignedShortSeq)
158  GET_SEQUENCE_DECL(DDS_LongSeq)
159  GET_SEQUENCE_DECL(DDS_UnsignedLongSeq)
160  GET_SEQUENCE_DECL(DDS_LongLongSeq)
161  GET_SEQUENCE_DECL(DDS_UnsignedLongLongSeq)
162  GET_SEQUENCE_DECL(DDS_FloatSeq)
163  GET_SEQUENCE_DECL(DDS_DoubleSeq)
164  GET_SEQUENCE_DECL(DDS_LongDoubleSeq)
165 
166  GET_ARRAY_DECL(match::octet_t) // also uint8_t
167  GET_ARRAY_DECL(bool)
168  GET_ARRAY_DECL(int8_t)
169  GET_ARRAY_DECL(char)
170  GET_ARRAY_DECL(char32_t)
171  GET_ARRAY_DECL(int16_t)
172  GET_ARRAY_DECL(uint16_t)
173  GET_ARRAY_DECL(int32_t)
174  GET_ARRAY_DECL(uint32_t)
175  GET_ARRAY_DECL(int64_t)
176  GET_ARRAY_DECL(uint64_t)
177  GET_ARRAY_DECL(float)
178  GET_ARRAY_DECL(double)
179 #ifdef __x86_64__
180  GET_ARRAY_DECL(long long int)
181 #endif
182 
183  template <class T> // When T is an enum
184  static DDS_ReturnCode_t set_array(
185  DDS_DynamicData &instance,
186  const MemberAccess & ma,
187  DDS_UnsignedLong length,
188  const T *array)
189  {
190  if (ma.access_by_id())
191  return instance.set_long_array(
192  NULL,
193  ma.get_id(),
194  length,
195  reinterpret_cast<const DDS_Long *>(array));
196  else
197  return instance.set_long_array(
198  ma.get_name(),
199  DDS_DYNAMIC_DATA_MEMBER_ID_UNSPECIFIED,
200  length,
201  reinterpret_cast<const DDS_Long *>(array));
202  }
203 
204  template <class T> // When T is an enum
205  static DDS_ReturnCode_t get_array(
206  const DDS_DynamicData & instance,
207  T *array,
208  DDS_UnsignedLong *length,
209  const MemberAccess &ma)
210  {
211  if (ma.access_by_id())
212  return instance.get_long_array(
213  reinterpret_cast<DDS_Long *>(array),
214  length,
215  NULL,
216  ma.get_id());
217  else
218  return instance.get_long_array(
219  reinterpret_cast<DDS_Long *>(array),
220  length,
221  ma.get_name(),
222  DDS_DYNAMIC_DATA_MEMBER_ID_UNSPECIFIED);
223  }
224 
225  REFLEX_DLL_EXPORT void set_seq_length(
226  DDS_DynamicData & seq,
227  size_t size,
228  bool is_string);
229 
230  } // namespace detail
231 
232 } // namespace reflex
233 
234 
235 #ifndef REFLEX_NO_HEADER_ONLY
236 #include "reflex/../../src/dd_extra.cxx"
237 #endif
238 
239 
240 #endif // RTIREFLEX_DD_EXTRA_H
241 
#define GET_ARRAY_DECL(BASIC_TYPE)
Definition: dd_extra.h:38
#define SET_SEQUENCE_DECL(DDS_SEQ_TYPE)
Definition: dd_extra.h:22
void swap(AutoDynamicData &lhs, AutoDynamicData &rhs)
Swap the contents of two AutoDynamicData instances. Never throws.
Definition: auto_dd.cxx:106
#define REFLEX_DLL_EXPORT
Definition: dllexport.h:35
#define GET_SEQUENCE_DECL(DDS_SEQ_TYPE)
Definition: dd_extra.h:27
unsigned char octet_t
Definition: dd_extra.h:48
#define SET_ARRAY_DECL(BASIC_TYPE)
Definition: dd_extra.h:32