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