TAO_Marshal_Union Class Reference

TAO_Marshal_Union. More...

#include <Marshal.h>

Inheritance diagram for TAO_Marshal_Union:

Inheritance graph
[legend]
Collaboration diagram for TAO_Marshal_Union:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_Marshal_Union (void)
virtual TAO::traverse_status skip (CORBA::TypeCode_ptr tc, TAO_InputCDR *context)
 skip operation

virtual TAO::traverse_status append (CORBA::TypeCode_ptr tc, TAO_InputCDR *src, TAO_OutputCDR *dest)
 append operation


Detailed Description

TAO_Marshal_Union.

marshal a union

Definition at line 246 of file Marshal.h.


Constructor & Destructor Documentation

ACE_INLINE TAO_Marshal_Union::TAO_Marshal_Union void   ) 
 

Definition at line 43 of file Marshal.inl.

00044 {
00045 }


Member Function Documentation

TAO::traverse_status TAO_Marshal_Union::append CORBA::TypeCode_ptr  tc,
TAO_InputCDR src,
TAO_OutputCDR dest
[virtual]
 

append operation

Implements TAO_Marshal_Object.

Definition at line 357 of file append.cpp.

References TAO::Unknown_IDL_Type::_tao_get_cdr(), CORBA::Char, TAO::Any_Impl::encoded(), CORBA::Long, TAO::Any_Impl::marshal_value(), TAO_Marshal_Object::perform_append(), ACE_InputCDR::read_boolean(), ACE_InputCDR::read_char(), ACE_InputCDR::read_long(), ACE_InputCDR::read_short(), ACE_InputCDR::read_ulong(), ACE_InputCDR::read_ushort(), ACE_InputCDR::read_wchar(), CORBA::Short, CORBA::Any::to_boolean, CORBA::Any::to_char, CORBA::Any::to_octet, CORBA::Any::to_wchar, CORBA::ULong, CORBA::UShort, CORBA::WChar, ACE_OutputCDR::write_boolean(), ACE_OutputCDR::write_char(), ACE_OutputCDR::write_long(), ACE_OutputCDR::write_short(), ACE_OutputCDR::write_ulong(), ACE_OutputCDR::write_ushort(), and ACE_OutputCDR::write_wchar().

