Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Unbounded_Sequence_CDR_T.h
blobab4fb8aca9e2589fdb4fa5aaa06d9273f3620b38
1 #ifndef TAO_UNBOUNDED_SEQUENCE_CDR_T_H
2 #define TAO_UNBOUNDED_SEQUENCE_CDR_T_H
3 /**
4 * @file
6 * @brief Extract the sequence
8 * @author Carlos O'Ryan
9 * @author Johnny Willemsen
12 #include "tao/orbconf.h"
13 #include "tao/CORBA_String.h"
14 #include "tao/SystemException.h"
15 #include "tao/Basic_Types_IDLv4.h"
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 namespace TAO {
20 template <typename stream>
21 bool demarshal_sequence(stream & strm, unbounded_value_sequence <CORBA::Short> & target) {
22 typedef TAO::unbounded_value_sequence <CORBA::Short> sequence;
23 ::CORBA::ULong new_length = 0;
24 if (!(strm >> new_length)) {
25 return false;
27 if (new_length > strm.length()) {
28 return false;
30 sequence tmp(new_length);
31 tmp.length(new_length);
32 typename sequence::value_type * buffer = tmp.get_buffer();
33 if (!strm.read_short_array (buffer, new_length)) {
34 return false;
36 tmp.swap(target);
37 return true;
40 template <typename stream>
41 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Long> & target) {
42 typedef TAO::unbounded_value_sequence <CORBA::Long> sequence;
43 ::CORBA::ULong new_length = 0;
44 if (!(strm >> new_length)) {
45 return false;
47 if (new_length > strm.length()) {
48 return false;
50 sequence tmp(new_length);
51 tmp.length(new_length);
52 typename sequence::value_type * buffer = tmp.get_buffer();
53 if (!strm.read_long_array (buffer, new_length)) {
54 return false;
56 tmp.swap(target);
57 return true;
60 template <typename stream>
61 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::ULong> & target) {
62 typedef TAO::unbounded_value_sequence <CORBA::ULong> sequence;
63 ::CORBA::ULong new_length = 0;
64 if (!(strm >> new_length)) {
65 return false;
67 if (new_length > strm.length()) {
68 return false;
70 sequence tmp(new_length);
71 tmp.length(new_length);
72 typename sequence::value_type * buffer = tmp.get_buffer();
73 if (!strm.read_ulong_array (buffer, new_length)) {
74 return false;
76 tmp.swap(target);
77 return true;
80 template <typename stream>
81 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::UShort> & target) {
82 typedef TAO::unbounded_value_sequence <CORBA::UShort> sequence;
83 ::CORBA::ULong new_length = 0;
84 if (!(strm >> new_length)) {
85 return false;
87 if (new_length > strm.length()) {
88 return false;
90 sequence tmp(new_length);
91 tmp.length(new_length);
92 typename sequence::value_type * buffer = tmp.get_buffer();
93 if (!strm.read_ushort_array (buffer, new_length)) {
94 return false;
96 tmp.swap(target);
97 return true;
100 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
101 template <typename stream>
102 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Octet> & target) {
103 typedef TAO::unbounded_value_sequence <CORBA::Octet> sequence;
104 ::CORBA::ULong new_length = 0;
105 if (!(strm >> new_length)) {
106 return false;
108 if (new_length > strm.length()) {
109 return false;
111 sequence tmp(new_length);
112 tmp.length(new_length);
113 if (ACE_BIT_DISABLED (strm.start ()->flags (), ACE_Message_Block::DONT_DELETE))
115 TAO_ORB_Core* orb_core = strm.orb_core ();
116 if (orb_core != 0 && strm.orb_core ()->resource_factory ()->
117 input_cdr_allocator_type_locked () == 1)
119 tmp.replace (new_length, strm.start ());
120 tmp.mb ()->wr_ptr (tmp.mb()->rd_ptr () + new_length);
121 strm.skip_bytes (new_length);
122 tmp.swap(target);
123 return true;
126 typename sequence::value_type * buffer = tmp.get_buffer();
127 if (!strm.read_octet_array (buffer, new_length)) {
128 return false;
130 tmp.swap(target);
131 return true;
133 #else
134 template <typename stream>
135 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Octet> & target) {
136 typedef TAO::unbounded_value_sequence <CORBA::Octet> sequence;
137 ::CORBA::ULong new_length = 0;
138 if (!(strm >> new_length)) {
139 return false;
141 if (new_length > strm.length()) {
142 return false;
144 sequence tmp(new_length);
145 tmp.length(new_length);
146 typename sequence::value_type * buffer = tmp.get_buffer();
147 if (!strm.read_octet_array (buffer, new_length)) {
148 return false;
150 tmp.swap(target);
151 return true;
153 #endif
155 template <typename stream>
156 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Char> & target) {
157 typedef TAO::unbounded_value_sequence <CORBA::Char> sequence;
158 ::CORBA::ULong new_length = 0;
159 if (!(strm >> new_length)) {
160 return false;
162 if (new_length > strm.length()) {
163 return false;
165 sequence tmp(new_length);
166 tmp.length(new_length);
167 typename sequence::value_type * buffer = tmp.get_buffer();
168 if (!strm.read_char_array (buffer, new_length)) {
169 return false;
171 tmp.swap(target);
172 return true;
175 # if (defined (ACE_HAS_WCHAR) || defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
176 template <typename stream>
177 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::WChar> & target) {
178 typedef TAO::unbounded_value_sequence <CORBA::WChar> sequence;
179 ::CORBA::ULong new_length = 0;
180 if (!(strm >> new_length)) {
181 return false;
183 if (new_length > strm.length()) {
184 return false;
186 sequence tmp(new_length);
187 tmp.length(new_length);
188 typename sequence::value_type * buffer = tmp.get_buffer();
189 if (!strm.read_wchar_array (buffer, new_length)) {
190 return false;
192 tmp.swap(target);
193 return true;
195 #endif
197 template <typename stream>
198 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Float> & target) {
199 typedef TAO::unbounded_value_sequence <CORBA::Float> sequence;
200 ::CORBA::ULong new_length = 0;
201 if (!(strm >> new_length)) {
202 return false;
204 if (new_length > strm.length()) {
205 return false;
207 sequence tmp(new_length);
208 tmp.length(new_length);
209 typename sequence::value_type * buffer = tmp.get_buffer();
210 if (!strm.read_float_array (buffer, new_length)) {
211 return false;
213 tmp.swap(target);
214 return true;
217 template <typename stream>
218 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Double> & target) {
219 typedef TAO::unbounded_value_sequence <CORBA::Double> sequence;
220 ::CORBA::ULong new_length = 0;
221 if (!(strm >> new_length)) {
222 return false;
224 if (new_length > strm.length()) {
225 return false;
227 sequence tmp(new_length);
228 tmp.length(new_length);
229 typename sequence::value_type * buffer = tmp.get_buffer();
230 if (!strm.read_double_array (buffer, new_length)) {
231 return false;
233 tmp.swap(target);
234 return true;
237 template <typename stream>
238 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::LongLong> & target) {
239 typedef TAO::unbounded_value_sequence <CORBA::LongLong> sequence;
240 ::CORBA::ULong new_length = 0;
241 if (!(strm >> new_length)) {
242 return false;
244 if (new_length > strm.length()) {
245 return false;
247 sequence tmp(new_length);
248 tmp.length(new_length);
249 typename sequence::value_type * buffer = tmp.get_buffer();
250 if (!strm.read_longlong_array (buffer, new_length)) {
251 return false;
253 tmp.swap(target);
254 return true;
257 template <typename stream>
258 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::ULongLong> & target) {
259 typedef TAO::unbounded_value_sequence <CORBA::ULongLong> sequence;
260 ::CORBA::ULong new_length = 0;
261 if (!(strm >> new_length)) {
262 return false;
264 if (new_length > strm.length()) {
265 return false;
267 sequence tmp(new_length);
268 tmp.length(new_length);
269 typename sequence::value_type * buffer = tmp.get_buffer();
270 if (!strm.read_ulonglong_array (buffer, new_length)) {
271 return false;
273 tmp.swap(target);
274 return true;
277 template <typename stream>
278 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::LongDouble> & target) {
279 typedef TAO::unbounded_value_sequence <CORBA::LongDouble> sequence;
280 ::CORBA::ULong new_length = 0;
281 if (!(strm >> new_length)) {
282 return false;
284 if (new_length > strm.length()) {
285 return false;
287 sequence tmp(new_length);
288 tmp.length(new_length);
289 typename sequence::value_type * buffer = tmp.get_buffer();
290 if (!strm.read_longdouble_array (buffer, new_length)) {
291 return false;
293 tmp.swap(target);
294 return true;
297 template <typename stream>
298 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Boolean> & target) {
299 typedef TAO::unbounded_value_sequence <CORBA::Boolean> sequence;
300 ::CORBA::ULong new_length = 0;
301 if (!(strm >> new_length)) {
302 return false;
304 if (new_length > strm.length()) {
305 return false;
307 sequence tmp(new_length);
308 tmp.length(new_length);
309 typename sequence::value_type * buffer = tmp.get_buffer();
310 if (!strm.read_boolean_array (buffer, new_length)) {
311 return false;
313 tmp.swap(target);
314 return true;
317 template <typename stream>
318 bool demarshal_sequence(stream & strm,
319 TAO::unbounded_value_sequence <CORBA::IDLv4::UInt8, CORBA::IDLv4::UInt8_tag> & target) {
320 typedef TAO::unbounded_value_sequence <CORBA::IDLv4::UInt8, CORBA::IDLv4::UInt8_tag> sequence;
321 ::CORBA::ULong new_length = 0;
322 if (!(strm >> new_length)) {
323 return false;
325 if (new_length > strm.length()) {
326 return false;
328 sequence tmp(new_length);
329 tmp.length(new_length);
330 typename sequence::value_type * buffer = tmp.get_buffer();
331 if (!strm.read_uint8_array (buffer, new_length)) {
332 return false;
334 tmp.swap(target);
335 return true;
338 template <typename stream>
339 bool demarshal_sequence(stream & strm,
340 TAO::unbounded_value_sequence <CORBA::IDLv4::Int8, CORBA::IDLv4::Int8_tag> & target) {
341 typedef TAO::unbounded_value_sequence <CORBA::IDLv4::Int8, CORBA::IDLv4::Int8_tag> sequence;
342 ::CORBA::ULong new_length = 0;
343 if (!(strm >> new_length)) {
344 return false;
346 if (new_length > strm.length()) {
347 return false;
349 sequence tmp(new_length);
350 tmp.length(new_length);
351 typename sequence::value_type * buffer = tmp.get_buffer();
352 if (!strm.read_int8_array (buffer, new_length)) {
353 return false;
355 tmp.swap(target);
356 return true;
359 template <typename stream, typename value_t>
360 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <value_t> & target) {
361 typedef TAO::unbounded_value_sequence <value_t> sequence;
362 ::CORBA::ULong new_length = 0;
363 if (!(strm >> new_length)) {
364 return false;
366 if (new_length > strm.length()) {
367 return false;
369 sequence tmp(new_length);
370 tmp.length(new_length);
371 typename sequence::value_type * buffer = tmp.get_buffer();
372 for(CORBA::ULong i = 0; i < new_length; ++i) {
373 if (!(strm >> buffer[i])) {
374 return false;
377 tmp.swap(target);
378 return true;
381 template <typename stream, typename charT>
382 bool demarshal_sequence(stream & strm, TAO::unbounded_basic_string_sequence <charT> & target) {
383 typedef TAO::unbounded_basic_string_sequence <charT> sequence;
384 typedef typename sequence::element_traits::string_var string_var;
385 typedef typename sequence::allocation_traits sequence_allocation_traits;
386 ::CORBA::ULong new_length = 0;
387 if (!(strm >> new_length)) {
388 return false;
390 if (new_length > strm.length()) {
391 return false;
393 sequence tmp(new_length, new_length,
394 sequence_allocation_traits::allocbuf_noinit(new_length),
395 true);
396 for(CORBA::ULong i = 0; i < new_length; ++i) {
397 string_var string;
398 if (!(strm >> string.inout ())) {
399 return false;
401 else {
402 tmp[i] = string._retn ();
405 tmp.swap(target);
406 return true;
409 template <typename stream, typename charT, CORBA::ULong BD_STR_MAX>
410 bool demarshal_sequence(stream & strm, TAO::unbounded_bd_string_sequence <charT, BD_STR_MAX> & target) {
411 typedef TAO::unbounded_bd_string_sequence <charT, BD_STR_MAX> sequence;
412 typedef typename sequence::element_traits::string_var string_var;
413 typedef typename sequence::allocation_traits sequence_allocation_traits;
414 ::CORBA::ULong new_length = 0;
415 if (!(strm >> new_length)) {
416 return false;
418 if (new_length > strm.length()) {
419 return false;
421 sequence tmp(new_length, new_length,
422 sequence_allocation_traits::allocbuf_noinit(new_length),
423 true);
424 for(CORBA::ULong i = 0; i < new_length; ++i) {
425 string_var string;
426 if (!(strm >> string.inout ())) {
427 return false;
429 else {
430 if (string.in () != 0 &&
431 ACE_OS::strlen (string.in ()) > tmp.bd_string_maximum ()) {
432 throw ::CORBA::BAD_PARAM ();
434 tmp[i] = string._retn ();
437 tmp.swap(target);
438 return true;
441 template <typename stream, typename object_t, typename object_t_var>
442 bool demarshal_sequence(stream & strm, TAO::unbounded_object_reference_sequence<object_t, object_t_var> & target) {
443 typedef TAO::unbounded_object_reference_sequence<object_t, object_t_var> sequence;
444 typedef typename sequence::allocation_traits sequence_allocation_traits;
445 ::CORBA::ULong new_length = 0;
446 if (!(strm >> new_length)) {
447 return false;
449 if (new_length > strm.length()) {
450 return false;
452 sequence tmp(new_length, new_length,
453 sequence_allocation_traits::allocbuf_noinit(new_length),
454 true);
455 typename sequence::value_type * buffer = tmp.get_buffer();
456 for(CORBA::ULong i = 0; i < new_length; ++i) {
457 if (!(strm >> buffer[i])) {
458 return false;
461 tmp.swap(target);
462 return true;
465 template <typename stream>
466 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Short> & source) {
467 ::CORBA::ULong const length = source.length ();
468 if (!(strm << length)) {
469 return false;
471 return strm.write_short_array (source.get_buffer (), length);
474 template <typename stream>
475 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Long> & source) {
476 ::CORBA::ULong const length = source.length ();
477 if (!(strm << length)) {
478 return false;
480 return strm.write_long_array (source.get_buffer (), length);
483 template <typename stream>
484 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::ULong> & source) {
485 ::CORBA::ULong const length = source.length ();
486 if (!(strm << length)) {
487 return false;
489 return strm.write_ulong_array (source.get_buffer (), length);
492 template <typename stream>
493 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::UShort> & source) {
494 ::CORBA::ULong const length = source.length ();
495 if (!(strm << length)) {
496 return false;
498 return strm.write_ushort_array (source.get_buffer (), length);
501 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
502 template <typename stream>
503 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Octet> & source) {
504 ::CORBA::ULong const length = source.length ();
505 if (!(strm << length)) {
506 return false;
508 if (source.mb ()) {
509 return strm.write_octet_array_mb (source.mb ());
511 return strm.write_octet_array (source.get_buffer (), length);
513 #else
514 template <typename stream>
515 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Octet> & source) {
516 ::CORBA::ULong const length = source.length ();
517 if (!(strm << length)) {
518 return false;
520 return strm.write_octet_array (source.get_buffer (), length);
522 #endif
524 template <typename stream>
525 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Char> & source) {
526 ::CORBA::ULong const length = source.length ();
527 if (!(strm << length)) {
528 return false;
530 return strm.write_char_array (source.get_buffer (), length);
533 # if (defined (ACE_HAS_WCHAR) || defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
534 template <typename stream>
535 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::WChar> & source) {
536 ::CORBA::ULong const length = source.length ();
537 if (!(strm << length)) {
538 return false;
540 return strm.write_wchar_array (source.get_buffer (), length);
542 #endif
544 template <typename stream>
545 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Float> & source) {
546 ::CORBA::ULong const length = source.length ();
547 if (!(strm << length)) {
548 return false;
550 return strm.write_float_array (source.get_buffer (), length);
553 template <typename stream>
554 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Double> & source) {
555 ::CORBA::ULong const length = source.length ();
556 if (!(strm << length)) {
557 return false;
559 return strm.write_double_array (source.get_buffer (), length);
562 template <typename stream>
563 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::LongLong> & source) {
564 ::CORBA::ULong const length = source.length ();
565 if (!(strm << length)) {
566 return false;
568 return strm.write_longlong_array (source.get_buffer (), length);
571 template <typename stream>
572 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::ULongLong> & source) {
573 ::CORBA::ULong const length = source.length ();
574 if (!(strm << length)) {
575 return false;
577 return strm.write_ulonglong_array (source.get_buffer (), length);
580 template <typename stream>
581 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::LongDouble> & source) {
582 ::CORBA::ULong const length = source.length ();
583 if (!(strm << length)) {
584 return false;
586 return strm.write_longdouble_array (source.get_buffer (), length);
589 template <typename stream>
590 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Boolean> & source) {
591 ::CORBA::ULong const length = source.length ();
592 if (!(strm << length)) {
593 return false;
595 return strm.write_boolean_array (source.get_buffer (), length);
598 template <typename stream>
599 bool marshal_sequence(stream & strm,
600 const TAO::unbounded_value_sequence <CORBA::IDLv4::UInt8, CORBA::IDLv4::UInt8_tag> & source) {
601 ::CORBA::ULong const length = source.length ();
602 if (!(strm << length)) {
603 return false;
605 return strm.write_uint8_array (source.get_buffer (), length);
608 template <typename stream>
609 bool marshal_sequence(stream & strm,
610 const TAO::unbounded_value_sequence <CORBA::IDLv4::Int8, CORBA::IDLv4::Int8_tag> & source) {
611 ::CORBA::ULong const length = source.length ();
612 if (!(strm << length)) {
613 return false;
615 return strm.write_int8_array (source.get_buffer (), length);
618 template <typename stream, typename value_t>
619 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <value_t> & source) {
620 ::CORBA::ULong const length = source.length ();
621 if (!(strm << length)) {
622 return false;
624 for(CORBA::ULong i = 0; i < length; ++i) {
625 if (!(strm << source[i])) {
626 return false;
629 return true;
632 template <typename stream, typename charT>
633 bool marshal_sequence(stream & strm, const TAO::unbounded_basic_string_sequence <charT> & source) {
634 ::CORBA::ULong const length = source.length ();
635 if (!(strm << length)) {
636 return false;
638 for(CORBA::ULong i = 0; i < length; ++i) {
639 if (!(strm << source[i])) {
640 return false;
643 return true;
646 template <typename stream, typename charT, CORBA::ULong BD_STR_MAX>
647 bool marshal_sequence(stream & strm, const TAO::unbounded_bd_string_sequence <charT, BD_STR_MAX> & source) {
648 ::CORBA::ULong const length = source.length ();
649 if (!(strm << length)) {
650 return false;
652 for(CORBA::ULong i = 0; i < length; ++i) {
653 if (source[i].in () != 0 &&
654 ACE_OS::strlen (source[i]) > source.bd_string_maximum ()) {
655 throw ::CORBA::BAD_PARAM ();
657 if (!(strm << source[i])) {
658 return false;
661 return true;
664 template <typename stream, typename object_t, typename object_t_var>
665 bool marshal_sequence(stream & strm, const TAO::unbounded_object_reference_sequence<object_t, object_t_var> & source) {
666 typedef typename TAO::unbounded_object_reference_sequence<object_t, object_t_var>::object_type objec_t;
667 ::CORBA::ULong const length = source.length ();
668 if (!(strm << length)) {
669 return false;
671 for(CORBA::ULong i = 0; i < length; ++i) {
672 if (!TAO::Objref_Traits<objec_t>::marshal (source[i], strm)) {
673 return false;
676 return true;
678 } // namespace TAO
680 TAO_END_VERSIONED_NAMESPACE_DECL
682 #endif /* TAO_UNBOUNDED_SEQUENCE_CDR_T_H */