1 #ifndef TAO_UNBOUNDED_SEQUENCE_CDR_T_H
2 #define TAO_UNBOUNDED_SEQUENCE_CDR_T_H
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
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
)) {
27 if (new_length
> strm
.length()) {
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
)) {
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
)) {
47 if (new_length
> strm
.length()) {
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
)) {
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
)) {
67 if (new_length
> strm
.length()) {
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
)) {
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
)) {
87 if (new_length
> strm
.length()) {
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
)) {
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
)) {
108 if (new_length
> strm
.length()) {
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
);
126 typename
sequence::value_type
* buffer
= tmp
.get_buffer();
127 if (!strm
.read_octet_array (buffer
, new_length
)) {
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
)) {
141 if (new_length
> strm
.length()) {
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
)) {
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
)) {
162 if (new_length
> strm
.length()) {
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
)) {
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
)) {
183 if (new_length
> strm
.length()) {
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
)) {
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
)) {
204 if (new_length
> strm
.length()) {
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
)) {
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
)) {
224 if (new_length
> strm
.length()) {
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
)) {
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
)) {
244 if (new_length
> strm
.length()) {
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
)) {
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
)) {
264 if (new_length
> strm
.length()) {
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
)) {
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
)) {
284 if (new_length
> strm
.length()) {
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
)) {
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
)) {
304 if (new_length
> strm
.length()) {
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
)) {
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
)) {
325 if (new_length
> strm
.length()) {
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
)) {
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
)) {
346 if (new_length
> strm
.length()) {
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
)) {
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
)) {
366 if (new_length
> strm
.length()) {
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
])) {
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
)) {
390 if (new_length
> strm
.length()) {
393 sequence
tmp(new_length
, new_length
,
394 sequence_allocation_traits::allocbuf_noinit(new_length
),
396 for(CORBA::ULong i
= 0; i
< new_length
; ++i
) {
398 if (!(strm
>> string
.inout ())) {
402 tmp
[i
] = string
._retn ();
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
)) {
418 if (new_length
> strm
.length()) {
421 sequence
tmp(new_length
, new_length
,
422 sequence_allocation_traits::allocbuf_noinit(new_length
),
424 for(CORBA::ULong i
= 0; i
< new_length
; ++i
) {
426 if (!(strm
>> string
.inout ())) {
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 ();
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
)) {
449 if (new_length
> strm
.length()) {
452 sequence
tmp(new_length
, new_length
,
453 sequence_allocation_traits::allocbuf_noinit(new_length
),
455 typename
sequence::value_type
* buffer
= tmp
.get_buffer();
456 for(CORBA::ULong i
= 0; i
< new_length
; ++i
) {
457 if (!(strm
>> buffer
[i
])) {
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
)) {
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
)) {
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
)) {
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
)) {
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
)) {
509 return strm
.write_octet_array_mb (source
.mb ());
511 return strm
.write_octet_array (source
.get_buffer (), length
);
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
)) {
520 return strm
.write_octet_array (source
.get_buffer (), length
);
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
)) {
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
)) {
540 return strm
.write_wchar_array (source
.get_buffer (), length
);
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
)) {
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
)) {
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
)) {
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
)) {
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
)) {
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
)) {
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
)) {
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
)) {
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
)) {
624 for(CORBA::ULong i
= 0; i
< length
; ++i
) {
625 if (!(strm
<< source
[i
])) {
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
)) {
638 for(CORBA::ULong i
= 0; i
< length
; ++i
) {
639 if (!(strm
<< source
[i
])) {
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
)) {
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
])) {
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
)) {
671 for(CORBA::ULong i
= 0; i
< length
; ++i
) {
672 if (!TAO::Objref_Traits
<objec_t
>::marshal (source
[i
], strm
)) {
680 TAO_END_VERSIONED_NAMESPACE_DECL
682 #endif /* TAO_UNBOUNDED_SEQUENCE_CDR_T_H */