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