Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Bounded_Sequence_CDR_T.h
blobf2339ff8bbfc9156c2d084234feffdf6619ac357
1 #ifndef TAO_BOUNDED_SEQUENCE_CDR_T_H
2 #define TAO_BOUNDED_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/SystemException.h"
14 #include "tao/Basic_Types_IDLv4.h"
16 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
18 namespace TAO {
19 template <typename stream, CORBA::ULong MAX>
20 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::Short, MAX> & target) {
21 typedef TAO::bounded_value_sequence <CORBA::Short, MAX> sequence;
22 ::CORBA::ULong new_length = 0;
23 if (!(strm >> new_length)) {
24 return false;
26 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
27 return false;
29 sequence tmp;
30 tmp.length(new_length);
31 typename sequence::value_type * buffer = tmp.get_buffer();
32 if (!strm.read_short_array (buffer, new_length)) {
33 return false;
35 tmp.swap(target);
36 return true;
39 template <typename stream, CORBA::ULong MAX>
40 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::Long, MAX> & target) {
41 typedef TAO::bounded_value_sequence <CORBA::Long, MAX> sequence;
42 ::CORBA::ULong new_length = 0;
43 if (!(strm >> new_length)) {
44 return false;
46 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
47 return false;
49 sequence tmp;
50 tmp.length(new_length);
51 typename sequence::value_type * buffer = tmp.get_buffer();
52 if (!strm.read_long_array (buffer, new_length)) {
53 return false;
55 tmp.swap(target);
56 return true;
59 template <typename stream, CORBA::ULong MAX>
60 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::ULong, MAX> & target) {
61 typedef TAO::bounded_value_sequence <CORBA::ULong, MAX> sequence;
62 ::CORBA::ULong new_length = 0;
63 if (!(strm >> new_length)) {
64 return false;
66 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
67 return false;
69 sequence tmp;
70 tmp.length(new_length);
71 typename sequence::value_type * buffer = tmp.get_buffer();
72 if (!strm.read_ulong_array (buffer, new_length)) {
73 return false;
75 tmp.swap(target);
76 return true;
79 template <typename stream, CORBA::ULong MAX>
80 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::UShort, MAX> & target) {
81 typedef TAO::bounded_value_sequence <CORBA::UShort, MAX> sequence;
82 ::CORBA::ULong new_length = 0;
83 if (!(strm >> new_length)) {
84 return false;
86 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
87 return false;
89 sequence tmp;
90 tmp.length(new_length);
91 typename sequence::value_type * buffer = tmp.get_buffer();
92 if (!strm.read_ushort_array (buffer, new_length)) {
93 return false;
95 tmp.swap(target);
96 return true;
99 template <typename stream, CORBA::ULong MAX>
100 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::Octet, MAX> & target) {
101 typedef TAO::bounded_value_sequence <CORBA::Octet, MAX> sequence;
102 ::CORBA::ULong new_length = 0;
103 if (!(strm >> new_length)) {
104 return false;
106 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
107 return false;
109 sequence tmp;
110 tmp.length(new_length);
111 typename sequence::value_type * buffer = tmp.get_buffer();
112 if (!strm.read_octet_array (buffer, new_length)) {
113 return false;
115 tmp.swap(target);
116 return true;
119 template <typename stream, CORBA::ULong MAX>
120 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::Char, MAX> & target) {
121 typedef TAO::bounded_value_sequence <CORBA::Char, MAX> sequence;
122 ::CORBA::ULong new_length = 0;
123 if (!(strm >> new_length)) {
124 return false;
126 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
127 return false;
129 sequence tmp;
130 tmp.length(new_length);
131 typename sequence::value_type * buffer = tmp.get_buffer();
132 if (!strm.read_char_array (buffer, new_length)) {
133 return false;
135 tmp.swap(target);
136 return true;
139 # if (defined (ACE_HAS_WCHAR) || defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
140 template <typename stream, CORBA::ULong MAX>
141 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::WChar, MAX> & target) {
142 typedef TAO::bounded_value_sequence <CORBA::WChar, MAX> sequence;
143 ::CORBA::ULong new_length = 0;
144 if (!(strm >> new_length)) {
145 return false;
147 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
148 return false;
150 sequence tmp;
151 tmp.length(new_length);
152 typename sequence::value_type * buffer = tmp.get_buffer();
153 if (!strm.read_wchar_array (buffer, new_length)) {
154 return false;
156 tmp.swap(target);
157 return true;
159 #endif
161 template <typename stream, CORBA::ULong MAX>
162 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::Float, MAX> & target) {
163 typedef TAO::bounded_value_sequence <CORBA::Float, MAX> sequence;
164 ::CORBA::ULong new_length = 0;
165 if (!(strm >> new_length)) {
166 return false;
168 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
169 return false;
171 sequence tmp;
172 tmp.length(new_length);
173 typename sequence::value_type * buffer = tmp.get_buffer();
174 if (!strm.read_float_array (buffer, new_length)) {
175 return false;
177 tmp.swap(target);
178 return true;
181 template <typename stream, CORBA::ULong MAX>
182 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::Double, MAX> & target) {
183 typedef TAO::bounded_value_sequence <CORBA::Double, MAX> sequence;
184 ::CORBA::ULong new_length = 0;
185 if (!(strm >> new_length)) {
186 return false;
188 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
189 return false;
191 sequence tmp;
192 tmp.length(new_length);
193 typename sequence::value_type * buffer = tmp.get_buffer();
194 if (!strm.read_double_array (buffer, new_length)) {
195 return false;
197 tmp.swap(target);
198 return true;
201 template <typename stream, CORBA::ULong MAX>
202 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::LongLong, MAX> & target) {
203 typedef TAO::bounded_value_sequence <CORBA::LongLong, MAX> sequence;
204 ::CORBA::ULong new_length = 0;
205 if (!(strm >> new_length)) {
206 return false;
208 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
209 return false;
211 sequence tmp;
212 tmp.length(new_length);
213 typename sequence::value_type * buffer = tmp.get_buffer();
214 if (!strm.read_longlong_array (buffer, new_length)) {
215 return false;
217 tmp.swap(target);
218 return true;
221 template <typename stream, CORBA::ULong MAX>
222 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::ULongLong, MAX> & target) {
223 typedef TAO::bounded_value_sequence <CORBA::ULongLong, MAX> sequence;
224 ::CORBA::ULong new_length = 0;
225 if (!(strm >> new_length)) {
226 return false;
228 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
229 return false;
231 sequence tmp;
232 tmp.length(new_length);
233 typename sequence::value_type * buffer = tmp.get_buffer();
234 if (!strm.read_ulonglong_array (buffer, new_length)) {
235 return false;
237 tmp.swap(target);
238 return true;
241 template <typename stream, CORBA::ULong MAX>
242 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::LongDouble, MAX> & target) {
243 typedef TAO::bounded_value_sequence <CORBA::LongDouble, MAX> sequence;
244 ::CORBA::ULong new_length = 0;
245 if (!(strm >> new_length)) {
246 return false;
248 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
249 return false;
251 sequence tmp;
252 tmp.length(new_length);
253 typename sequence::value_type * buffer = tmp.get_buffer();
254 if (!strm.read_longdouble_array (buffer, new_length)) {
255 return false;
257 tmp.swap(target);
258 return true;
261 template <typename stream, CORBA::ULong MAX>
262 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <CORBA::Boolean, MAX> & target) {
263 typedef TAO::bounded_value_sequence <CORBA::Boolean, MAX> sequence;
264 ::CORBA::ULong new_length = 0;
265 if (!(strm >> new_length)) {
266 return false;
268 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
269 return false;
271 sequence tmp;
272 tmp.length(new_length);
273 typename sequence::value_type * buffer = tmp.get_buffer();
274 if (!strm.read_boolean_array (buffer, new_length)) {
275 return false;
277 tmp.swap(target);
278 return true;
281 template <typename stream, CORBA::ULong MAX>
282 bool demarshal_sequence(stream & strm,
283 TAO::bounded_value_sequence <CORBA::IDLv4::UInt8, MAX, CORBA::IDLv4::UInt8_tag> & target) {
284 typedef TAO::bounded_value_sequence <CORBA::IDLv4::UInt8, MAX, CORBA::IDLv4::UInt8_tag> sequence;
285 ::CORBA::ULong new_length = 0;
286 if (!(strm >> new_length)) {
287 return false;
289 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
290 return false;
292 sequence tmp;
293 tmp.length(new_length);
294 typename sequence::value_type * buffer = tmp.get_buffer();
295 if (!strm.read_uint8_array (buffer, new_length)) {
296 return false;
298 tmp.swap(target);
299 return true;
302 template <typename stream, CORBA::ULong MAX>
303 bool demarshal_sequence(stream & strm,
304 TAO::bounded_value_sequence <CORBA::IDLv4::Int8, MAX, CORBA::IDLv4::Int8_tag> & target) {
305 typedef TAO::bounded_value_sequence <CORBA::IDLv4::Int8, MAX, CORBA::IDLv4::Int8_tag> sequence;
306 ::CORBA::ULong new_length = 0;
307 if (!(strm >> new_length)) {
308 return false;
310 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
311 return false;
313 sequence tmp;
314 tmp.length(new_length);
315 typename sequence::value_type * buffer = tmp.get_buffer();
316 if (!strm.read_int8_array (buffer, new_length)) {
317 return false;
319 tmp.swap(target);
320 return true;
323 template <typename stream, typename value_t, CORBA::ULong MAX>
324 bool demarshal_sequence(stream & strm, TAO::bounded_value_sequence <value_t, MAX> & target) {
325 typedef TAO::bounded_value_sequence <value_t, MAX> sequence;
326 ::CORBA::ULong new_length = 0;
327 if (!(strm >> new_length)) {
328 return false;
330 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
331 return false;
333 sequence tmp;
334 tmp.length(new_length);
335 typename sequence::value_type * buffer = tmp.get_buffer();
336 for(CORBA::ULong i = 0; i < new_length; ++i) {
337 if (!(strm >> buffer[i])) {
338 return false;
341 tmp.swap(target);
342 return true;
345 template <typename stream, typename charT, CORBA::ULong MAX>
346 bool demarshal_sequence(stream & strm, TAO::bounded_basic_string_sequence <charT, MAX> & target) {
347 typedef typename TAO::bounded_basic_string_sequence <charT, MAX> sequence;
348 typedef typename sequence::element_traits::string_var string_var;
349 typedef typename sequence::allocation_traits sequence_allocation_traits;
350 ::CORBA::ULong new_length = 0;
351 if (!(strm >> new_length)) {
352 return false;
354 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
355 return false;
357 sequence tmp(new_length,
358 sequence_allocation_traits::allocbuf_noinit(new_length),
359 true);
360 for(CORBA::ULong i = 0; i < new_length; ++i) {
361 string_var string;
362 if (!(strm >> string.inout ())) {
363 return false;
365 else {
366 tmp[i] = string._retn ();
369 tmp.swap(target);
370 return true;
373 template <typename stream, typename charT, CORBA::ULong MAX, CORBA::ULong BD_STR_MAX>
374 bool demarshal_sequence(stream & strm, TAO::bounded_bd_string_sequence <charT, MAX, BD_STR_MAX> & target) {
375 typedef typename TAO::bounded_bd_string_sequence <charT, MAX, BD_STR_MAX> sequence;
376 typedef typename sequence::element_traits::string_var string_var;
377 typedef typename sequence::allocation_traits sequence_allocation_traits;
378 ::CORBA::ULong new_length = 0;
379 if (!(strm >> new_length)) {
380 return false;
382 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
383 return false;
385 sequence tmp(new_length,
386 sequence_allocation_traits::allocbuf_noinit(new_length),
387 true);
388 for(CORBA::ULong i = 0; i < new_length; ++i) {
389 string_var string;
390 if (!(strm >> string.inout ())) {
391 return false;
393 else {
394 if (string.in () != 0 &&
395 ACE_OS::strlen (string.in ()) > tmp.bd_string_maximum ()) {
396 throw ::CORBA::BAD_PARAM ();
398 tmp[i] = string._retn ();
401 tmp.swap(target);
402 return true;
405 template <typename stream, typename object_t, typename object_t_var, CORBA::ULong MAX>
406 bool demarshal_sequence(stream & strm, TAO::bounded_object_reference_sequence<object_t, object_t_var, MAX> & target) {
407 typedef typename TAO::bounded_object_reference_sequence<object_t, object_t_var, MAX> sequence;
408 typedef typename sequence::allocation_traits sequence_allocation_traits;
409 ::CORBA::ULong new_length = 0;
410 if (!(strm >> new_length)) {
411 return false;
413 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
414 return false;
416 sequence tmp(new_length,
417 sequence_allocation_traits::allocbuf_noinit(new_length),
418 true);
419 typename sequence::value_type * buffer = tmp.get_buffer();
420 for(CORBA::ULong i = 0; i < new_length; ++i) {
421 if (!(strm >> buffer[i])) {
422 return false;
425 tmp.swap(target);
426 return true;
429 template <typename stream, CORBA::ULong MAX>
430 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::Short, MAX> & source) {
431 ::CORBA::ULong const length = source.length ();
432 if (length > source.maximum () || !(strm << length)) {
433 return false;
435 return strm.write_short_array (source.get_buffer (), length);
438 template <typename stream, CORBA::ULong MAX>
439 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::Long, MAX> & source) {
440 ::CORBA::ULong const length = source.length ();
441 if (length > source.maximum () || !(strm << length)) {
442 return false;
444 return strm.write_long_array (source.get_buffer (), length);
447 template <typename stream, CORBA::ULong MAX>
448 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::ULong, MAX> & source) {
449 ::CORBA::ULong const length = source.length ();
450 if (length > source.maximum () || !(strm << length)) {
451 return false;
453 return strm.write_ulong_array (source.get_buffer (), length);
456 template <typename stream, CORBA::ULong MAX>
457 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::UShort, MAX> & source) {
458 ::CORBA::ULong const length = source.length ();
459 if (length > source.maximum () || !(strm << length)) {
460 return false;
462 return strm.write_ushort_array (source.get_buffer (), length);
465 template <typename stream, CORBA::ULong MAX>
466 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::Octet, MAX> & source) {
467 ::CORBA::ULong const length = source.length ();
468 if (length > source.maximum () || !(strm << length)) {
469 return false;
471 return strm.write_octet_array (source.get_buffer (), length);
474 template <typename stream, CORBA::ULong MAX>
475 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::Char, MAX> & source) {
476 ::CORBA::ULong const length = source.length ();
477 if (length > source.maximum () || !(strm << length)) {
478 return false;
480 return strm.write_char_array (source.get_buffer (), length);
483 # if (defined (ACE_HAS_WCHAR) || defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
484 template <typename stream, CORBA::ULong MAX>
485 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::WChar, MAX> & source) {
486 ::CORBA::ULong const length = source.length ();
487 if (length > source.maximum () || !(strm << length)) {
488 return false;
490 return strm.write_wchar_array (source.get_buffer (), length);
492 #endif
494 template <typename stream, CORBA::ULong MAX>
495 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::Float, MAX> & source) {
496 ::CORBA::ULong const length = source.length ();
497 if (length > source.maximum () || !(strm << length)) {
498 return false;
500 return strm.write_float_array (source.get_buffer (), length);
503 template <typename stream, CORBA::ULong MAX>
504 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::Double, MAX> & source) {
505 ::CORBA::ULong const length = source.length ();
506 if (length > source.maximum () || !(strm << length)) {
507 return false;
509 return strm.write_double_array (source.get_buffer (), length);
512 template <typename stream, CORBA::ULong MAX>
513 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::LongLong, MAX> & source) {
514 ::CORBA::ULong const length = source.length ();
515 if (length > source.maximum () || !(strm << length)) {
516 return false;
518 return strm.write_longlong_array (source.get_buffer (), length);
521 template <typename stream, CORBA::ULong MAX>
522 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::ULongLong, MAX> & source) {
523 ::CORBA::ULong const length = source.length ();
524 if (length > source.maximum () || !(strm << length)) {
525 return false;
527 return strm.write_ulonglong_array (source.get_buffer (), length);
530 template <typename stream, CORBA::ULong MAX>
531 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::LongDouble, MAX> & source) {
532 ::CORBA::ULong const length = source.length ();
533 if (length > source.maximum () || !(strm << length)) {
534 return false;
536 return strm.write_longdouble_array (source.get_buffer (), length);
539 template <typename stream, CORBA::ULong MAX>
540 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <CORBA::Boolean, MAX> & source) {
541 ::CORBA::ULong const length = source.length ();
542 if (length > source.maximum () || !(strm << length)) {
543 return false;
545 return strm.write_boolean_array (source.get_buffer (), length);
548 template <typename stream, CORBA::ULong MAX>
549 bool marshal_sequence(stream & strm,
550 const TAO::bounded_value_sequence <CORBA::IDLv4::UInt8, MAX, CORBA::IDLv4::UInt8_tag> & source) {
551 ::CORBA::ULong const length = source.length ();
552 if (length > source.maximum () || !(strm << length)) {
553 return false;
555 return strm.write_uint8_array (source.get_buffer (), length);
558 template <typename stream, CORBA::ULong MAX>
559 bool marshal_sequence(stream & strm,
560 const TAO::bounded_value_sequence <CORBA::IDLv4::Int8, MAX, CORBA::IDLv4::Int8_tag> & source) {
561 ::CORBA::ULong const length = source.length ();
562 if (length > source.maximum () || !(strm << length)) {
563 return false;
565 return strm.write_int8_array (source.get_buffer (), length);
568 template <typename stream, typename value_t, CORBA::ULong MAX>
569 bool marshal_sequence(stream & strm, const TAO::bounded_value_sequence <value_t, MAX> & source) {
570 ::CORBA::ULong const length = source.length ();
571 if (length > source.maximum () || !(strm << length)) {
572 return false;
574 for(CORBA::ULong i = 0; i < length; ++i) {
575 if (!(strm << source[i])) {
576 return false;
579 return true;
582 template <typename stream, typename charT, CORBA::ULong MAX>
583 bool marshal_sequence(stream & strm, const TAO::bounded_basic_string_sequence <charT, MAX> & source) {
584 ::CORBA::ULong const length = source.length ();
585 if (length > source.maximum () || !(strm << length)) {
586 return false;
588 for(CORBA::ULong i = 0; i < length; ++i) {
589 if (!(strm << source[i])) {
590 return false;
593 return true;
596 template <typename stream, typename charT, CORBA::ULong MAX, CORBA::ULong BD_STR_MAX>
597 bool marshal_sequence(stream & strm, const TAO::bounded_bd_string_sequence <charT, MAX, BD_STR_MAX> & source) {
598 ::CORBA::ULong const length = source.length ();
599 if (length > source.maximum () || !(strm << length)) {
600 return false;
602 for(CORBA::ULong i = 0; i < length; ++i) {
603 if (source[i].in () != 0 &&
604 ACE_OS::strlen (source[i]) > source.bd_string_maximum ()) {
605 throw ::CORBA::BAD_PARAM ();
607 if (!(strm << source[i])) {
608 return false;
611 return true;
614 template <typename stream, typename object_t, typename object_t_var, CORBA::ULong MAX>
615 bool marshal_sequence(stream & strm, const TAO::bounded_object_reference_sequence<object_t, object_t_var, MAX> & source) {
616 typedef typename TAO::bounded_object_reference_sequence<object_t, object_t_var, MAX>::object_type object_type;
617 ::CORBA::ULong const length = source.length ();
618 if (length > source.maximum () || !(strm << length)) {
619 return false;
621 for(CORBA::ULong i = 0; i < length; ++i) {
622 if (!TAO::Objref_Traits<object_type>::marshal (source[i], strm)) {
623 return false;
626 return true;
628 } // namespace TAO
630 TAO_END_VERSIONED_NAMESPACE_DECL
632 #endif /* TAO_BOUNDED_SEQUENCE_CDR_T_H */