Line data Source code
1 : /*
2 : * Distributed under the OpenDDS License.
3 : * See: http://www.opendds.org/license.html
4 : */
5 :
6 : #ifndef OPENDDS_DCPS_XTYPES_DYNAMIC_DATA_ADAPTER_H
7 : #define OPENDDS_DCPS_XTYPES_DYNAMIC_DATA_ADAPTER_H
8 :
9 : #ifndef OPENDDS_SAFETY_PROFILE
10 : # include <dds/DCPS/Definitions.h>
11 : # if OPENDDS_HAS_DYNAMIC_DATA_ADAPTER
12 : # include "DynamicDataBase.h"
13 : # include "Utils.h"
14 :
15 : # include <vector>
16 : # else
17 : # include <dds/DdsDynamicDataC.h>
18 : # endif
19 :
20 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
21 :
22 : namespace OpenDDS {
23 : namespace XTypes {
24 :
25 : // If changing just these two, also change the get_dynamic_data_adapter forward
26 : // declarations in Sample.h.
27 : template <typename T, typename Tag>
28 : DDS::DynamicData_ptr get_dynamic_data_adapter(DDS::DynamicType_ptr type, const T& value);
29 : template <typename T, typename Tag>
30 : DDS::DynamicData_ptr get_dynamic_data_adapter(DDS::DynamicType_ptr type, T& value);
31 :
32 : template <typename T>
33 9 : DDS::DynamicData_ptr get_dynamic_data_adapter(DDS::DynamicType_ptr type, T& value)
34 : {
35 9 : return get_dynamic_data_adapter<T, T>(type, value);
36 : }
37 :
38 : template <typename T>
39 0 : DDS::DynamicData_ptr get_dynamic_data_adapter(DDS::DynamicType_ptr type, const T& value)
40 : {
41 0 : return get_dynamic_data_adapter<T, T>(type, value);
42 : }
43 :
44 : template <typename T, typename Tag>
45 : const T* get_dynamic_data_adapter_value(DDS::DynamicData_ptr dda);
46 :
47 : # if OPENDDS_HAS_DYNAMIC_DATA_ADAPTER
48 :
49 : template <typename T, typename Tag = void>
50 : class DynamicDataAdapterImpl;
51 :
52 : /**
53 : * Base class for all classes that allow interfacing with the C++ mapping types
54 : * as DynamicData.
55 : *
56 : * TODO:
57 : * - Support direct array methods, like get_int32_values
58 : * - Part of this is accessing all types as complex value.
59 : * - Implement equals, clear_value, clear_all_values, and clear_nonkey_values
60 : * - Respect bounds of strings and sequences.
61 : * - Implement way for unions branch to initialized with a default value so
62 : * get_complex_value works like DynamicDataImpl if there is no selected
63 : * branch. This might be able to be done in either code generation of
64 : * DynamicDataAdapterImpl or maybe purely in terms of DynamicDataAdapter.
65 : */
66 : class OpenDDS_Dcps_Export DynamicDataAdapter : public DynamicDataBase {
67 : public:
68 220 : DynamicDataAdapter(DDS::DynamicType_ptr type, bool read_only)
69 : : DynamicDataBase(type)
70 220 : , read_only_(read_only)
71 : {
72 220 : }
73 :
74 : DDS::UInt32 get_item_count();
75 : DDS::MemberId get_member_id_by_name(const char* name);
76 : virtual DDS::MemberId get_member_id_at_index_impl(DDS::UInt32);
77 : DDS::MemberId get_member_id_at_index(DDS::UInt32 index);
78 :
79 : DDS::ReturnCode_t clear_all_values();
80 : DDS::ReturnCode_t clear_nonkey_values();
81 : DDS::ReturnCode_t clear_value(DDS::MemberId);
82 : DDS::DynamicData_ptr clone();
83 :
84 9 : DDS::ReturnCode_t get_int8_value(CORBA::Int8& value,
85 : DDS::MemberId id)
86 : {
87 9 : return get_raw_value("get_int8_value", &value, TK_INT8, id);
88 : }
89 :
90 9 : DDS::ReturnCode_t set_int8_value(DDS::MemberId id,
91 : CORBA::Int8 value)
92 : {
93 9 : return set_raw_value("set_int8_value", id, &value, TK_INT8);
94 : }
95 :
96 9 : DDS::ReturnCode_t get_uint8_value(CORBA::UInt8& value,
97 : DDS::MemberId id)
98 : {
99 9 : return get_raw_value("get_uint8_value", &value, TK_UINT8, id);
100 : }
101 :
102 9 : DDS::ReturnCode_t set_uint8_value(DDS::MemberId id,
103 : CORBA::UInt8 value)
104 : {
105 9 : return set_raw_value("set_uint8_value", id, &value, TK_UINT8);
106 : }
107 :
108 9 : DDS::ReturnCode_t get_int16_value(CORBA::Short& value,
109 : DDS::MemberId id)
110 : {
111 9 : return get_raw_value("get_int16_value", &value, TK_INT16, id);
112 : }
113 :
114 9 : DDS::ReturnCode_t set_int16_value(DDS::MemberId id,
115 : CORBA::Short value)
116 : {
117 9 : return set_raw_value("set_int16_value", id, &value, TK_INT16);
118 : }
119 :
120 9 : DDS::ReturnCode_t get_uint16_value(CORBA::UShort& value,
121 : DDS::MemberId id)
122 : {
123 9 : return get_raw_value("get_uint16_value", &value, TK_UINT16, id);
124 : }
125 :
126 9 : DDS::ReturnCode_t set_uint16_value(DDS::MemberId id,
127 : CORBA::UShort value)
128 : {
129 9 : return set_raw_value("set_uint16_value", id, &value, TK_UINT16);
130 : }
131 :
132 33 : DDS::ReturnCode_t get_int32_value(CORBA::Long& value,
133 : DDS::MemberId id)
134 : {
135 33 : return get_raw_value("get_int32_value", &value, TK_INT32, id);
136 : }
137 :
138 26 : DDS::ReturnCode_t set_int32_value(DDS::MemberId id,
139 : CORBA::Long value)
140 : {
141 26 : return set_raw_value("set_int32_value", id, &value, TK_INT32);
142 : }
143 :
144 56 : DDS::ReturnCode_t get_uint32_value(CORBA::ULong& value,
145 : DDS::MemberId id)
146 : {
147 56 : return get_raw_value("get_uint32_value", &value, TK_UINT32, id);
148 : }
149 :
150 38 : DDS::ReturnCode_t set_uint32_value(DDS::MemberId id,
151 : CORBA::ULong value)
152 : {
153 38 : return set_raw_value("set_uint32_value", id, &value, TK_UINT32);
154 : }
155 :
156 9 : DDS::ReturnCode_t get_int64_value_impl(DDS::Int64& value, DDS::MemberId id)
157 : {
158 9 : return get_raw_value("get_int64_value", &value, TK_INT64, id);
159 : }
160 :
161 9 : DDS::ReturnCode_t set_int64_value(DDS::MemberId id,
162 : CORBA::LongLong value)
163 : {
164 9 : return set_raw_value("set_int64_value", id, &value, TK_INT64);
165 : }
166 :
167 9 : DDS::ReturnCode_t get_uint64_value_impl(DDS::UInt64& value, DDS::MemberId id)
168 : {
169 9 : return get_raw_value("get_uint64_value", &value, TK_UINT64, id);
170 : }
171 :
172 9 : DDS::ReturnCode_t set_uint64_value(DDS::MemberId id,
173 : CORBA::ULongLong value)
174 : {
175 9 : return set_raw_value("set_uint64_value", id, &value, TK_UINT64);
176 : }
177 :
178 9 : DDS::ReturnCode_t get_float32_value(CORBA::Float& value,
179 : DDS::MemberId id)
180 : {
181 9 : return get_raw_value("get_float32_value", &value, TK_FLOAT32, id);
182 : }
183 :
184 9 : DDS::ReturnCode_t set_float32_value(DDS::MemberId id,
185 : CORBA::Float value)
186 : {
187 9 : return set_raw_value("set_float32_value", id, &value, TK_FLOAT32);
188 : }
189 :
190 10 : DDS::ReturnCode_t get_float64_value(CORBA::Double& value,
191 : DDS::MemberId id)
192 : {
193 10 : return get_raw_value("get_float64_value", &value, TK_FLOAT64, id);
194 : }
195 :
196 10 : DDS::ReturnCode_t set_float64_value(DDS::MemberId id,
197 : CORBA::Double value)
198 : {
199 10 : return set_raw_value("set_float64_value", id, &value, TK_FLOAT64);
200 : }
201 :
202 8 : DDS::ReturnCode_t get_float128_value(CORBA::LongDouble& value,
203 : DDS::MemberId id)
204 : {
205 8 : return get_raw_value("get_float128_value", &value, TK_FLOAT128, id);
206 : }
207 :
208 8 : DDS::ReturnCode_t set_float128_value(DDS::MemberId id,
209 : CORBA::LongDouble value)
210 : {
211 8 : return set_raw_value("set_float128_value", id, &value, TK_FLOAT128);
212 : }
213 :
214 9 : DDS::ReturnCode_t get_char8_value(CORBA::Char& value,
215 : DDS::MemberId id)
216 : {
217 9 : return get_raw_value("get_char8_value", &value, TK_CHAR8, id);
218 : }
219 :
220 9 : DDS::ReturnCode_t set_char8_value(DDS::MemberId id,
221 : CORBA::Char value)
222 : {
223 9 : return set_raw_value("set_char8_value", id, &value, TK_CHAR8);
224 : }
225 :
226 9 : DDS::ReturnCode_t get_char16_value(CORBA::WChar& value,
227 : DDS::MemberId id)
228 : {
229 9 : return get_raw_value("get_char16_value", &value, TK_CHAR16, id);
230 : }
231 :
232 9 : DDS::ReturnCode_t set_char16_value(DDS::MemberId id,
233 : CORBA::WChar value)
234 : {
235 9 : return set_raw_value("set_char16_value", id, &value, TK_CHAR16);
236 : }
237 :
238 9 : DDS::ReturnCode_t get_byte_value(DDS::Byte& value,
239 : DDS::MemberId id)
240 : {
241 9 : return get_raw_value("get_byte_value", &value, TK_BYTE, id);
242 : }
243 :
244 9 : DDS::ReturnCode_t set_byte_value(DDS::MemberId id,
245 : CORBA::Octet value)
246 : {
247 9 : return set_raw_value("set_byte_value", id, &value, TK_BYTE);
248 : }
249 :
250 9 : DDS::ReturnCode_t get_boolean_value(CORBA::Boolean& value,
251 : DDS::MemberId id)
252 : {
253 9 : return get_raw_value("get_boolean_value", &value, TK_BOOLEAN, id);
254 : }
255 :
256 9 : DDS::ReturnCode_t set_boolean_value(DDS::MemberId id,
257 : CORBA::Boolean value)
258 : {
259 9 : return set_raw_value("set_boolean_value", id, &value, TK_BOOLEAN);
260 : }
261 :
262 10 : DDS::ReturnCode_t get_string_value(char*& value,
263 : DDS::MemberId id)
264 : {
265 10 : return get_raw_value("get_string_value", &value, TK_STRING8, id);
266 : }
267 :
268 10 : DDS::ReturnCode_t set_string_value(DDS::MemberId id,
269 : const char* value)
270 : {
271 10 : return set_raw_value("set_string_value", id, value, TK_STRING8);
272 : }
273 :
274 9 : DDS::ReturnCode_t get_wstring_value(CORBA::WChar*& value,
275 : DDS::MemberId id)
276 : {
277 9 : return get_raw_value("get_wstring_value", &value, TK_STRING16, id);
278 : }
279 :
280 9 : DDS::ReturnCode_t set_wstring_value(DDS::MemberId id,
281 : const CORBA::WChar* value)
282 : {
283 9 : return set_raw_value("set_wstring_value", id, value, TK_STRING16);
284 : }
285 :
286 210 : DDS::ReturnCode_t get_complex_value(DDS::DynamicData_ptr& value,
287 : DDS::MemberId id)
288 : {
289 210 : return get_raw_value("get_complex_value", &value, TK_NONE, id);
290 : }
291 :
292 0 : DDS::ReturnCode_t set_complex_value(DDS::MemberId id,
293 : DDS::DynamicData_ptr value)
294 : {
295 0 : return set_raw_value("set_complex_value", id, value, TK_NONE);
296 : }
297 :
298 0 : DDS::ReturnCode_t get_int32_values(DDS::Int32Seq&,
299 : DDS::MemberId)
300 : {
301 0 : return unsupported_method("DynamicDataAdapater::get_int32_values");
302 : }
303 :
304 0 : DDS::ReturnCode_t set_int32_values(DDS::MemberId,
305 : const DDS::Int32Seq&)
306 : {
307 0 : return unsupported_method("DynamicDataAdapater::set_int32_values");
308 : }
309 :
310 0 : DDS::ReturnCode_t get_uint32_values(DDS::UInt32Seq&,
311 : DDS::MemberId)
312 : {
313 0 : return unsupported_method("DynamicDataAdapater::get_uint32_values");
314 : }
315 :
316 0 : DDS::ReturnCode_t set_uint32_values(DDS::MemberId,
317 : const DDS::UInt32Seq&)
318 : {
319 0 : return unsupported_method("DynamicDataAdapater::set_uint32_values");
320 : }
321 :
322 0 : DDS::ReturnCode_t get_int8_values(DDS::Int8Seq&,
323 : DDS::MemberId)
324 : {
325 0 : return unsupported_method("DynamicDataAdapater::get_int8_values");
326 : }
327 :
328 0 : DDS::ReturnCode_t set_int8_values(DDS::MemberId,
329 : const DDS::Int8Seq&)
330 : {
331 0 : return unsupported_method("DynamicDataAdapater::set_int8_values");
332 : }
333 :
334 0 : DDS::ReturnCode_t get_uint8_values(DDS::UInt8Seq&,
335 : DDS::MemberId)
336 : {
337 0 : return unsupported_method("DynamicDataAdapater::get_uint8_values");
338 : }
339 :
340 0 : DDS::ReturnCode_t set_uint8_values(DDS::MemberId,
341 : const DDS::UInt8Seq&)
342 : {
343 0 : return unsupported_method("DynamicDataAdapater::set_uint8_values");
344 : }
345 :
346 0 : DDS::ReturnCode_t get_int16_values(DDS::Int16Seq&,
347 : DDS::MemberId)
348 : {
349 0 : return unsupported_method("DynamicDataAdapater::get_int16_values");
350 : }
351 :
352 0 : DDS::ReturnCode_t set_int16_values(DDS::MemberId,
353 : const DDS::Int16Seq&)
354 : {
355 0 : return unsupported_method("DynamicDataAdapater::set_int16_values");
356 : }
357 :
358 0 : DDS::ReturnCode_t get_uint16_values(DDS::UInt16Seq&,
359 : DDS::MemberId)
360 : {
361 0 : return unsupported_method("DynamicDataAdapater::get_uint16_values");
362 : }
363 :
364 0 : DDS::ReturnCode_t set_uint16_values(DDS::MemberId,
365 : const DDS::UInt16Seq&)
366 : {
367 0 : return unsupported_method("DynamicDataAdapater::set_uint16_values");
368 : }
369 :
370 0 : DDS::ReturnCode_t get_int64_values(DDS::Int64Seq&,
371 : DDS::MemberId)
372 : {
373 0 : return unsupported_method("DynamicDataAdapater::get_int64_values");
374 : }
375 :
376 0 : DDS::ReturnCode_t set_int64_values(DDS::MemberId,
377 : const DDS::Int64Seq&)
378 : {
379 0 : return unsupported_method("DynamicDataAdapater::set_int64_values");
380 : }
381 :
382 0 : DDS::ReturnCode_t get_uint64_values(DDS::UInt64Seq&,
383 : DDS::MemberId)
384 : {
385 0 : return unsupported_method("DynamicDataAdapater::get_uint64_values");
386 : }
387 :
388 0 : DDS::ReturnCode_t set_uint64_values(DDS::MemberId,
389 : const DDS::UInt64Seq&)
390 : {
391 0 : return unsupported_method("DynamicDataAdapater::set_uint64_values");
392 : }
393 :
394 0 : DDS::ReturnCode_t get_float32_values(DDS::Float32Seq&,
395 : DDS::MemberId)
396 : {
397 0 : return unsupported_method("DynamicDataAdapater::get_float32_values");
398 : }
399 :
400 0 : DDS::ReturnCode_t set_float32_values(DDS::MemberId,
401 : const DDS::Float32Seq&)
402 : {
403 0 : return unsupported_method("DynamicDataAdapater::set_float32_values");
404 : }
405 :
406 0 : DDS::ReturnCode_t get_float64_values(DDS::Float64Seq&,
407 : DDS::MemberId)
408 : {
409 0 : return unsupported_method("DynamicDataAdapater::get_float64_values");
410 : }
411 :
412 0 : DDS::ReturnCode_t set_float64_values(DDS::MemberId,
413 : const DDS::Float64Seq&)
414 : {
415 0 : return unsupported_method("DynamicDataAdapater::set_float64_values");
416 : }
417 :
418 0 : DDS::ReturnCode_t get_float128_values(DDS::Float128Seq&,
419 : DDS::MemberId)
420 : {
421 0 : return unsupported_method("DynamicDataAdapater::get_float128_values");
422 : }
423 :
424 0 : DDS::ReturnCode_t set_float128_values(DDS::MemberId,
425 : const DDS::Float128Seq&)
426 : {
427 0 : return unsupported_method("DynamicDataAdapater::set_float128_values");
428 : }
429 :
430 0 : DDS::ReturnCode_t get_char8_values(DDS::CharSeq&,
431 : DDS::MemberId)
432 : {
433 0 : return unsupported_method("DynamicDataAdapater::get_char8_values");
434 : }
435 :
436 0 : DDS::ReturnCode_t set_char8_values(DDS::MemberId,
437 : const DDS::CharSeq&)
438 : {
439 0 : return unsupported_method("DynamicDataAdapater::set_char8_values");
440 : }
441 :
442 0 : DDS::ReturnCode_t get_char16_values(DDS::WcharSeq&,
443 : DDS::MemberId)
444 : {
445 0 : return unsupported_method("DynamicDataAdapater::get_char16_values");
446 : }
447 :
448 0 : DDS::ReturnCode_t set_char16_values(DDS::MemberId,
449 : const DDS::WcharSeq&)
450 : {
451 0 : return unsupported_method("DynamicDataAdapater::set_char16_values");
452 : }
453 :
454 0 : DDS::ReturnCode_t get_byte_values(DDS::ByteSeq&,
455 : DDS::MemberId)
456 : {
457 0 : return unsupported_method("DynamicDataAdapater::get_byte_values");
458 : }
459 :
460 0 : DDS::ReturnCode_t set_byte_values(DDS::MemberId,
461 : const DDS::ByteSeq&)
462 : {
463 0 : return unsupported_method("DynamicDataAdapater::set_byte_values");
464 : }
465 :
466 0 : DDS::ReturnCode_t get_boolean_values(DDS::BooleanSeq&,
467 : DDS::MemberId)
468 : {
469 0 : return unsupported_method("DynamicDataAdapater::get_boolean_values");
470 : }
471 :
472 0 : DDS::ReturnCode_t set_boolean_values(DDS::MemberId,
473 : const DDS::BooleanSeq&)
474 : {
475 0 : return unsupported_method("DynamicDataAdapater::set_boolean_values");
476 : }
477 :
478 0 : DDS::ReturnCode_t get_string_values(DDS::StringSeq&,
479 : DDS::MemberId)
480 : {
481 0 : return unsupported_method("DynamicDataAdapater::get_string_values");
482 : }
483 :
484 0 : DDS::ReturnCode_t set_string_values(DDS::MemberId,
485 : const DDS::StringSeq&)
486 : {
487 0 : return unsupported_method("DynamicDataAdapater::set_string_values");
488 : }
489 :
490 0 : DDS::ReturnCode_t get_wstring_values(DDS::WstringSeq&,
491 : DDS::MemberId)
492 : {
493 0 : return unsupported_method("DynamicDataAdapater::get_wstring_values");
494 : }
495 :
496 0 : DDS::ReturnCode_t set_wstring_values(DDS::MemberId,
497 : const DDS::WstringSeq&)
498 : {
499 0 : return unsupported_method("DynamicDataAdapater::set_wstring_values");
500 : }
501 :
502 : protected:
503 : const bool read_only_;
504 :
505 : DDS::ReturnCode_t invalid_id(const char* method, DDS::MemberId id) const;
506 : DDS::ReturnCode_t missing_dda(const char* method, DDS::MemberId id) const;
507 : DDS::ReturnCode_t assert_mutable(const char* method) const;
508 : DDS::ReturnCode_t check_index(const char* method, DDS::UInt32 index, DDS::UInt32 size) const;
509 : DDS::ReturnCode_t check_member(
510 : DDS::DynamicType_var& member_type, const char* method, DDS::TypeKind tk, DDS::MemberId id);
511 : DDS::ReturnCode_t check_member(const char* method, DDS::TypeKind tk, DDS::MemberId id);
512 :
513 : virtual DDS::ReturnCode_t get_raw_value(
514 : const char* method, void* dest, DDS::TypeKind tk, DDS::MemberId id) = 0;
515 :
516 : virtual DDS::ReturnCode_t set_raw_value(
517 : const char* method, DDS::MemberId id, const void* source, DDS::TypeKind tk) = 0;
518 :
519 : template <typename T>
520 188 : DDS::ReturnCode_t get_simple_raw_value(
521 : const char* method, void* dest, DDS::TypeKind tk, T source, DDS::MemberId id)
522 : {
523 188 : const DDS::ReturnCode_t rc = check_member(method, tk, id);
524 188 : if (rc == DDS::RETCODE_OK) {
525 188 : *static_cast<T*>(dest) = source;
526 : }
527 188 : return rc;
528 : }
529 :
530 : /*
531 : * It's possible to call this function with incorrectly matched types and
532 : * GCC could warn about this when the source value from set_*_value is
533 : * smaller than T in get_raw_value. This isn't actually a problem because
534 : * check_member requires tk to match the member's type.
535 : */
536 : # if OPENDDS_GCC_HAS_DIAG_PUSHPOP
537 : # pragma GCC diagnostic push
538 : # pragma GCC diagnostic ignored "-Warray-bounds"
539 : # endif
540 : template <typename T>
541 169 : DDS::ReturnCode_t set_simple_raw_value(
542 : const char* method, T& dest, DDS::MemberId id, const void* source, DDS::TypeKind tk)
543 : {
544 169 : const DDS::ReturnCode_t rc = check_member(method, tk, id);
545 169 : if (rc == DDS::RETCODE_OK) {
546 169 : dest = *static_cast<const T*>(source);
547 : }
548 169 : return rc;
549 : }
550 : # if OPENDDS_GCC_HAS_DIAG_PUSHPOP
551 : # pragma GCC diagnostic pop
552 : # endif
553 :
554 : // A reference to a std::vector<bool> element isn't a bool&, so it's a special
555 : // case.
556 : DDS::ReturnCode_t set_bool_vector_elem_raw_value(
557 : const char* method, std::vector<bool>::reference dest, DDS::MemberId id,
558 : const void* source, DDS::TypeKind tk)
559 : {
560 : const DDS::ReturnCode_t rc = check_member(method, tk, id);
561 : if (rc == DDS::RETCODE_OK) {
562 : dest = *static_cast<const bool*>(source);
563 : }
564 : return rc;
565 : }
566 :
567 : /// For now dest must be a Int32 and tk must be TK_INT32
568 : template <typename Enum>
569 18 : DDS::ReturnCode_t get_enum_raw_value(
570 : const char* method, void* dest, DDS::TypeKind tk, Enum source, DDS::MemberId id)
571 : {
572 18 : const DDS::ReturnCode_t rc = check_member(method, tk, id);
573 18 : if (rc == DDS::RETCODE_OK) {
574 18 : *static_cast<DDS::Int32*>(dest) = static_cast<DDS::Int32>(source);
575 : }
576 18 : return rc;
577 : }
578 :
579 : /// For now source must be a Int32 and tk must be TK_INT32
580 : template <typename Enum>
581 12 : DDS::ReturnCode_t set_enum_raw_value(
582 : const char* method, Enum& dest, DDS::MemberId id, const void* source, DDS::TypeKind tk)
583 : {
584 12 : const DDS::ReturnCode_t rc = check_member(method, tk, id);
585 12 : if (rc == DDS::RETCODE_OK) {
586 12 : dest = static_cast<Enum>(*static_cast<const DDS::Int32*>(source));
587 : }
588 12 : return rc;
589 : }
590 :
591 : DDS::ReturnCode_t get_s8_raw_value(
592 : const char* method, void* dest, DDS::TypeKind tk, const char* source, DDS::MemberId id);
593 : DDS::ReturnCode_t set_s8_raw_value(
594 : const char* method, char*& dest, DDS::MemberId id, const void* source, DDS::TypeKind tk);
595 : DDS::ReturnCode_t get_cpp11_s8_raw_value(
596 : const char* method, void* dest, DDS::TypeKind tk,
597 : const std::string& source, DDS::MemberId id);
598 : DDS::ReturnCode_t set_cpp11_s8_raw_value(
599 : const char* method, std::string& dest, DDS::MemberId id,
600 : const void* source, DDS::TypeKind tk);
601 : DDS::ReturnCode_t get_s16_raw_value(
602 : const char* method, void* dest, DDS::TypeKind tk,
603 : const DDS::Char16* source, DDS::MemberId id);
604 : DDS::ReturnCode_t set_s16_raw_value(
605 : const char* method, DDS::Char16*& dest, DDS::MemberId id,
606 : const void* source, DDS::TypeKind tk);
607 : DDS::ReturnCode_t get_cpp11_s16_raw_value(
608 : const char* method, void* dest, DDS::TypeKind tk,
609 : const std::wstring& source, DDS::MemberId id);
610 : DDS::ReturnCode_t set_cpp11_s16_raw_value(
611 : const char* method, std::wstring& dest, DDS::MemberId id,
612 : const void* source, DDS::TypeKind tk);
613 :
614 : template <typename T, typename Tag>
615 210 : DDS::ReturnCode_t get_complex_raw_value(
616 : const char* method, void* dest, DDS::TypeKind tk, T& source, DDS::MemberId id)
617 : {
618 210 : DDS::DynamicType_var member_type;
619 210 : const DDS::ReturnCode_t rc = check_member(member_type, method, tk, id);
620 210 : if (rc != DDS::RETCODE_OK) {
621 0 : return rc;
622 : }
623 210 : DDS::DynamicData*& dest_value = *static_cast<DDS::DynamicData**>(dest);
624 210 : CORBA::release(dest_value);
625 210 : dest_value = get_dynamic_data_adapter<T, Tag>(member_type, source);
626 210 : if (!dest_value) {
627 0 : return missing_dda(method, id);
628 : }
629 210 : return rc;
630 210 : }
631 :
632 : template <typename T, typename Tag>
633 0 : DDS::ReturnCode_t set_indirect_complex_raw_value_impl(
634 : const char* method, T& dest, DDS::MemberId id, DDS::DynamicType_ptr member_type,
635 : DDS::DynamicData_ptr source_dd)
636 : {
637 0 : DDS::DynamicData_var dest_dda = get_dynamic_data_adapter<T, Tag>(member_type, dest);
638 0 : if (!dest_dda) {
639 0 : return missing_dda(method, id);
640 : }
641 0 : return copy(dest_dda, source_dd);
642 0 : }
643 :
644 : template <typename T, typename Tag>
645 0 : DDS::ReturnCode_t set_direct_complex_raw_value(
646 : const char* method, T& dest, DDS::MemberId id, const void* source, DDS::TypeKind tk)
647 : {
648 0 : DDS::DynamicType_var member_type;
649 0 : const DDS::ReturnCode_t rc = check_member(member_type, method, tk, id);
650 0 : if (rc != DDS::RETCODE_OK) {
651 0 : return rc;
652 : }
653 :
654 0 : DDS::DynamicData* const source_dd = static_cast<DDS::DynamicData*>(const_cast<void*>(source));
655 :
656 : // If the source is another DynamicDataAdapter of the member type then do a
657 : // direct copy, else do an indirect copy.
658 0 : const T* const source_value = get_dynamic_data_adapter_value<T, Tag>(source_dd);
659 0 : if (source_value) {
660 0 : if (source_value != &dest) {
661 0 : dest = *source_value;
662 : }
663 0 : return DDS::RETCODE_OK;
664 : }
665 :
666 0 : return set_indirect_complex_raw_value_impl<T, Tag>(method, dest, id, member_type, source_dd);
667 0 : }
668 :
669 : // In the classic mapping arrays are C arrays, which can't be copied using =,
670 : // so only do a indirect copy.
671 : template <typename T, typename Tag>
672 0 : DDS::ReturnCode_t set_indirect_complex_raw_value(
673 : const char* method, T& dest, DDS::MemberId id, const void* source, DDS::TypeKind tk)
674 : {
675 0 : DDS::DynamicType_var member_type;
676 0 : const DDS::ReturnCode_t rc = check_member(member_type, method, tk, id);
677 0 : if (rc != DDS::RETCODE_OK) {
678 0 : return rc;
679 : }
680 0 : return set_indirect_complex_raw_value_impl<T, Tag>(method, dest, id, member_type,
681 0 : static_cast<DDS::DynamicData*>(const_cast<void*>(source)));
682 0 : }
683 : };
684 :
685 : template <typename T>
686 : class DynamicDataAdapter_T : public DynamicDataAdapter {
687 : public:
688 220 : DynamicDataAdapter_T(DDS::DynamicType_ptr type, T& value)
689 : : DynamicDataAdapter(type, /* read_only = */ false)
690 220 : , value_(value)
691 : {
692 220 : }
693 :
694 0 : DynamicDataAdapter_T(DDS::DynamicType_ptr type, const T& value)
695 : : DynamicDataAdapter(type, /* read_only = */ true)
696 0 : , value_(const_cast<T&>(value))
697 : {
698 0 : }
699 :
700 0 : const T& wrapped() const
701 : {
702 0 : return value_;
703 : }
704 :
705 : protected:
706 : T& value_;
707 : };
708 :
709 : # endif // OPENDDS_HAS_DYNAMIC_DATA_ADAPTER
710 :
711 : } // namespace XTypes
712 : } // namespace OpenDDS
713 :
714 : OPENDDS_END_VERSIONED_NAMESPACE_DECL
715 :
716 : #endif // OPENDDS_SAFETY_PROFILE
717 :
718 : #endif // OPENDDS_DCPS_XTYPES_DYNAMIC_DATA_ADAPTER_H
|