00360 {
00361   CORBA::TypeCode_var discrim_tc = tc->discriminator_type ();
00362 
00363   CORBA::ULong kind = discrim_tc->kind ();
00364 
00365   // Save the discriminator value in a temporary variable...
00366   CORBA::Short short_v = CORBA::Short();
00367   CORBA::UShort ushort_v = CORBA::UShort();
00368   CORBA::Long long_v = CORBA::Long();
00369   CORBA::ULong ulong_v = CORBA::ULong();
00370   CORBA::ULong enum_v = CORBA::ULong();
00371   CORBA::Char char_v = CORBA::Char();
00372   CORBA::WChar wchar_v = CORBA::WChar();
00373   CORBA::Boolean boolean_v = false;
00374 
00375   switch (kind)
00376     {
00377     case CORBA::tk_short:
00378       {
00379         if (!src->read_short (short_v)
00380             || !dest->write_short (short_v))
00381           return TAO::TRAVERSE_STOP;
00382       }
00383       break;
00384 
00385     case CORBA::tk_ushort:
00386       {
00387         if (!src->read_ushort (ushort_v)
00388             || !dest->write_ushort (ushort_v))
00389           return TAO::TRAVERSE_STOP;
00390       }
00391       break;
00392 
00393     case CORBA::tk_long:
00394       {
00395         if (!src->read_long (long_v)
00396             || !dest->write_long (long_v))
00397           return TAO::TRAVERSE_STOP;
00398       }
00399       break;
00400 
00401     case CORBA::tk_ulong:
00402       {
00403         if (!src->read_ulong (ulong_v)
00404             || !dest->write_ulong (ulong_v))
00405           return TAO::TRAVERSE_STOP;
00406       }
00407       break;
00408 
00409     case CORBA::tk_enum:
00410       {
00411         if (!src->read_ulong (enum_v)
00412             || !dest->write_ulong (enum_v))
00413           return TAO::TRAVERSE_STOP;
00414       }
00415       break;
00416 
00417     case CORBA::tk_char:
00418       {
00419         if (!src->read_char (char_v)
00420             || !dest->write_char (char_v))
00421           return TAO::TRAVERSE_STOP;
00422       }
00423       break;
00424 
00425     case CORBA::tk_wchar:
00426       {
00427         if (!src->read_wchar (wchar_v)
00428             || !dest->write_wchar (wchar_v))
00429           return TAO::TRAVERSE_STOP;
00430       }
00431       break;
00432 
00433     case CORBA::tk_boolean:
00434       {
00435         if (!src->read_boolean (boolean_v)
00436             || !dest->write_boolean (boolean_v))
00437           return TAO::TRAVERSE_STOP;
00438       }
00439       break;
00440 
00441     default:
00442       return TAO::TRAVERSE_STOP;
00443     }
00444 
00445   const CORBA::ULong member_count =
00446     tc->member_count ();
00447 
00448   const CORBA::ULong null_member = ~static_cast<CORBA::ULong> (0U);
00449 
00450   CORBA::ULong current_member = null_member;
00451   CORBA::ULong default_member = null_member;
00452 
00453   for (CORBA::ULong i = 0;
00454        i < member_count && current_member == null_member;
00455        ++i)
00456     {
00457       CORBA::Any_var any = tc->member_label (i);
00458 
00459       CORBA::Octet o;
00460 
00461       if ((any >>= CORBA::Any::to_octet (o)) && o == 0)
00462         {
00463           CORBA::ULong default_index =
00464             tc->default_index ();
00465 
00466           if (i != default_index)
00467             throw ::CORBA::BAD_TYPECODE ();
00468           // Found the default branch, save its position and continue
00469           // trying to find the current value...
00470           default_member = i;
00471           continue;
00472         }
00473 
00474       switch (kind)
00475         {
00476         case CORBA::tk_short:
00477           {
00478             CORBA::Short d;
00479             if ((any >>= d) && d == short_v)
00480               current_member = i;
00481           }
00482           break;
00483 
00484         case CORBA::tk_ushort:
00485           {
00486             CORBA::UShort d;
00487             if ((any >>= d) && d == ushort_v)
00488               current_member = i;
00489           }
00490           break;
00491 
00492         case CORBA::tk_long:
00493           {
00494             CORBA::Long d;
00495             if ((any >>= d) && d == long_v)
00496               current_member = i;
00497           }
00498           break;
00499 
00500         case CORBA::tk_ulong:
00501           {
00502             CORBA::ULong d;
00503             if ((any >>= d) && d == ulong_v)
00504               current_member = i;
00505           }
00506           break;
00507 
00508         case CORBA::tk_enum:
00509           {
00510             CORBA::ULong d;
00511             TAO::Any_Impl *impl = any->impl ();
00512 
00513             if (impl->encoded ())
00514               {
00515                 TAO::Unknown_IDL_Type * const unk =
00516                   dynamic_cast<TAO::Unknown_IDL_Type *> (impl);
00517 
00518                 if (!unk)
00519                   throw ::CORBA::INTERNAL ();
00520 
00521                 // We don't want unk's rd_ptr to move, in case
00522                 // we are shared by another Any, so we use this
00523                 // to copy the state, not the buffer.
00524                 TAO_InputCDR for_reading (unk->_tao_get_cdr ());
00525 
00526                 for_reading.read_ulong (d);
00527               }
00528             else
00529               {
00530                 TAO_OutputCDR out;
00531                 impl->marshal_value (out);
00532                 TAO_InputCDR cdr (out);
00533                 cdr.read_ulong (d);
00534               }
00535 
00536             if (d == enum_v)
00537               {
00538                 current_member = i;
00539               }
00540           }
00541           break;
00542 
00543         case CORBA::tk_char:
00544           {
00545             CORBA::Char d;
00546             if ((any >>= CORBA::Any::to_char (d)) && d == char_v)
00547               current_member = i;
00548           }
00549           break;
00550 
00551         case CORBA::tk_wchar:
00552           {
00553             CORBA::WChar d;
00554             if ((any >>= CORBA::Any::to_wchar (d)) && d == wchar_v)
00555               current_member = i;
00556           }
00557           break;
00558 
00559         case CORBA::tk_boolean:
00560           {
00561             CORBA::Boolean d;
00562             if ((any >>= CORBA::Any::to_boolean (d)) && d == boolean_v)
00563               current_member = i;
00564           }
00565           break;
00566 
00567         default:
00568           return TAO::TRAVERSE_STOP;
00569         }
00570     }
00571 
00572   if (current_member == null_member)
00573     {
00574       // Cannot find the current member, check if there is a
00575       // default...
00576       if (default_member != null_member)
00577         {
00578           // Good, use the default to append...
00579           CORBA::TypeCode_var member_tc =
00580             tc->member_type (default_member);
00581           return TAO_Marshal_Object::perform_append (member_tc.in (),
00582                                                      src,
00583                                                      dest);
00584         }
00585 
00586       // If we're here, we have an implicit default case, and we
00587       // should just return without appending anything, since no
00588       // union member was marshaled in the first place.
00589       return TAO::TRAVERSE_CONTINUE;
00590     }
00591 
00592   // If we found the member successfully then just use that one...
00593   CORBA::TypeCode_var member_tc =
00594     tc->member_type (current_member);
00595   return TAO_Marshal_Object::perform_append (member_tc.in (),
00596                                              src,
00597                                              dest
00598                                             );
00599 }

