Unbounded_Sequence_CDR_T.h

Go to the documentation of this file.
00001 #ifndef guard_unbounded_sequence_cdr
00002 #define guard_unbounded_sequence_cdr
00003 /**
00004  * @file
00005  *
00006  * @brief Extract the sequence
00007  *
00008  * $Id: Unbounded_Sequence_CDR_T.h 77525 2007-03-05 11:02:51Z johnnyw $
00009  *
00010  * @author Carlos O'Ryan
00011  * @author Johnny Willemsen
00012  */
00013 
00014 #include "tao/orbconf.h"
00015 #include "tao/CORBA_String.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)) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
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::unbounded_basic_string_sequence <charT> & target) {
00321     typedef TAO::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     ::CORBA::ULong const length = source.length ();
00372     if (!(strm << length)) {
00373       return false;
00374     }
00375     return strm.write_short_array (source.get_buffer (), length);
00376   }
00377 
00378   template <typename stream>
00379   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Long> & source) {
00380     ::CORBA::ULong const length = source.length ();
00381     if (!(strm << length)) {
00382       return false;
00383     }
00384     return strm.write_long_array (source.get_buffer (), length);
00385   }
00386 
00387   template <typename stream>
00388   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::ULong> & source) {
00389     ::CORBA::ULong const length = source.length ();
00390     if (!(strm << length)) {
00391       return false;
00392     }
00393     return strm.write_ulong_array (source.get_buffer (), length);
00394   }
00395 
00396   template <typename stream>
00397   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::UShort> & source) {
00398     ::CORBA::ULong const length = source.length ();
00399     if (!(strm << length)) {
00400       return false;
00401     }
00402     return strm.write_ushort_array (source.get_buffer (), length);
00403   }
00404 
00405 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
00406   template <typename stream>
00407   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Octet> & source) {
00408     ::CORBA::ULong const length = source.length ();
00409     if (!(strm << length)) {
00410       return false;
00411     }
00412     if (source.mb ()) {
00413       return strm.write_octet_array_mb (source.mb ());
00414     }
00415     return strm.write_octet_array (source.get_buffer (), length);
00416   }
00417 #else
00418   template <typename stream>
00419   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Octet> & source) {
00420     ::CORBA::ULong const length = source.length ();
00421     if (!(strm << length)) {
00422       return false;
00423     }
00424     return strm.write_octet_array (source.get_buffer (), length);
00425   }
00426 #endif
00427 
00428   template <typename stream>
00429   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Char> & source) {
00430     ::CORBA::ULong const length = source.length ();
00431     if (!(strm << length)) {
00432       return false;
00433     }
00434     return strm.write_char_array (source.get_buffer (), length);
00435   }
00436 
00437 # if (defined (ACE_HAS_WCHAR) || defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
00438   template <typename stream>
00439   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::WChar> & source) {
00440     ::CORBA::ULong const length = source.length ();
00441     if (!(strm << length)) {
00442       return false;
00443     }
00444     return strm.write_wchar_array (source.get_buffer (), length);
00445   }
00446 #endif
00447 
00448   template <typename stream>
00449   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Float> & source) {
00450     ::CORBA::ULong const length = source.length ();
00451     if (!(strm << length)) {
00452       return false;
00453     }
00454     return strm.write_float_array (source.get_buffer (), length);
00455   }
00456 
00457   template <typename stream>
00458   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Double> & source) {
00459     ::CORBA::ULong const length = source.length ();
00460     if (!(strm << length)) {
00461       return false;
00462     }
00463     return strm.write_double_array (source.get_buffer (), length);
00464   }
00465 
00466   template <typename stream>
00467   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::ULongLong> & source) {
00468     ::CORBA::ULong const length = source.length ();
00469     if (!(strm << length)) {
00470       return false;
00471     }
00472     return strm.write_ulonglong_array (source.get_buffer (), length);
00473   }
00474 
00475   template <typename stream>
00476   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::LongDouble> & source) {
00477     ::CORBA::ULong const length = source.length ();
00478     if (!(strm << length)) {
00479       return false;
00480     }
00481     return strm.write_longdouble_array (source.get_buffer (), length);
00482   }
00483 
00484   template <typename stream>
00485   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <CORBA::Boolean> & source) {
00486     ::CORBA::ULong const length = source.length ();
00487     if (!(strm << length)) {
00488       return false;
00489     }
00490     return strm.write_boolean_array (source.get_buffer (), length);
00491   }
00492 
00493   template <typename stream, typename value_t>
00494   bool marshal_sequence(stream & strm, const TAO::unbounded_value_sequence <value_t> & source) {
00495     ::CORBA::ULong const length = source.length ();
00496     if (!(strm << length)) {
00497       return false;
00498     }
00499     for(CORBA::ULong i = 0; i < length; ++i) {
00500       if (!(strm << source[i])) {
00501         return false;
00502       }
00503     }
00504     return true;
00505   }
00506 
00507   template <typename stream, typename charT>
00508   bool marshal_sequence(stream & strm, const TAO::unbounded_basic_string_sequence <charT> & source) {
00509     ::CORBA::ULong const length = source.length ();
00510     if (!(strm << length)) {
00511       return false;
00512     }
00513     for(CORBA::ULong i = 0; i < length; ++i) {
00514       if (!(strm << source[i])) {
00515         return false;
00516       }
00517     }
00518     return true;
00519   }
00520 
00521   template <typename stream, typename object_t, typename object_t_var>
00522   bool marshal_sequence(stream & strm, const TAO::unbounded_object_reference_sequence<object_t, object_t_var> & source) {
00523     typedef typename TAO::unbounded_object_reference_sequence<object_t, object_t_var>::object_type objec_t;
00524     ::CORBA::ULong const length = source.length ();
00525     if (!(strm << length)) {
00526       return false;
00527     }
00528     for(CORBA::ULong i = 0; i < length; ++i) {
00529       if (!TAO::Objref_Traits<objec_t>::marshal (source[i], strm)) {
00530         return false;
00531       }
00532     }
00533     return true;
00534   }
00535 } // namespace TAO
00536 
00537 TAO_END_VERSIONED_NAMESPACE_DECL
00538 
00539 #endif /* guard_unbounded_sequence_cdr */

Generated on Tue Feb 2 17:37:53 2010 for TAO by  doxygen 1.4.7