00001 #ifndef guard_unbounded_sequence_cdr
00002 #define guard_unbounded_sequence_cdr
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "tao/orbconf.h"
00015 #include "tao/CORBA_String.h"
00016 #include "tao/SystemException.h"
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 namespace TAO {
00021 template <typename stream>
00022 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Short> & target) {
00023 typedef TAO::unbounded_value_sequence <CORBA::Short> sequence;
00024 ::CORBA::ULong new_length = 0;
00025 if (!(strm >> new_length)) {
00026 return false;
00027 }
00028 if (new_length > strm.length()) {
00029 return false;
00030 }
00031 sequence tmp(new_length);
00032 tmp.length(new_length);
00033 typename sequence::value_type * buffer = tmp.get_buffer();
00034 if (!strm.read_short_array (buffer, new_length)) {
00035 return false;
00036 }
00037 tmp.swap(target);
00038 return true;
00039 }
00040
00041 template <typename stream>
00042 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Long> & target) {
00043 typedef TAO::unbounded_value_sequence <CORBA::Long> sequence;
00044 ::CORBA::ULong new_length = 0;
00045 if (!(strm >> new_length)) {
00046 return false;
00047 }
00048 if (new_length > strm.length()) {
00049 return false;
00050 }
00051 sequence tmp(new_length);
00052 tmp.length(new_length);
00053 typename sequence::value_type * buffer = tmp.get_buffer();
00054 if (!strm.read_long_array (buffer, new_length)) {
00055 return false;
00056 }
00057 tmp.swap(target);
00058 return true;
00059 }
00060
00061 template <typename stream>
00062 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::ULong> & target) {
00063 typedef TAO::unbounded_value_sequence <CORBA::ULong> sequence;
00064 ::CORBA::ULong new_length = 0;
00065 if (!(strm >> new_length)) {
00066 return false;
00067 }
00068 if (new_length > strm.length()) {
00069 return false;
00070 }
00071 sequence tmp(new_length);
00072 tmp.length(new_length);
00073 typename sequence::value_type * buffer = tmp.get_buffer();
00074 if (!strm.read_ulong_array (buffer, new_length)) {
00075 return false;
00076 }
00077 tmp.swap(target);
00078 return true;
00079 }
00080
00081 template <typename stream>
00082 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::UShort> & target) {
00083 typedef TAO::unbounded_value_sequence <CORBA::UShort> sequence;
00084 ::CORBA::ULong new_length = 0;
00085 if (!(strm >> new_length)) {
00086 return false;
00087 }
00088 if (new_length > strm.length()) {
00089 return false;
00090 }
00091 sequence tmp(new_length);
00092 tmp.length(new_length);
00093 typename sequence::value_type * buffer = tmp.get_buffer();
00094 if (!strm.read_ushort_array (buffer, new_length)) {
00095 return false;
00096 }
00097 tmp.swap(target);
00098 return true;
00099 }
00100
00101 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
00102 template <typename stream>
00103 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Octet> & target) {
00104 typedef TAO::unbounded_value_sequence <CORBA::Octet> sequence;
00105 ::CORBA::ULong new_length = 0;
00106 if (!(strm >> new_length)) {
00107 return false;
00108 }
00109 if (new_length > strm.length()) {
00110 return false;
00111 }
00112 sequence tmp(new_length);
00113 tmp.length(new_length);
00114 if (ACE_BIT_DISABLED (strm.start ()->flags (), ACE_Message_Block::DONT_DELETE))
00115 {
00116 TAO_ORB_Core* orb_core = strm.orb_core ();
00117 if (orb_core != 0 && strm.orb_core ()->resource_factory ()->
00118 input_cdr_allocator_type_locked () == 1)
00119 {
00120 tmp.replace (new_length, strm.start ());
00121 tmp.mb ()->wr_ptr (tmp.mb()->rd_ptr () + new_length);
00122 strm.skip_bytes (new_length);
00123 tmp.swap(target);
00124 return true;
00125 }
00126 }
00127 typename sequence::value_type * buffer = tmp.get_buffer();
00128 if (!strm.read_octet_array (buffer, new_length)) {
00129 return false;
00130 }
00131 tmp.swap(target);
00132 return true;
00133 }
00134 #else
00135 template <typename stream>
00136 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Octet> & target) {
00137 typedef TAO::unbounded_value_sequence <CORBA::Octet> sequence;
00138 ::CORBA::ULong new_length = 0;
00139 if (!(strm >> new_length)) {
00140 return false;
00141 }
00142 if (new_length > strm.length()) {
00143 return false;
00144 }
00145 sequence tmp(new_length);
00146 tmp.length(new_length);
00147 typename sequence::value_type * buffer = tmp.get_buffer();
00148 if (!strm.read_octet_array (buffer, new_length)) {
00149 return false;
00150 }
00151 tmp.swap(target);
00152 return true;
00153 }
00154 #endif
00155
00156 template <typename stream>
00157 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Char> & target) {
00158 typedef TAO::unbounded_value_sequence <CORBA::Char> sequence;
00159 ::CORBA::ULong new_length = 0;
00160 if (!(strm >> new_length)) {
00161 return false;
00162 }
00163 if (new_length > strm.length()) {
00164 return false;
00165 }
00166 sequence tmp(new_length);
00167 tmp.length(new_length);
00168 typename sequence::value_type * buffer = tmp.get_buffer();
00169 if (!strm.read_char_array (buffer, new_length)) {
00170 return false;
00171 }
00172 tmp.swap(target);
00173 return true;
00174 }
00175
00176 # if (defined (ACE_HAS_WCHAR) || defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
00177 template <typename stream>
00178 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::WChar> & target) {
00179 typedef TAO::unbounded_value_sequence <CORBA::WChar> sequence;
00180 ::CORBA::ULong new_length = 0;
00181 if (!(strm >> new_length)) {
00182 return false;
00183 }
00184 if (new_length > strm.length()) {
00185 return false;
00186 }
00187 sequence tmp(new_length);
00188 tmp.length(new_length);
00189 typename sequence::value_type * buffer = tmp.get_buffer();
00190 if (!strm.read_wchar_array (buffer, new_length)) {
00191 return false;
00192 }
00193 tmp.swap(target);
00194 return true;
00195 }
00196 #endif
00197
00198 template <typename stream>
00199 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Float> & target) {
00200 typedef TAO::unbounded_value_sequence <CORBA::Float> sequence;
00201 ::CORBA::ULong new_length = 0;
00202 if (!(strm >> new_length)) {
00203 return false;
00204 }
00205 if (new_length > strm.length()) {
00206 return false;
00207 }
00208 sequence tmp(new_length);
00209 tmp.length(new_length);
00210 typename sequence::value_type * buffer = tmp.get_buffer();
00211 if (!strm.read_float_array (buffer, new_length)) {
00212 return false;
00213 }
00214 tmp.swap(target);
00215 return true;
00216 }
00217
00218 template <typename stream>
00219 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Double> & target) {
00220 typedef TAO::unbounded_value_sequence <CORBA::Double> sequence;
00221 ::CORBA::ULong new_length = 0;
00222 if (!(strm >> new_length)) {
00223 return false;
00224 }
00225 if (new_length > strm.length()) {
00226 return false;
00227 }
00228 sequence tmp(new_length);
00229 tmp.length(new_length);
00230 typename sequence::value_type * buffer = tmp.get_buffer();
00231 if (!strm.read_double_array (buffer, new_length)) {
00232 return false;
00233 }
00234 tmp.swap(target);
00235 return true;
00236 }
00237
00238 template <typename stream>
00239 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::LongLong> & target) {
00240 typedef TAO::unbounded_value_sequence <CORBA::LongLong> sequence;
00241 ::CORBA::ULong new_length = 0;
00242 if (!(strm >> new_length)) {
00243 return false;
00244 }
00245 if (new_length > strm.length()) {
00246 return false;
00247 }
00248 sequence tmp(new_length);
00249 tmp.length(new_length);
00250 typename sequence::value_type * buffer = tmp.get_buffer();
00251 if (!strm.read_longlong_array (buffer, new_length)) {
00252 return false;
00253 }
00254 tmp.swap(target);
00255 return true;
00256 }
00257
00258 template <typename stream>
00259 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::ULongLong> & target) {
00260 typedef TAO::unbounded_value_sequence <CORBA::ULongLong> sequence;
00261 ::CORBA::ULong new_length = 0;
00262 if (!(strm >> new_length)) {
00263 return false;
00264 }
00265 if (new_length > strm.length()) {
00266 return false;
00267 }
00268 sequence tmp(new_length);
00269 tmp.length(new_length);
00270 typename sequence::value_type * buffer = tmp.get_buffer();
00271 if (!strm.read_ulonglong_array (buffer, new_length)) {
00272 return false;
00273 }
00274 tmp.swap(target);
00275 return true;
00276 }
00277
00278 template <typename stream>
00279 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::LongDouble> & target) {
00280 typedef TAO::unbounded_value_sequence <CORBA::LongDouble> sequence;
00281 ::CORBA::ULong new_length = 0;
00282 if (!(strm >> new_length)) {
00283 return false;
00284 }
00285 if (new_length > strm.length()) {
00286 return false;
00287 }
00288 sequence tmp(new_length);
00289 tmp.length(new_length);
00290 typename sequence::value_type * buffer = tmp.get_buffer();
00291 if (!strm.read_longdouble_array (buffer, new_length)) {
00292 return false;
00293 }
00294 tmp.swap(target);
00295 return true;
00296 }
00297
00298 template <typename stream>
00299 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <CORBA::Boolean> & target) {
00300 typedef TAO::unbounded_value_sequence <CORBA::Boolean> sequence;
00301 ::CORBA::ULong new_length = 0;
00302 if (!(strm >> new_length)) {
00303 return false;
00304 }
00305 if (new_length > strm.length()) {
00306 return false;
00307 }
00308 sequence tmp(new_length);
00309 tmp.length(new_length);
00310 typename sequence::value_type * buffer = tmp.get_buffer();
00311 if (!strm.read_boolean_array (buffer, new_length)) {
00312 return false;
00313 }
00314 tmp.swap(target);
00315 return true;
00316 }
00317
00318 template <typename stream, typename value_t>
00319 bool demarshal_sequence(stream & strm, TAO::unbounded_value_sequence <value_t> & target) {
00320 typedef TAO::unbounded_value_sequence <value_t> sequence;
00321 ::CORBA::ULong new_length = 0;
00322 if (!(strm >> new_length)) {
00323 return false;
00324 }
00325 if (new_length > strm.length()) {
00326 return false;
00327 }
00328 sequence tmp(new_length);
00329 tmp.length(new_length);
00330 typename sequence::value_type * buffer = tmp.get_buffer();
00331 for(CORBA::ULong i = 0; i < new_length; ++i) {
00332 if (!(strm >> buffer[i])) {
00333 return false;
00334 }
00335 }
00336 tmp.swap(target);
00337 return true;
00338 }
00339
00340 template <typename stream, typename charT>
00341 bool demarshal_sequence(stream & strm, TAO::unbounded_basic_string_sequence <charT> & target) {
00342 typedef TAO::unbounded_basic_string_sequence <charT> sequence;
00343 typedef typename sequence::element_traits::string_var string_var;
00344 typedef typename sequence::allocation_traits sequence_allocation_traits;
00345 ::CORBA::ULong new_length = 0;
00346 if (!(strm >> new_length)) {
00347 return false;
00348 }
00349 if (new_length > strm.length()) {
00350 return false;
00351 }
00352 sequence tmp(new_length, new_length,
00353 sequence_allocation_traits::allocbuf_noinit(new_length),
00354 true);
00355 for(CORBA::ULong i = 0; i < new_length; ++i) {
00356 string_var string;
00357 if (!(strm >> string.inout ())) {
00358 return false;
00359 }
00360 else {
00361 tmp[i] = string._retn ();
00362 }
00363 }
00364 tmp.swap(target);
00365 return true;
00366 }
00367
00368 template <typename stream, typename charT, CORBA::ULong BD_STR_MAX>
00369 bool demarshal_sequence(stream & strm, TAO::unbounded_bd_string_sequence <charT, BD_STR_MAX> & target) {
00370 typedef TAO::unbounded_bd_string_sequence <charT, BD_STR_MAX> sequence;
00371 typedef typename sequence::element_traits::string_var string_var;
00372 typedef typename sequence::allocation_traits sequence_allocation_traits;
00373 ::CORBA::ULong new_length = 0;
00374 if (!(strm >> new_length)) {
00375 return false;
00376 }
00377 if (new_length > strm.length()) {
00378 return false;
00379 }
00380 sequence tmp(new_length, new_length,
00381 sequence_allocation_traits::allocbuf_noinit(new_length),
00382 true);
00383 for(CORBA::ULong i = 0; i < new_length; ++i) {
00384 string_var string;
00385 if (!(strm >> string.inout ())) {
00386 return false;
00387 }
00388 else {
00389 if (string.in () != 0 &&
00390 ACE_OS::strlen (string.in ()) > tmp.bd_string_maximum ()) {
00391 throw ::CORBA::BAD_PARAM ();
00392 }
00393 tmp[i] = string._retn ();
00394 }
00395 }
00396 tmp.swap(target);
00397 return true;
00398 }
00399
00400 template <typename stream, typename object_t, typename object_t_var>
00401 bool demarshal_sequence(stream & strm, TAO::unbounded_object_reference_sequence<object_t, object_t_var> & target) {
00402 typedef TAO::unbounded_object_reference_sequence<object_t, object_t_var> sequence;
00403 typedef typename sequence::allocation_traits sequence_allocation_traits;
00404 ::CORBA::ULong new_length = 0;
00405 if (!(strm >> new_length)) {
00406 return false;
00407 }
00408 if (new_length > strm.length()) {
00409 return false;
00410 }
00411 sequence tmp(new_length, new_length,
00412 sequence_allocation_traits::allocbuf_noinit(new_length),
00413 true);
00414 typename sequence::value_type * buffer = tmp.get_buffer();
00415 for(CORBA::ULong i = 0; i < new_length; ++i) {
00416 if (!(strm >> buffer[i])) {
00417 return false;
00418 }
00419 }
00420 tmp.swap(target);
00421 return true;
00422 }
00423 }
00424
00425 namespace TAO {
00426 template <typename stream>
00427 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Short> & source) {
00428 ::CORBA::ULong const length = source.length ();
00429 if (!(strm << length)) {
00430 return false;
00431 }
00432 return strm.write_short_array (source.get_buffer (), length);
00433 }
00434
00435 template <typename stream>
00436 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Long> & source) {
00437 ::CORBA::ULong const length = source.length ();
00438 if (!(strm << length)) {
00439 return false;
00440 }
00441 return strm.write_long_array (source.get_buffer (), length);
00442 }
00443
00444 template <typename stream>
00445 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::ULong> & source) {
00446 ::CORBA::ULong const length = source.length ();
00447 if (!(strm << length)) {
00448 return false;
00449 }
00450 return strm.write_ulong_array (source.get_buffer (), length);
00451 }
00452
00453 template <typename stream>
00454 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::UShort> & source) {
00455 ::CORBA::ULong const length = source.length ();
00456 if (!(strm << length)) {
00457 return false;
00458 }
00459 return strm.write_ushort_array (source.get_buffer (), length);
00460 }
00461
00462 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
00463 template <typename stream>
00464 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Octet> & source) {
00465 ::CORBA::ULong const length = source.length ();
00466 if (!(strm << length)) {
00467 return false;
00468 }
00469 if (source.mb ()) {
00470 return strm.write_octet_array_mb (source.mb ());
00471 }
00472 return strm.write_octet_array (source.get_buffer (), length);
00473 }
00474 #else
00475 template <typename stream>
00476 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Octet> & source) {
00477 ::CORBA::ULong const length = source.length ();
00478 if (!(strm << length)) {
00479 return false;
00480 }
00481 return strm.write_octet_array (source.get_buffer (), length);
00482 }
00483 #endif
00484
00485 template <typename stream>
00486 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Char> & source) {
00487 ::CORBA::ULong const length = source.length ();
00488 if (!(strm << length)) {
00489 return false;
00490 }
00491 return strm.write_char_array (source.get_buffer (), length);
00492 }
00493
00494 # if (defined (ACE_HAS_WCHAR) || defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
00495 template <typename stream>
00496 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::WChar> & source) {
00497 ::CORBA::ULong const length = source.length ();
00498 if (!(strm << length)) {
00499 return false;
00500 }
00501 return strm.write_wchar_array (source.get_buffer (), length);
00502 }
00503 #endif
00504
00505 template <typename stream>
00506 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Float> & source) {
00507 ::CORBA::ULong const length = source.length ();
00508 if (!(strm << length)) {
00509 return false;
00510 }
00511 return strm.write_float_array (source.get_buffer (), length);
00512 }
00513
00514 template <typename stream>
00515 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Double> & source) {
00516 ::CORBA::ULong const length = source.length ();
00517 if (!(strm << length)) {
00518 return false;
00519 }
00520 return strm.write_double_array (source.get_buffer (), length);
00521 }
00522
00523 template <typename stream>
00524 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::LongLong> & source) {
00525 ::CORBA::ULong const length = source.length ();
00526 if (!(strm << length)) {
00527 return false;
00528 }
00529 return strm.write_longlong_array (source.get_buffer (), length);
00530 }
00531
00532 template <typename stream>
00533 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::ULongLong> & source) {
00534 ::CORBA::ULong const length = source.length ();
00535 if (!(strm << length)) {
00536 return false;
00537 }
00538 return strm.write_ulonglong_array (source.get_buffer (), length);
00539 }
00540
00541 template <typename stream>
00542 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::LongDouble> & source) {
00543 ::CORBA::ULong const length = source.length ();
00544 if (!(strm << length)) {
00545 return false;
00546 }
00547 return strm.write_longdouble_array (source.get_buffer (), length);
00548 }
00549
00550 template <typename stream>
00551 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Boolean> & source) {
00552 ::CORBA::ULong const length = source.length ();
00553 if (!(strm << length)) {
00554 return false;
00555 }
00556 return strm.write_boolean_array (source.get_buffer (), length);
00557 }
00558
00559 template <typename stream, typename value_t>
00560 bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <value_t> & source) {
00561 ::CORBA::ULong const length = source.length ();
00562 if (!(strm << length)) {
00563 return false;
00564 }
00565 for(CORBA::ULong i = 0; i < length; ++i) {
00566 if (!(strm << source[i])) {
00567 return false;
00568 }
00569 }
00570 return true;
00571 }
00572
00573 template <typename stream, typename charT>
00574 bool marshal_sequence(stream & strm, const TAO::unbounded_basic_string_sequence <charT> & source) {
00575 ::CORBA::ULong const length = source.length ();
00576 if (!(strm << length)) {
00577 return false;
00578 }
00579 for(CORBA::ULong i = 0; i < length; ++i) {
00580 if (!(strm << source[i])) {
00581 return false;
00582 }
00583 }
00584 return true;
00585 }
00586
00587 template <typename stream, typename charT, CORBA::ULong BD_STR_MAX>
00588 bool marshal_sequence(stream & strm, const TAO::unbounded_bd_string_sequence <charT, BD_STR_MAX> & source) {
00589 ::CORBA::ULong const length = source.length ();
00590 if (!(strm << length)) {
00591 return false;
00592 }
00593 for(CORBA::ULong i = 0; i < length; ++i) {
00594 if (source[i].in () != 0 &&
00595 ACE_OS::strlen (source[i]) > source.bd_string_maximum ()) {
00596 throw ::CORBA::BAD_PARAM ();
00597 }
00598 if (!(strm << source[i])) {
00599 return false;
00600 }
00601 }
00602 return true;
00603 }
00604
00605 template <typename stream, typename object_t, typename object_t_var>
00606 bool marshal_sequence(stream & strm, const TAO::unbounded_object_reference_sequence<object_t, object_t_var> & source) {
00607 typedef typename TAO::unbounded_object_reference_sequence<object_t, object_t_var>::object_type objec_t;
00608 ::CORBA::ULong const length = source.length ();
00609 if (!(strm << length)) {
00610 return false;
00611 }
00612 for(CORBA::ULong i = 0; i < length; ++i) {
00613 if (!TAO::Objref_Traits<objec_t>::marshal (source[i], strm)) {
00614 return false;
00615 }
00616 }
00617 return true;
00618 }
00619 }
00620
00621 TAO_END_VERSIONED_NAMESPACE_DECL
00622
00623 #endif