TAO::traverse_status TAO_Marshal_Union::skip CORBA::TypeCode_ptr  tc,
TAO_InputCDR context
[virtual]
 

skip operation

Implements TAO_Marshal_Object.

Definition at line 321 of file skip.cpp.

References TAO::Unknown_IDL_Type::_tao_get_cdr(), CORBA::Char, TAO::Any_Impl::encoded(), CORBA::Long, TAO::Any_Impl::marshal_value(), TAO_Marshal_Object::perform_skip(), ACE_InputCDR::read_boolean(), ACE_InputCDR::read_char(), ACE_InputCDR::read_long(), ACE_InputCDR::read_short(), ACE_InputCDR::read_ulong(), ACE_InputCDR::read_ushort(), ACE_InputCDR::read_wchar(), CORBA::Short, CORBA::Any::to_boolean, CORBA::Any::to_char, CORBA::Any::to_octet, CORBA::Any::to_wchar, CORBA::ULong, CORBA::UShort, and CORBA::WChar.

00322 {
00323   CORBA::TypeCode_var discrim_tc =
00324     tc->discriminator_type ();
00325 
00326   CORBA::ULong const kind =
00327     discrim_tc->kind ();
00328 
00329   // Save the discriminator value in a temporary variable...
00330   CORBA::Short short_v = CORBA::Short();
00331   CORBA::UShort ushort_v = CORBA::UShort();
00332   CORBA::Long long_v = CORBA::Long();
00333   CORBA::ULong ulong_v = CORBA::ULong();
00334   CORBA::ULong enum_v = CORBA::ULong();
00335   CORBA::Char char_v = CORBA::Char();
00336   CORBA::WChar wchar_v = CORBA::WChar();
00337   CORBA::Boolean boolean_v = false;
00338 
00339   switch (kind)
00340     {
00341     case CORBA::tk_short:
00342       {
00343         if (!src->read_short (short_v))
00344           return TAO::TRAVERSE_STOP;
00345       }
00346       break;
00347 
00348     case CORBA::tk_ushort:
00349       {
00350         if (!src->read_ushort (ushort_v))
00351           return TAO::TRAVERSE_STOP;
00352       }
00353       break;
00354 
00355     case CORBA::tk_long:
00356       {
00357         if (!src->read_long (long_v))
00358           return TAO::TRAVERSE_STOP;
00359       }
00360       break;
00361 
00362     case CORBA::tk_ulong:
00363       {
00364         if (!src->read_ulong (ulong_v))
00365           return TAO::TRAVERSE_STOP;
00366       }
00367       break;
00368 
00369     case CORBA::tk_enum:
00370       {
00371         if (!src->read_ulong (enum_v))
00372           return TAO::TRAVERSE_STOP;
00373       }
00374       break;
00375 
00376     case CORBA::tk_char:
00377       {
00378         if (!src->read_char (char_v))
00379           return TAO::TRAVERSE_STOP;
00380       }
00381       break;
00382 
00383     case CORBA::tk_wchar:
00384       {
00385         if (!src->read_wchar (wchar_v))
00386           return TAO::TRAVERSE_STOP;
00387       }
00388       break;
00389 
00390     case CORBA::tk_boolean:
00391       {
00392         if (!src->read_boolean (boolean_v))
00393           return TAO::TRAVERSE_STOP;
00394       }
00395       break;
00396 
00397     default:
00398       return TAO::TRAVERSE_STOP;
00399     }
00400 
00401   const CORBA::ULong member_count =
00402     tc->member_count ();
00403 
00404   const CORBA::ULong null_member = ~static_cast<CORBA::ULong> (0U);
00405 
00406   CORBA::ULong current_member = null_member;
00407   CORBA::ULong default_member = null_member;
00408 
00409   for (CORBA::ULong i = 0;
00410        i < member_count && current_member == null_member;
00411        ++i)
00412     {
00413       CORBA::Any_var any = tc->member_label (i);
00414 
00415       CORBA::Octet o;
00416       if ((any >>= CORBA::Any::to_octet (o)) && o == 0)
00417         {
00418           CORBA::ULong default_index =
00419             tc->default_index ();
00420 
00421           if (i != default_index)
00422             throw ::CORBA::BAD_TYPECODE ();
00423           // Found the default branch, save its position and continue
00424           // trying to find the current value...
00425           default_member = i;
00426           continue;
00427         }
00428 
00429       switch (kind)
00430         {
00431         case CORBA::tk_short:
00432           {
00433             CORBA::Short d;
00434             if ((any >>= d) && d == short_v)
00435               current_member = i;
00436           }
00437           break;
00438 
00439         case CORBA::tk_ushort:
00440           {
00441             CORBA::UShort d;
00442             if ((any >>= d) && d == ushort_v)
00443               current_member = i;
00444           }
00445           break;
00446 
00447         case CORBA::tk_long:
00448           {
00449             CORBA::Long d;
00450             if ((any >>= d) && d == long_v)
00451               current_member = i;
00452           }
00453           break;
00454 
00455         case CORBA::tk_ulong:
00456           {
00457             CORBA::ULong d;
00458             if ((any >>= d) && d == ulong_v)
00459               current_member = i;
00460           }
00461           break;
00462 
00463         case CORBA::tk_enum:
00464           {
00465             CORBA::ULong d;
00466             TAO::Any_Impl *impl = any->impl ();
00467 
00468             if (impl->encoded ())
00469               {
00470                 TAO::Unknown_IDL_Type * const unk =
00471                   dynamic_cast<TAO::Unknown_IDL_Type *> (impl);
00472 
00473                 if (!unk)
00474                   throw ::CORBA::INTERNAL ();
00475 
00476                 // We don't want unk's rd_ptr to move, in case
00477                 // we are shared by another Any, so we use this
00478                 // to copy the state, not the buffer.
00479                 TAO_InputCDR for_reading (unk->_tao_get_cdr ());
00480 
00481                 for_reading.read_ulong (d);
00482               }
00483             else
00484               {
00485                 TAO_OutputCDR out;
00486                 impl->marshal_value (out);
00487                 TAO_InputCDR cdr (out);
00488                 cdr.read_ulong (d);
00489               }
00490 
00491             if (d == enum_v)
00492               {
00493                 current_member = i;
00494               }
00495           }
00496           break;
00497 
00498         case CORBA::tk_char:
00499           {
00500             CORBA::Char d;
00501             if ((any >>= CORBA::Any::to_char (d)) && d == char_v)
00502               current_member = i;
00503           }
00504           break;
00505 
00506         case CORBA::tk_wchar:
00507           {
00508             CORBA::WChar d;
00509             if ((any >>= CORBA::Any::to_wchar (d)) && d == wchar_v)
00510               current_member = i;
00511           }
00512           break;
00513 
00514         case CORBA::tk_boolean:
00515           {
00516             CORBA::Boolean d;
00517             if ((any >>= CORBA::Any::to_boolean (d)) && d == boolean_v)
00518               current_member = i;
00519           }
00520           break;
00521 
00522         default:
00523           return TAO::TRAVERSE_STOP;
00524         }
00525     }
00526 
00527   if (current_member == null_member)
00528     {
00529       // Cannot find the current member, check if there is a
00530       // default...
00531       if (default_member != null_member)
00532         {
00533           // Good, use the default to append...
00534           CORBA::TypeCode_var member_tc =
00535             tc->member_type (default_member);
00536           return TAO_Marshal_Object::perform_skip (member_tc.in (), src);
00537         }
00538 
00539       // If we're here, we have an implicit default case, and we
00540       // should just return without skipping anything, since no
00541       // union member was marshaled in the first place.
00542       return TAO::TRAVERSE_CONTINUE;
00543     }
00544 
00545   // If we found the member successfully then just use that one...
00546   CORBA::TypeCode_var member_tc =
00547     tc->member_type (current_member);
00548 
00549   return TAO_Marshal_Object::perform_skip (member_tc.in (), src);
00550 }


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 13:21:58 2008 for TAO_AnyTypeCode by doxygen 1.3.6