Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Any.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 // $Id: Any.cpp,v 1.1.1.4.2.3 2003/05/14 14:03:30 chad Exp $
00003 
00004 // Portions of this file are:
00005 // Copyright 1994-1995 by Sun Microsystems Inc.
00006 // All Rights Reserved
00007 
00008 #include "tao/Any.h"
00009 #include "tao/Typecode.h"
00010 #include "tao/Marshal.h"
00011 #include "tao/ORB_Core.h"
00012 #include "tao/Object.h"
00013 #include "tao/AbstractBase.h"
00014 #include "tao/debug.h"
00015 
00016 #if !defined (__ACE_INLINE__)
00017 # include "tao/Any.i"
00018 #endif /* ! __ACE_INLINE__ */
00019 
00020 ACE_RCSID (tao,
00021            Any,
00022            "$Id: Any.cpp,v 1.1.1.4.2.3 2003/05/14 14:03:30 chad Exp $")
00023 
00024 CORBA::TypeCode_ptr
00025 CORBA_Any::type (void) const
00026 {
00027   return CORBA::TypeCode::_duplicate (this->type_.in ());
00028 }
00029 
00030 // Will replace if the TypeCode arg is an alias for the existing one -
00031 // otherwise raises an exception.
00032 
00033 void
00034 CORBA_Any::type (CORBA::TypeCode_ptr tc
00035                  ACE_ENV_ARG_DECL)
00036 {
00037   CORBA::Boolean equiv = this->type_->equivalent (tc
00038                                                   ACE_ENV_ARG_PARAMETER);
00039   ACE_CHECK;
00040 
00041   if (equiv)
00042     {
00043       this->type_ = CORBA::TypeCode::_duplicate (tc);
00044     }
00045   else
00046     {
00047       ACE_THROW (CORBA::BAD_TYPECODE ());
00048     }
00049 }
00050 
00051 // This method is deprecated and will eventually be removed from the
00052 // spec. It is included here for backward compatibility and its return
00053 // value may NOT be cast to anything useful. It will only tell whether the
00054 // Any contains a value or not. Use of >>= is recommended for anything else.
00055 
00056 const void *
00057 CORBA_Any::value (void) const
00058 {
00059   if (this->any_owns_data_)
00060     {
00061       return this->value_;
00062     }
00063   else
00064     {
00065       return this->cdr_;
00066     }
00067 }
00068 
00069 // Default "Any" constructor -- initializes to nulls per the
00070 // OMG C++ mapping.
00071 
00072 // NOTE: null (zero) typecode pointers are also treated as the null
00073 // typecode ...
00074 
00075 CORBA_Any::CORBA_Any (void)
00076   : type_ (CORBA::TypeCode::_duplicate (CORBA::_tc_null)),
00077     byte_order_ (TAO_ENCAP_BYTE_ORDER),
00078     cdr_ (0),
00079     any_owns_data_ (0),
00080     contains_local_ (0),
00081     value_ (0),
00082     destructor_ (0),
00083     char_translator_ (0),
00084     wchar_translator_ (0)
00085 {
00086 }
00087 
00088 CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr tc)
00089   : type_ (CORBA::TypeCode::_duplicate (tc)),
00090     byte_order_ (TAO_ENCAP_BYTE_ORDER),
00091     cdr_ (0),
00092     any_owns_data_ (0),
00093     contains_local_ (0),
00094     value_ (0),
00095     destructor_ (0),
00096     char_translator_ (0),
00097     wchar_translator_ (0)
00098 {
00099 }
00100 
00101 // Constructor using a message block.
00102 CORBA_Any::CORBA_Any (CORBA::TypeCode_ptr type,
00103                       CORBA::UShort,
00104                       int byte_order,
00105                       const ACE_Message_Block* mb)
00106   : type_ (CORBA::TypeCode::_duplicate (type)),
00107     byte_order_ (byte_order),
00108     any_owns_data_ (0),
00109     contains_local_ (0),
00110     value_ (0),
00111     destructor_ (0),
00112     char_translator_ (0),
00113     wchar_translator_ (0)
00114 {
00115   ACE_NEW (this->cdr_,
00116            ACE_Message_Block);
00117   ACE_CDR::consolidate (this->cdr_,
00118                         mb);
00119 }
00120 
00121 // Copy constructor for "Any".
00122 CORBA_Any::CORBA_Any (const CORBA_Any &src)
00123   : cdr_ (0),
00124     any_owns_data_ (0),
00125     contains_local_ (src.contains_local_),
00126     value_ (0),
00127     destructor_ (0),
00128     char_translator_ (0),
00129     wchar_translator_ (0)
00130 
00131 {
00132   if (!CORBA::is_nil (src.type_.in ()))
00133     {
00134       this->type_ = CORBA::TypeCode::_duplicate (src.type_.in ());
00135     }
00136   else
00137     {
00138       this->type_ = CORBA::TypeCode::_duplicate (CORBA::_tc_null);
00139     }
00140 
00141   // CDR stream always contains encoded object, if any holds anything
00142   // at all.
00143   this->byte_order_ = src.byte_order_;
00144 
00145   if (src.cdr_ != 0)
00146     {
00147       ACE_NEW (this->cdr_,
00148                ACE_Message_Block);
00149       ACE_CDR::consolidate (this->cdr_,
00150                             src.cdr_);
00151     }
00152 
00153   this->char_translator_ = src.char_translator_;
00154   this->wchar_translator_ = src.wchar_translator_;
00155 
00156   // No need to copy src's value_.  We can always get that from cdr.
00157 }
00158 
00159 // assignment operator
00160 
00161 CORBA_Any &
00162 CORBA_Any::operator= (const CORBA_Any &src)
00163 {
00164   // Check if it is a self assignment
00165   if (this == &src)
00166     {
00167       return *this;
00168     }
00169 
00170   // Decrement the refcount on the Message_Block we hold, it does not
00171   // matter if we own the data or not, because we always own the
00172   // message block (i.e. it is always cloned or duplicated.
00173   ACE_Message_Block::release ((ACE_Message_Block *) this->cdr_);
00174   this->cdr_ = 0;
00175 
00176   // If we own any previous data, deallocate it.
00177   this->free_value ();
00178 
00179   // Now copy the contents of the source to ourselves.
00180   if (!CORBA::is_nil (src.type_.in ()))
00181     {
00182       this->type_ =
00183         CORBA::TypeCode::_duplicate (src.type_.in ());
00184     }
00185   else
00186     {
00187       this->type_ =
00188         CORBA::TypeCode::_duplicate (CORBA::_tc_null);
00189     }
00190 
00191   this->byte_order_ = src.byte_order_;
00192 
00193   if (src.cdr_ != 0)
00194     {
00195       ACE_NEW_RETURN (this->cdr_,
00196                       ACE_Message_Block,
00197                       *this);
00198 
00199       ACE_CDR::consolidate (this->cdr_,
00200                             src.cdr_);
00201     }
00202 
00203   return *this;
00204 }
00205 
00206 // Destructor for an "Any" deep-frees memory if needed.
00207 CORBA_Any::~CORBA_Any (void)
00208 {
00209   // Decrement the refcount on the Message_Block we hold, it does not
00210   // matter if we own the data or not, because we always own the
00211   // message block (i.e. it is always cloned or duplicated.
00212 
00213   ACE_Message_Block::release (this->cdr_);
00214   this->cdr_ = 0;
00215 
00216   this->free_value ();
00217 }
00218 
00219 // TAO proprietary methods, used in the implementation of the >>= and
00220 // <<= operators.
00221 
00222 void
00223 CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
00224                          int byte_order,
00225                          const ACE_Message_Block *mb)
00226 {
00227   // Decrement the refcount on the Message_Block we hold, it does not
00228   // matter if we own the data or not, because we always own the
00229   // message block (i.e. it is always cloned or duplicated).
00230   ACE_Message_Block::release (this->cdr_);
00231   this->cdr_ = 0;
00232 
00233   this->free_value ();
00234 
00235   this->type_ = CORBA::TypeCode::_duplicate (tc);
00236 
00237   this->byte_order_ = byte_order;
00238 
00239   ACE_NEW (this->cdr_,
00240            ACE_Message_Block);
00241 
00242   ACE_CDR::consolidate (this->cdr_,
00243                         mb);
00244   // We can save the decode operation if there's no need to extract
00245   // the object.
00246 }
00247 
00248 void
00249 CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
00250                          int byte_order,
00251                          const ACE_Message_Block *mb,
00252                          CORBA::Boolean any_owns_data,
00253                          void* value,
00254                          CORBA::Any::_tao_destructor destructor)
00255 {
00256   // Decrement the refcount on the Message_Block we hold, it does not
00257   // matter if we own the data or not, because we always own the
00258   // message block (i.e. it is always cloned or duplicated).
00259   ACE_Message_Block::release (this->cdr_);
00260   this->cdr_ = 0;
00261 
00262   this->free_value ();
00263 
00264   this->any_owns_data_ = any_owns_data;
00265   this->value_ = value;
00266 
00267   this->type_ = CORBA::TypeCode::_duplicate (tc);
00268 
00269   this->byte_order_ = byte_order;
00270   ACE_NEW (this->cdr_, ACE_Message_Block);
00271   ACE_CDR::consolidate (this->cdr_, mb);
00272   // We can save the decode operation if there's no need to extract
00273   // the object.
00274 
00275   this->destructor_ = destructor;
00276 }
00277 
00278 void
00279 CORBA_Any::_tao_replace (CORBA::TypeCode_ptr tc,
00280                          CORBA::Boolean any_owns_data,
00281                          void* value,
00282                          CORBA::Any::_tao_destructor destructor)
00283 {
00284   this->free_value ();
00285 
00286   this->any_owns_data_ = any_owns_data;
00287   this->value_ = value;
00288 
00289   this->type_ = CORBA::TypeCode::_duplicate (tc);
00290 
00291   this->destructor_ = destructor;
00292 }
00293 
00294 // Free internal data.
00295 void
00296 CORBA_Any::free_value (void)
00297 {
00298   if (this->any_owns_data_
00299       && this->value_ != 0
00300       && this->destructor_ != 0)
00301     {
00302       (*this->destructor_) (this->value_);
00303     }
00304   this->any_owns_data_ = 0;
00305   this->value_ = 0;
00306   this->destructor_ = 0;
00307 }
00308 
00309 void
00310 CORBA_Any::_tao_encode (TAO_OutputCDR &cdr,
00311                         TAO_ORB_Core *orb_core
00312                         ACE_ENV_ARG_DECL)
00313 {
00314   // Always append the CDR stream, even when the value_.
00315   if (this->cdr_ == 0)
00316     ACE_THROW (CORBA::NO_IMPLEMENT ());
00317 
00318   TAO_InputCDR in (this->cdr_,
00319                    this->byte_order_,
00320                    TAO_DEF_GIOP_MAJOR,
00321                    TAO_DEF_GIOP_MINOR,
00322                    orb_core);
00323   TAO_Marshal_Object::perform_append (this->type_.in (),
00324                                       &in,
00325                                       &cdr
00326                                       ACE_ENV_ARG_PARAMETER);
00327 }
00328 
00329 void
00330 CORBA_Any::_tao_decode (TAO_InputCDR &cdr
00331                         ACE_ENV_ARG_DECL)
00332 {
00333   // Just read into the CDR stream...
00334 
00335   // @@ (JP) The following code depends on the fact that
00336   //         TAO_InputCDR does not contain chained message blocks,
00337   //         otherwise <begin> and <end> could be part of
00338   //         different buffers!
00339 
00340   // This will be the start of a new message block.
00341   char *begin = cdr.rd_ptr ();
00342 
00343   // Skip over the next aregument.
00344   CORBA::TypeCode::traverse_status status =
00345     TAO_Marshal_Object::perform_skip (this->type_.in (),
00346                                       &cdr
00347                                       ACE_ENV_ARG_PARAMETER);
00348   ACE_CHECK;
00349 
00350   if (status != CORBA::TypeCode::TRAVERSE_CONTINUE)
00351     {
00352       ACE_THROW (CORBA::MARSHAL ());
00353     }
00354 
00355   // This will be the end of the new message block.
00356   char *end = cdr.rd_ptr ();
00357 
00358   // The ACE_CDR::mb_align() call can shift the rd_ptr by up to
00359   // ACE_CDR::MAX_ALIGNMENT-1 bytes. Similarly, the offset adjustment
00360   // can move the rd_ptr by up to the same amount. We accommodate
00361   // this by including 2 * ACE_CDR::MAX_ALIGNMENT bytes of additional
00362   // space in the message block.
00363   size_t size = end - begin;
00364   ACE_Message_Block mb (size + 2 * ACE_CDR::MAX_ALIGNMENT);
00365   ACE_CDR::mb_align (&mb);
00366   ptr_arith_t offset = ptr_arith_t (begin) % ACE_CDR::MAX_ALIGNMENT;
00367   mb.rd_ptr (offset);
00368   mb.wr_ptr (offset + size);
00369 
00370   ACE_OS::memcpy (mb.rd_ptr (),
00371                   begin,
00372                   size);
00373 
00374   this->char_translator_ = cdr.char_translator();
00375   this->wchar_translator_ = cdr.wchar_translator();
00376 
00377   // Stick it into the Any. It gets duplicated there.
00378   this->_tao_replace (this->type_.in (),
00379                       cdr.byte_order (),
00380                       &mb);
00381 }
00382 
00383 // Insertion operators.
00384 
00385 void
00386 CORBA_Any::operator<<= (CORBA::Short s)
00387 {
00388   TAO_OutputCDR stream;
00389   stream << s;
00390   this->_tao_replace (CORBA::_tc_short,
00391                       TAO_ENCAP_BYTE_ORDER,
00392                       stream.begin ());
00393 }
00394 
00395 void
00396 CORBA_Any::operator<<= (CORBA::UShort s)
00397 {
00398   TAO_OutputCDR stream;
00399   stream << s;
00400   this->_tao_replace (CORBA::_tc_ushort,
00401                       TAO_ENCAP_BYTE_ORDER,
00402                       stream.begin ());
00403 }
00404 
00405 void
00406 CORBA_Any::operator<<= (CORBA::Long l)
00407 {
00408   TAO_OutputCDR stream;
00409   stream << l;
00410   this->_tao_replace (CORBA::_tc_long,
00411                       TAO_ENCAP_BYTE_ORDER,
00412                       stream.begin ());
00413 }
00414 
00415 void
00416 CORBA_Any::operator<<= (CORBA::ULong l)
00417 {
00418   TAO_OutputCDR stream;
00419   stream << l;
00420   this->_tao_replace (CORBA::_tc_ulong,
00421                       TAO_ENCAP_BYTE_ORDER,
00422                       stream.begin ());
00423 }
00424 
00425 void
00426 CORBA_Any::operator<<= (CORBA::LongLong l)
00427 {
00428   TAO_OutputCDR stream;
00429   stream << l;
00430   this->_tao_replace (CORBA::_tc_longlong,
00431                       TAO_ENCAP_BYTE_ORDER,
00432                       stream.begin ());
00433 }
00434 
00435 void
00436 CORBA_Any::operator<<= (CORBA::ULongLong l)
00437 {
00438   TAO_OutputCDR stream;
00439   stream << l;
00440   this->_tao_replace (CORBA::_tc_ulonglong,
00441                       TAO_ENCAP_BYTE_ORDER,
00442                       stream.begin ());
00443 }
00444 
00445 void
00446 CORBA_Any::operator<<= (CORBA::Float f)
00447 {
00448   TAO_OutputCDR stream;
00449   stream << f;
00450   this->_tao_replace (CORBA::_tc_float,
00451                       TAO_ENCAP_BYTE_ORDER,
00452                       stream.begin ());
00453 }
00454 
00455 void
00456 CORBA_Any::operator<<= (CORBA::Double d)
00457 {
00458   TAO_OutputCDR stream;
00459   stream << d;
00460   this->_tao_replace (CORBA::_tc_double,
00461                       TAO_ENCAP_BYTE_ORDER,
00462                       stream.begin ());
00463 }
00464 
00465 void
00466 CORBA_Any::operator<<= (CORBA::LongDouble d)
00467 {
00468   TAO_OutputCDR stream;
00469   stream << d;
00470   this->_tao_replace (CORBA::_tc_longdouble,
00471                       TAO_ENCAP_BYTE_ORDER,
00472                       stream.begin ());
00473 }
00474 
00475 // Insertion of Any - copying.
00476 void
00477 CORBA_Any::operator<<= (const CORBA_Any &a)
00478 {
00479   TAO_OutputCDR stream;
00480   stream << a;
00481   this->_tao_replace (CORBA::_tc_any,
00482                       TAO_ENCAP_BYTE_ORDER,
00483                       stream.begin ());
00484 }
00485 
00486 // Insertion of Any - non-copying.
00487 void
00488 CORBA::Any::_tao_any_destructor (void *x)
00489 {
00490   CORBA::Any *tmp = ACE_static_cast (CORBA::Any *, x);
00491   delete tmp;
00492 }
00493 
00494 void
00495 CORBA::Any::operator<<= (CORBA::Any *a)
00496 {
00497   TAO_OutputCDR stream;
00498   stream << *a;
00499   this->_tao_replace (CORBA::_tc_any,
00500                       TAO_ENCAP_BYTE_ORDER,
00501                       stream.begin (),
00502                       1,
00503                       a,
00504                       CORBA::Any::_tao_any_destructor);
00505 }
00506 
00507 // implementing the special types
00508 
00509 void
00510 CORBA_Any::operator<<= (from_boolean b)
00511 {
00512   TAO_OutputCDR stream;
00513   stream << b;
00514   this->_tao_replace (CORBA::_tc_boolean,
00515                       TAO_ENCAP_BYTE_ORDER,
00516                       stream.begin ());
00517 }
00518 
00519 void
00520 CORBA_Any::operator<<= (from_octet o)
00521 {
00522   TAO_OutputCDR stream;
00523   stream << o;
00524   this->_tao_replace (CORBA::_tc_octet,
00525                       TAO_ENCAP_BYTE_ORDER,
00526                       stream.begin ());
00527 }
00528 
00529 void
00530 CORBA_Any::operator<<= (from_char c)
00531 {
00532   TAO_OutputCDR stream;
00533   stream << c;
00534   this->_tao_replace (CORBA::_tc_char,
00535                       TAO_ENCAP_BYTE_ORDER,
00536                       stream.begin ());
00537 }
00538 
00539 void
00540 CORBA_Any::operator<<= (from_wchar wc)
00541 {
00542   TAO_OutputCDR stream;
00543   stream << wc;
00544   this->_tao_replace (CORBA::_tc_wchar,
00545                       TAO_ENCAP_BYTE_ORDER,
00546                       stream.begin ());
00547 }
00548 
00549 void
00550 CORBA_Any::operator<<= (CORBA::TypeCode_ptr tc)
00551 {
00552   TAO_OutputCDR stream;
00553   stream << tc;
00554   this->_tao_replace (CORBA::_tc_TypeCode,
00555                       TAO_ENCAP_BYTE_ORDER,
00556                       stream.begin ());
00557 }
00558 
00559 // Insertion of CORBA::Exception - copying.
00560 void
00561 CORBA_Any::operator<<= (const CORBA_Exception &exception)
00562 {
00563   ACE_DECLARE_NEW_CORBA_ENV;
00564 
00565   ACE_TRY
00566     {
00567       TAO_OutputCDR stream;
00568       exception._tao_encode (stream
00569                              ACE_ENV_ARG_PARAMETER);
00570       ACE_TRY_CHECK;
00571 
00572       this->_tao_replace (exception._type (),
00573                           TAO_ENCAP_BYTE_ORDER,
00574                           stream.begin ());
00575     }
00576   ACE_CATCHANY
00577     {
00578       if (TAO_debug_level > 0)
00579         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00580                              ACE_TEXT ("Exception in CORBA::Exception ")
00581                              ACE_TEXT ("insertion\n"));
00582     }
00583   ACE_ENDTRY;
00584   ACE_CHECK;
00585 }
00586 
00587 // Insertion of CORBA::Exception - non-copying.
00588 void
00589 CORBA_Any::operator<<= (CORBA_Exception *exception)
00590 {
00591   ACE_DECLARE_NEW_CORBA_ENV;
00592 
00593   ACE_TRY
00594     {
00595       TAO_OutputCDR stream;
00596       exception->_tao_encode (stream
00597                               ACE_ENV_ARG_PARAMETER);
00598       ACE_TRY_CHECK;
00599 
00600       this->_tao_replace (exception->_type (),
00601                           TAO_ENCAP_BYTE_ORDER,
00602                           stream.begin (),
00603                           1,
00604                           exception,
00605                           CORBA_Exception::_tao_any_destructor);
00606     }
00607   ACE_CATCHANY
00608     {
00609       if (TAO_debug_level > 0)
00610         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00611                              ACE_TEXT ("Exception in CORBA::Exception ")
00612                              ACE_TEXT ("insertion\n"));
00613     }
00614   ACE_ENDTRY;
00615   ACE_CHECK;
00616 }
00617 
00618 // Insertion of CORBA object - copying.
00619 void
00620 CORBA::Any::operator<<= (const CORBA::Object_ptr obj)
00621 {
00622   CORBA::Object_ptr objptr =
00623     CORBA::Object::_duplicate (obj);
00624 
00625   (*this) <<= &objptr;
00626 }
00627 
00628 // Insertion of CORBA object - non-copying.
00629 void
00630 CORBA::Any::operator<<= (CORBA::Object_ptr *objptr)
00631 {
00632   if (objptr == 0)
00633     {
00634       return; // @@ Should we raise an exception?
00635     }
00636 
00637   TAO_OutputCDR stream;
00638   stream << *objptr;
00639   this->_tao_replace (CORBA::_tc_Object,
00640                       TAO_ENCAP_BYTE_ORDER,
00641                       stream.begin ());
00642 }
00643 
00644 // Insertion of from_string.
00645 void
00646 CORBA_Any::operator<<= (from_string s)
00647 {
00648   TAO_OutputCDR stream;
00649   stream << s;
00650 
00651   char *tmp;
00652   // Non-copying.
00653   if (s.nocopy_)
00654     {
00655       tmp = s.val_;
00656     }
00657   else
00658     {
00659       tmp = CORBA::string_dup (s.val_);
00660     }
00661 
00662   if (s.bound_ > 0)
00663     {
00664       // If the inserted string is bounded, we create a typecode.
00665       static CORBA::Long _oc_string [] =
00666       {
00667         TAO_ENCAP_BYTE_ORDER,   // native endian + padding; "tricky"
00668         ACE_static_cast (CORBA::Long, s.bound_)
00669       };
00670 
00671       CORBA::TypeCode_ptr tc = 0;
00672 
00673       ACE_NEW (tc,
00674                CORBA::TypeCode (CORBA::tk_string,
00675                                 sizeof _oc_string,
00676                                 (char *) &_oc_string,
00677                                 1,
00678                                 sizeof (CORBA::String_var)));
00679 
00680       this->_tao_replace (tc,
00681                           TAO_ENCAP_BYTE_ORDER,
00682                           stream.begin (),
00683                           1,
00684                           tmp,
00685                           CORBA::Any::_tao_any_string_destructor);
00686 
00687       CORBA::release (tc);
00688     }
00689   else
00690     {
00691       // Unbounded.
00692       this->_tao_replace (CORBA::_tc_string,
00693                           TAO_ENCAP_BYTE_ORDER,
00694                           stream.begin (),
00695                           1,
00696                           tmp,
00697                           CORBA::Any::_tao_any_string_destructor);
00698     }
00699 }
00700 
00701 void
00702 CORBA_Any::operator<<= (from_wstring ws)
00703 {
00704   TAO_OutputCDR stream;
00705   stream << ws;
00706 
00707   CORBA::WChar *tmp;
00708   // Non-copying.
00709   if (ws.nocopy_)
00710     {
00711       tmp = ws.val_;
00712     }
00713   else
00714     {
00715       tmp = CORBA::wstring_dup (ws.val_);
00716     }
00717 
00718   if (ws.bound_ > 0)
00719     {
00720       // If the inserted string is bounded, we create a typecode.
00721       static CORBA::Long _oc_wstring [] =
00722       {
00723         TAO_ENCAP_BYTE_ORDER,   // native endian + padding; "tricky"
00724         ACE_static_cast (CORBA::Long, ws.bound_)
00725       };
00726 
00727       CORBA::TypeCode_ptr tc = 0;
00728       ACE_NEW (tc,
00729                CORBA::TypeCode (CORBA::tk_wstring,
00730                                 sizeof _oc_wstring,
00731                                 (char *) &_oc_wstring,
00732                                 1,
00733                                 sizeof (CORBA::WString_var)));
00734 
00735       this->_tao_replace (tc,
00736                           TAO_ENCAP_BYTE_ORDER,
00737                           stream.begin (),
00738                           1,
00739                           tmp,
00740                           CORBA::Any::_tao_any_wstring_destructor);
00741 
00742       CORBA::release (tc);
00743     }
00744   else
00745     {
00746       this->_tao_replace (CORBA::_tc_wstring,
00747                           TAO_ENCAP_BYTE_ORDER,
00748                           stream.begin (),
00749                           1,
00750                           tmp,
00751                           CORBA::Any::_tao_any_wstring_destructor);
00752     }
00753 }
00754 
00755 // Extraction: these are safe and hence we have to check that the
00756 // typecode of the Any is equal to the one we are trying to extract
00757 // into.
00758 
00759 CORBA::Boolean
00760 CORBA_Any::operator>>= (CORBA::Short &s) const
00761 {
00762   ACE_DECLARE_NEW_CORBA_ENV;
00763 
00764   ACE_TRY
00765     {
00766       CORBA::Boolean result =
00767         this->type_->equivalent (CORBA::_tc_short
00768                                  ACE_ENV_ARG_PARAMETER);
00769       ACE_TRY_CHECK;
00770 
00771       if (!result)
00772         return 0;
00773 
00774       TAO_InputCDR stream (this->cdr_,
00775                            this->byte_order_);
00776       return stream.read_short (s);
00777     }
00778   ACE_CATCHANY
00779     {
00780       if (TAO_debug_level > 0)
00781         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00782                              ACE_TEXT ("Exception in CORBA::Short ")
00783                              ACE_TEXT ("extraction\n"));
00784     }
00785   ACE_ENDTRY;
00786 
00787   return 0;
00788 }
00789 
00790 CORBA::Boolean
00791 CORBA_Any::operator>>= (CORBA::UShort &s) const
00792 {
00793   ACE_DECLARE_NEW_CORBA_ENV;
00794 
00795   ACE_TRY
00796     {
00797       CORBA::Boolean result =
00798         this->type_->equivalent (CORBA::_tc_ushort
00799                                  ACE_ENV_ARG_PARAMETER);
00800       ACE_TRY_CHECK;
00801 
00802       if (!result)
00803         {
00804           return 0;
00805         }
00806 
00807       TAO_InputCDR stream (this->cdr_,
00808                            this->byte_order_);
00809 
00810       return stream.read_ushort (s);
00811     }
00812   ACE_CATCHANY
00813     {
00814       if (TAO_debug_level > 0)
00815         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00816                              ACE_TEXT ("Exception in CORBA::UShort ")
00817                              ACE_TEXT ("extraction\n"));
00818     }
00819   ACE_ENDTRY;
00820 
00821   return 0;
00822 }
00823 
00824 CORBA::Boolean
00825 CORBA_Any::operator>>= (CORBA::Long &l) const
00826 {
00827   ACE_DECLARE_NEW_CORBA_ENV;
00828 
00829   ACE_TRY
00830     {
00831       CORBA::Boolean result =
00832         this->type_->equivalent (CORBA::_tc_long
00833                                  ACE_ENV_ARG_PARAMETER);
00834       ACE_TRY_CHECK;
00835 
00836       if (!result)
00837         {
00838           return 0;
00839         }
00840 
00841       TAO_InputCDR stream (this->cdr_,
00842                            this->byte_order_);
00843 
00844       return stream.read_long (l);
00845     }
00846   ACE_CATCHANY
00847     {
00848       if (TAO_debug_level > 0)
00849         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00850                              ACE_TEXT ("Exception in CORBA::Long ")
00851                              ACE_TEXT ("extraction\n"));
00852     }
00853   ACE_ENDTRY;
00854 
00855   return 0;
00856 }
00857 
00858 CORBA::Boolean
00859 CORBA_Any::operator>>= (CORBA::ULong &l) const
00860 {
00861   ACE_DECLARE_NEW_CORBA_ENV;
00862 
00863   ACE_TRY
00864     {
00865       CORBA::Boolean result =
00866         this->type_->equivalent (CORBA::_tc_ulong
00867                                  ACE_ENV_ARG_PARAMETER);
00868       ACE_TRY_CHECK;
00869 
00870       if (!result)
00871         {
00872           return 0;
00873         }
00874 
00875       TAO_InputCDR stream (this->cdr_,
00876                            this->byte_order_);
00877 
00878       return stream.read_ulong (l);
00879     }
00880   ACE_CATCHANY
00881     {
00882       if (TAO_debug_level > 0)
00883         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00884                              ACE_TEXT ("Exception in CORBA::ULong ")
00885                              ACE_TEXT ("extraction\n"));
00886     }
00887   ACE_ENDTRY;
00888 
00889   return 0;
00890 }
00891 
00892 CORBA::Boolean
00893 CORBA_Any::operator>>= (CORBA::LongLong &l) const
00894 {
00895   ACE_DECLARE_NEW_CORBA_ENV;
00896 
00897   ACE_TRY
00898     {
00899       CORBA::Boolean result =
00900         this->type_->equivalent (CORBA::_tc_longlong
00901                                  ACE_ENV_ARG_PARAMETER);
00902       ACE_TRY_CHECK;
00903 
00904       if (!result)
00905         {
00906           return 0;
00907         }
00908 
00909       TAO_InputCDR stream (this->cdr_,
00910                            this->byte_order_);
00911 
00912       return stream.read_longlong (l);
00913     }
00914   ACE_CATCHANY
00915     {
00916       if (TAO_debug_level > 0)
00917         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00918                              ACE_TEXT ("Exception in CORBA::LongLong ")
00919                              ACE_TEXT ("extraction\n"));
00920     }
00921   ACE_ENDTRY;
00922 
00923   return 0;
00924 }
00925 
00926 CORBA::Boolean
00927 CORBA_Any::operator>>= (CORBA::ULongLong &l) const
00928 {
00929   ACE_DECLARE_NEW_CORBA_ENV;
00930 
00931   ACE_TRY
00932     {
00933       CORBA::Boolean result =
00934         this->type_->equivalent (CORBA::_tc_ulonglong
00935                                  ACE_ENV_ARG_PARAMETER);
00936       ACE_TRY_CHECK;
00937 
00938       if (result)
00939         {
00940           if (this->any_owns_data_ && this->value_)
00941             {
00942               l = *(CORBA::ULongLong *) this->value_;
00943               return 1;
00944             }
00945           else
00946             {
00947               TAO_InputCDR stream (this->cdr_,
00948                                    this->byte_order_);
00949               return stream.read_ulonglong (l);
00950             }
00951         }
00952       else
00953         {
00954           return 0;
00955         }
00956     }
00957   ACE_CATCHANY
00958     {
00959       if (TAO_debug_level > 0)
00960         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00961                              ACE_TEXT ("Exception in CORBA::ULongLong ")
00962                              ACE_TEXT ("extraction\n"));
00963     }
00964   ACE_ENDTRY;
00965 
00966   return 0;
00967 }
00968 
00969 CORBA::Boolean
00970 CORBA_Any::operator>>= (CORBA::Float &f) const
00971 {
00972   ACE_DECLARE_NEW_CORBA_ENV;
00973 
00974   ACE_TRY
00975     {
00976       CORBA::Boolean result =
00977         this->type_->equivalent (CORBA::_tc_float
00978                                  ACE_ENV_ARG_PARAMETER);
00979       ACE_TRY_CHECK;
00980 
00981       if (!result)
00982         {
00983           return 0;
00984         }
00985 
00986       TAO_InputCDR stream (this->cdr_,
00987                            this->byte_order_);
00988 
00989       return stream.read_float (f);
00990     }
00991   ACE_CATCHANY
00992     {
00993       if (TAO_debug_level > 0)
00994         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00995                              ACE_TEXT ("Exception in CORBA::Float ")
00996                              ACE_TEXT ("extraction\n"));
00997     }
00998   ACE_ENDTRY;
00999 
01000   return 0;
01001 }
01002 
01003 CORBA::Boolean
01004 CORBA_Any::operator>>= (CORBA::Double &d) const
01005 {
01006   ACE_DECLARE_NEW_CORBA_ENV;
01007 
01008   ACE_TRY
01009     {
01010       CORBA::Boolean result =
01011         this->type_->equivalent (CORBA::_tc_double
01012                                  ACE_ENV_ARG_PARAMETER);
01013       ACE_TRY_CHECK;
01014 
01015       if (!result)
01016         {
01017           return 0;
01018         }
01019 
01020       TAO_InputCDR stream (this->cdr_,
01021                            this->byte_order_);
01022 
01023       return stream.read_double (d);
01024     }
01025   ACE_CATCHANY
01026     {
01027       if (TAO_debug_level > 0)
01028         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01029                              ACE_TEXT ("Exception in CORBA::Double ")
01030                              ACE_TEXT ("extraction\n"));
01031     }
01032   ACE_ENDTRY;
01033 
01034   return 0;
01035 }
01036 
01037 CORBA::Boolean
01038 CORBA_Any::operator>>= (CORBA::LongDouble &ld) const
01039 {
01040   ACE_DECLARE_NEW_CORBA_ENV;
01041 
01042   ACE_TRY
01043     {
01044       CORBA::Boolean result =
01045         this->type_->equivalent (CORBA::_tc_longdouble
01046                                  ACE_ENV_ARG_PARAMETER);
01047       ACE_TRY_CHECK;
01048 
01049       if (!result)
01050         {
01051           return 0;
01052         }
01053 
01054       TAO_InputCDR stream (this->cdr_,
01055                            this->byte_order_);
01056 
01057       return stream.read_longdouble (ld);
01058     }
01059   ACE_CATCHANY
01060     {
01061       if (TAO_debug_level > 0)
01062         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01063                              ACE_TEXT ("Exception in CORBA::LongDouble ")
01064                              ACE_TEXT ("extraction\n"));
01065     }
01066   ACE_ENDTRY;
01067 
01068   return 0;
01069 }
01070 
01071 CORBA::Boolean
01072 CORBA_Any::operator>>= (CORBA::Any &a) const
01073 {
01074   ACE_DECLARE_NEW_CORBA_ENV;
01075 
01076   ACE_TRY
01077     {
01078       CORBA::Boolean result =
01079         this->type_->equivalent (CORBA::_tc_any
01080                                  ACE_ENV_ARG_PARAMETER);
01081       ACE_TRY_CHECK;
01082 
01083       if (!result)
01084         {
01085           return 0;
01086         }
01087 
01088       TAO_InputCDR stream (this->cdr_,
01089                            this->byte_order_);
01090       if (stream >> a)
01091         {
01092           return 1;
01093         }
01094     }
01095   ACE_CATCHANY
01096     {
01097       if (TAO_debug_level > 0)
01098         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01099                              ACE_TEXT ("Exception in CORBA::Any ")
01100                              ACE_TEXT ("extraction\n"));
01101     }
01102   ACE_ENDTRY;
01103 
01104   return 0;
01105 }
01106 
01107 CORBA::Boolean
01108 CORBA_Any::operator>>= (const CORBA::Any *&a) const
01109 {
01110   ACE_DECLARE_NEW_CORBA_ENV;
01111 
01112   ACE_TRY
01113     {
01114       a = 0;
01115       CORBA::Boolean equivalent =
01116         this->type_->equivalent (CORBA::_tc_any
01117                                  ACE_ENV_ARG_PARAMETER);
01118       ACE_TRY_CHECK;
01119 
01120       if (!equivalent)
01121         {
01122           return 0;
01123         }
01124 
01125       if (this->any_owns_data_ && this->value_)
01126         {
01127           a = (CORBA::Any *) this->value_;
01128           return 1;
01129         }
01130       else
01131         {
01132           CORBA::Any *x;
01133           ACE_NEW_RETURN (x, CORBA::Any, 0);
01134           CORBA::Any_var tmp = x;
01135           TAO_InputCDR stream (this->cdr_,
01136                                this->byte_order_);
01137 
01138           if (!(stream >> tmp.inout ()))
01139             {
01140               return 0;
01141             }
01142 
01143           ACE_const_cast(
01144             CORBA::Any*,
01145             this)->_tao_replace (CORBA::_tc_any,
01146                                  1,
01147                                  ACE_static_cast (CORBA::Any *, tmp),
01148                                  CORBA::Any::_tao_any_destructor);
01149 
01150           ACE_const_cast (CORBA::Any *&, a) = tmp._retn ();
01151           return 1;
01152         }
01153     }
01154   ACE_CATCHANY
01155     {
01156       if (TAO_debug_level > 0)
01157         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01158                              ACE_TEXT ("Exception in CORBA::Any ")
01159                              ACE_TEXT ("extraction\n"));
01160     }
01161   ACE_ENDTRY;
01162 
01163   a = 0;
01164   return 0;
01165 }
01166 
01167 CORBA::Boolean
01168 CORBA_Any::operator>>= (const char *&s) const
01169 {
01170   ACE_DECLARE_NEW_CORBA_ENV;
01171 
01172   ACE_TRY
01173     {
01174       s = 0;
01175 
01176       CORBA::Boolean result =
01177         this->type_->equivalent (CORBA::_tc_string
01178                                  ACE_ENV_ARG_PARAMETER);
01179       ACE_TRY_CHECK;
01180 
01181       if (!result)
01182         {
01183           return 0;
01184         }
01185 
01186       if (this->any_owns_data_ && this->value_)
01187         {
01188           s = ACE_static_cast (char *, this->value_);
01189           return 1;
01190         }
01191 
01192 
01193       TAO_InputCDR stream (this->cdr_,
01194                            this->byte_order_);
01195 
01196       stream.char_translator(this->char_translator_);
01197 
01198       CORBA::String_var tmp;
01199 
01200       if (!stream.read_string (tmp.out ()))
01201         {
01202           return 0;
01203         }
01204 
01205       ACE_const_cast(CORBA::Any*,
01206                      this)->_tao_replace (CORBA::_tc_string,
01207                                           1,
01208                                           tmp.inout (),
01209                                           CORBA::Any::_tao_any_string_destructor);
01210 
01211       s = tmp._retn ();
01212       return 1;
01213     }
01214   ACE_CATCHANY
01215     {
01216     }
01217   ACE_ENDTRY;
01218 
01219   s = 0;
01220   return 0;
01221 }
01222 
01223 void
01224 CORBA_Any::_tao_any_string_destructor (void *x)
01225 {
01226   char *tmp = ACE_static_cast (char *, x);
01227   CORBA::string_free (tmp);
01228 }
01229 
01230 void
01231 CORBA::Any::_tao_any_wstring_destructor (void *x)
01232 {
01233   CORBA::WChar *tmp = ACE_static_cast (CORBA::WChar *, x);
01234   CORBA::wstring_free (tmp);
01235 }
01236 
01237 CORBA::Boolean
01238 CORBA_Any::operator>>= (const CORBA::WChar *&s) const
01239 {
01240   ACE_DECLARE_NEW_CORBA_ENV;
01241 
01242   ACE_TRY
01243     {
01244       s = 0;
01245 
01246       CORBA::Boolean result =
01247         this->type_->equivalent (CORBA::_tc_wstring
01248                                  ACE_ENV_ARG_PARAMETER);
01249       ACE_TRY_CHECK;
01250 
01251       if (!result)
01252         {
01253           return 0;
01254         }
01255 
01256       if (this->any_owns_data_ && this->value_)
01257         {
01258           s = ACE_static_cast (CORBA::WChar *, this->value_);
01259           return 1;
01260         }
01261 
01262       TAO_InputCDR stream (this->cdr_,
01263                            this->byte_order_);
01264 
01265       stream.wchar_translator(this->wchar_translator_);
01266 
01267       CORBA::WString_var tmp;
01268 
01269       if (!stream.read_wstring (tmp.out ()))
01270         {
01271           return 0;
01272         }
01273 
01274       ACE_const_cast(CORBA::Any*,
01275                      this)->_tao_replace (CORBA::_tc_wstring,
01276                                           1,
01277                                           tmp.inout (),
01278                                           CORBA::Any::_tao_any_wstring_destructor);
01279 
01280       s = tmp._retn ();
01281       return 1;
01282     }
01283   ACE_CATCHANY
01284     {
01285       if (TAO_debug_level > 0)
01286         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01287                              ACE_TEXT ("Exception in unbounded wstring ")
01288                              ACE_TEXT ("extraction\n"));
01289     }
01290   ACE_ENDTRY;
01291 
01292   return 0;
01293 }
01294 
01295 void
01296 CORBA::Any::_tao_any_tc_destructor (void *x)
01297 {
01298   CORBA::TypeCode_ptr tmp = ACE_static_cast (CORBA::TypeCode_ptr, x);
01299   CORBA::release (tmp);
01300 }
01301 
01302 CORBA::Boolean
01303 CORBA_Any::operator>>= (CORBA::TypeCode_ptr &tc) const
01304 {
01305   ACE_DECLARE_NEW_CORBA_ENV;
01306 
01307   ACE_TRY
01308     {
01309       CORBA::Boolean result =
01310         this->type_->equivalent (CORBA::_tc_TypeCode
01311                                  ACE_ENV_ARG_PARAMETER);
01312       ACE_TRY_CHECK;
01313 
01314       if (!result)
01315         {
01316           return 0;
01317         }
01318 
01319       if (this->any_owns_data_ && this->value_)
01320         {
01321           tc = ACE_static_cast (CORBA::TypeCode_ptr, this->value_);
01322           return 1;
01323         }
01324 
01325       TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
01326                            this->byte_order_);
01327       CORBA::TypeCode_var tmp;
01328 
01329       if (!(stream >> tmp.inout ()))
01330         {
01331           return 0;
01332         }
01333 
01334       ACE_const_cast(CORBA::Any*,
01335                      this)->_tao_replace (CORBA::_tc_TypeCode,
01336                                           1,
01337                                           tmp.in (),
01338                                           CORBA::Any::_tao_any_tc_destructor);
01339 
01340       tc = tmp._retn ();
01341       return 1;
01342     }
01343   ACE_CATCHANY
01344     {
01345       if (TAO_debug_level > 0)
01346         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01347                              ACE_TEXT ("Exception in CORBA::TypeCode_ptr ")
01348                              ACE_TEXT ("extraction\n"));
01349     }
01350   ACE_ENDTRY;
01351 
01352   return 0;
01353 }
01354 
01355 // = extraction into the special types
01356 
01357 CORBA::Boolean
01358 CORBA_Any::operator>>= (to_boolean b) const
01359 {
01360   ACE_DECLARE_NEW_CORBA_ENV;
01361 
01362   ACE_TRY
01363     {
01364       CORBA::Boolean result =
01365         this->type_->equivalent (CORBA::_tc_boolean
01366                                  ACE_ENV_ARG_PARAMETER);
01367       ACE_TRY_CHECK;
01368 
01369       if (!result)
01370         {
01371           return 0;
01372         }
01373 
01374       TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
01375                            this->byte_order_);
01376 
01377       return stream.read_boolean (b.ref_);
01378     }
01379   ACE_CATCHANY
01380     {
01381       if (TAO_debug_level > 0)
01382         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01383                              ACE_TEXT ("Exception in CORBA::Boolean ")
01384                              ACE_TEXT ("extraction\n"));
01385     }
01386   ACE_ENDTRY;
01387 
01388   return 0;
01389 }
01390 
01391 CORBA::Boolean
01392 CORBA_Any::operator>>= (to_octet o) const
01393 {
01394   ACE_DECLARE_NEW_CORBA_ENV;
01395 
01396   ACE_TRY
01397     {
01398       CORBA::Boolean result =
01399         this->type_->equivalent (CORBA::_tc_octet
01400                                  ACE_ENV_ARG_PARAMETER);
01401       ACE_TRY_CHECK;
01402 
01403       if (!result)
01404         {
01405           return 0;
01406         }
01407 
01408       TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
01409                            this->byte_order_);
01410 
01411       return stream.read_octet (o.ref_);
01412     }
01413   ACE_CATCHANY
01414     {
01415       if (TAO_debug_level > 0)
01416         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01417                              ACE_TEXT ("Exception in CORBA::Octet ")
01418                              ACE_TEXT ("extraction\n"));
01419     }
01420   ACE_ENDTRY;
01421 
01422   return 0;
01423 }
01424 
01425 CORBA::Boolean
01426 CORBA_Any::operator>>= (to_char c) const
01427 {
01428   ACE_DECLARE_NEW_CORBA_ENV;
01429 
01430   ACE_TRY
01431     {
01432       CORBA::Boolean result =
01433         this->type_->equivalent (CORBA::_tc_char
01434                                  ACE_ENV_ARG_PARAMETER);
01435       ACE_TRY_CHECK;
01436 
01437       if (!result)
01438         {
01439           return 0;
01440         }
01441 
01442       TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
01443                            this->byte_order_);
01444       stream.char_translator(this->char_translator_);
01445 
01446       return stream.read_char (c.ref_);
01447     }
01448   ACE_CATCHANY
01449     {
01450       if (TAO_debug_level > 0)
01451         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01452                              ACE_TEXT ("Exception in CORBA::Char ")
01453                              ACE_TEXT ("extraction\n"));
01454     }
01455   ACE_ENDTRY;
01456 
01457   return 0;
01458 }
01459 
01460 CORBA::Boolean
01461 CORBA_Any::operator>>= (to_wchar wc) const
01462 {
01463   ACE_DECLARE_NEW_CORBA_ENV;
01464 
01465   ACE_TRY
01466     {
01467       CORBA::Boolean result =
01468         this->type_->equivalent (CORBA::_tc_wchar
01469                                  ACE_ENV_ARG_PARAMETER);
01470       ACE_TRY_CHECK;
01471 
01472       if (!result)
01473         {
01474           return 0;
01475         }
01476 
01477       TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
01478                            this->byte_order_);
01479       stream.wchar_translator(this->wchar_translator_);
01480 
01481       return stream.read_wchar (wc.ref_);
01482     }
01483   ACE_CATCHANY
01484     {
01485       if (TAO_debug_level > 0)
01486         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01487                              ACE_TEXT ("Exception in CORBA::WChar ")
01488                              ACE_TEXT ("extraction\n"));
01489     }
01490   ACE_ENDTRY;
01491 
01492   return 0;
01493 }
01494 
01495 CORBA::Boolean
01496 CORBA_Any::operator>>= (to_string s) const
01497 {
01498   ACE_DECLARE_NEW_CORBA_ENV;
01499 
01500   ACE_TRY
01501     {
01502       CORBA::ULong kind =
01503         this->type_->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01504       ACE_TRY_CHECK;
01505 
01506       CORBA::TypeCode_var tcvar =
01507         CORBA::TypeCode::_duplicate (this->type_.in ());
01508 
01509       while (kind == CORBA::tk_alias)
01510         {
01511           tcvar = tcvar->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
01512           ACE_TRY_CHECK;
01513 
01514           kind = tcvar->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01515           ACE_TRY_CHECK;
01516         }
01517 
01518       if (kind != CORBA::tk_string)
01519         {
01520           return 0;
01521         }
01522 
01523       CORBA::ULong bound = tcvar->length (ACE_ENV_SINGLE_ARG_PARAMETER);
01524       ACE_TRY_CHECK;
01525 
01526       if (s.bound_ != bound)
01527         {
01528           return 0;
01529         }
01530 
01531       if (this->any_owns_data_ && this->value_)
01532         {
01533           s.val_ = ACE_static_cast (char *, this->value_);
01534           return 1;
01535         }
01536 
01537       TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
01538                            this->byte_order_);
01539       stream.char_translator(this->char_translator_);
01540 
01541       CORBA::String_var tmp;
01542 
01543       if (!stream.read_string (tmp.out ()))
01544         {
01545           return 0;
01546         }
01547 
01548       CORBA::Any *non_const_this = ACE_const_cast (CORBA::Any*,
01549                                                    this);
01550       non_const_this->_tao_replace (CORBA::_tc_string,
01551                                     1,
01552                                     tmp.inout (),
01553                                     CORBA::Any::_tao_any_string_destructor);
01554 
01555       s.val_ = tmp._retn ();
01556       return 1;
01557     }
01558   ACE_CATCHANY
01559     {
01560       if (TAO_debug_level > 0)
01561         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01562                              ACE_TEXT ("Exception in bounded string ")
01563                              ACE_TEXT ("extraction\n"));
01564     }
01565   ACE_ENDTRY;
01566 
01567   return 0;
01568 }
01569 
01570 CORBA::Boolean
01571 CORBA_Any::operator>>= (to_wstring ws) const
01572 {
01573   ACE_DECLARE_NEW_CORBA_ENV;
01574 
01575   ACE_TRY
01576     {
01577       CORBA::ULong kind =
01578         this->type_->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01579       ACE_TRY_CHECK;
01580 
01581       CORBA::TypeCode_var tcvar =
01582         CORBA::TypeCode::_duplicate (this->type_.in ());
01583 
01584       while (kind == CORBA::tk_alias)
01585         {
01586           tcvar = tcvar->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
01587           ACE_TRY_CHECK;
01588 
01589           kind = tcvar->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01590           ACE_TRY_CHECK;
01591         }
01592 
01593       if (kind != CORBA::tk_wstring)
01594         {
01595           return 0;
01596         }
01597 
01598       CORBA::ULong bound = tcvar->length (ACE_ENV_SINGLE_ARG_PARAMETER);
01599       ACE_TRY_CHECK;
01600 
01601       if (ws.bound_ != bound)
01602         {
01603           return 0;
01604         }
01605 
01606       if (this->any_owns_data_ && this->value_)
01607         {
01608           ws.val_ = ACE_static_cast (CORBA::WChar *, this->value_);
01609           return 1;
01610         }
01611 
01612       TAO_InputCDR stream ((ACE_Message_Block *) this->cdr_,
01613                            this->byte_order_);
01614 
01615       stream.char_translator(this->char_translator_);
01616 
01617       CORBA::WString_var tmp;
01618 
01619       if (!stream.read_wstring (tmp.out ()))
01620         {
01621           return 0;
01622         }
01623 
01624       CORBA::Any *non_const_this = ACE_const_cast (CORBA::Any*,
01625                                                    this);
01626       non_const_this->_tao_replace (CORBA::_tc_wstring,
01627                                     1,
01628                                     ACE_static_cast (CORBA::WChar *, tmp),
01629                                     CORBA::Any::_tao_any_wstring_destructor);
01630 
01631       ws.val_ = tmp._retn ();
01632       return 1;
01633     }
01634   ACE_CATCHANY
01635     {
01636       if (TAO_debug_level > 0)
01637         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01638                              ACE_TEXT ("Exception in bounded wstring ")
01639                              ACE_TEXT ("extraction\n"));
01640     }
01641   ACE_ENDTRY;
01642 
01643   return 0;
01644 }
01645 
01646 CORBA::Boolean
01647 CORBA_Any::operator>>= (to_object obj) const
01648 {
01649   ACE_DECLARE_NEW_CORBA_ENV;
01650 
01651   ACE_TRY
01652     {
01653       CORBA::ULong kind =
01654         this->type_->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01655       ACE_TRY_CHECK;
01656 
01657       CORBA::TypeCode_var tcvar =
01658         CORBA::TypeCode::_duplicate (this->type_.in ());
01659 
01660       while (kind == CORBA::tk_alias)
01661         {
01662           tcvar = tcvar->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
01663           ACE_TRY_CHECK;
01664 
01665           kind = tcvar->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01666           ACE_TRY_CHECK;
01667         }
01668 
01669       if (kind != CORBA::tk_objref)
01670         {
01671           return 0;
01672         }
01673 
01674       // It is hard to apply this optimization, because value_ points
01675       // to a derived class from CORBA::Object, and with multiple
01676       // virtual inheritance.  One posibility is to use a helper
01677       // function to upcast from void* to CORBA::Object_ptr, but this
01678       // is only useful to implement the >>=(to_object) operator,
01679       // which is very rarely used.
01680       // It is better to just demarshal the object everytime,
01681       // specially because the caller owns the returned object.
01682       //
01683       // if (this->any_owns_data_ && this->value_)
01684       //  {
01685       //    // CORBA 2.3 has changed the behavior of this operator. Caller
01686       //    // is now responsible for release.
01687       //    obj.ref_ =
01688       //      CORBA::Object::_duplicate (
01689       //          (*this->upcast_) (this->value_)
01690       //        );
01691       //    return 1;
01692       //  }
01693 
01694       // @@ This uses ORB_Core instance because we need one to
01695       // demarshal objects (to create the right profiles for that
01696       // object), but the Any does not belong to any ORB.
01697       TAO_InputCDR stream (this->cdr_,
01698                            this->byte_order_,
01699                            TAO_DEF_GIOP_MAJOR,
01700                            TAO_DEF_GIOP_MINOR,
01701                            TAO_ORB_Core_instance ());
01702 
01703       if (stream >> obj.ref_)
01704         {
01705           return 1;
01706         }
01707     }
01708   ACE_CATCHANY
01709     {
01710       if (TAO_debug_level > 0)
01711         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01712                              ACE_TEXT ("Exception in CORBA::Object_ptr ")
01713                              ACE_TEXT ("extraction\n"));
01714     }
01715   ACE_ENDTRY;
01716 
01717   return 0;
01718 }
01719 
01720 CORBA::Boolean
01721 CORBA_Any::operator>>= (to_abstract_base obj) const
01722 {
01723   ACE_DECLARE_NEW_CORBA_ENV;
01724 
01725   ACE_TRY
01726     {
01727       CORBA::ULong kind =
01728         this->type_->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01729       ACE_TRY_CHECK;
01730 
01731       CORBA::TypeCode_var tcvar =
01732         CORBA::TypeCode::_duplicate (this->type_.in ());
01733 
01734       while (kind == CORBA::tk_alias)
01735         {
01736           tcvar = tcvar->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
01737           ACE_TRY_CHECK;
01738 
01739           kind = tcvar->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01740           ACE_TRY_CHECK;
01741         }
01742 
01743       if (kind != CORBA::tk_abstract_interface)
01744         {
01745           return 0;
01746         }
01747 
01748       // @@ This uses ORB_Core instance because we need one to
01749       // demarshal objects (to create the right profiles for that
01750       // object), but the Any does not belong to any ORB.
01751       TAO_InputCDR stream (this->cdr_,
01752                            this->byte_order_,
01753                            TAO_DEF_GIOP_MAJOR,
01754                            TAO_DEF_GIOP_MINOR,
01755                            TAO_ORB_Core_instance ());
01756 
01757       if (stream >> obj.ref_)
01758         {
01759           return 1;
01760         }
01761     }
01762   ACE_CATCHANY
01763     {
01764       if (TAO_debug_level > 0)
01765         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01766                              ACE_TEXT ("Exception in CORBA::AbstractBase ")
01767                              ACE_TEXT ("extraction\n"));
01768     }
01769   ACE_ENDTRY;
01770 
01771   return 0;
01772 }
01773 
01774 CORBA::Boolean
01775 CORBA_Any::operator>>= (to_value obj) const
01776 {
01777   ACE_DECLARE_NEW_CORBA_ENV;
01778 
01779   ACE_TRY
01780     {
01781       CORBA::ULong kind =
01782         this->type_->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01783       ACE_TRY_CHECK;
01784 
01785       CORBA::TypeCode_var tcvar =
01786         CORBA::TypeCode::_duplicate (this->type_.in ());
01787 
01788       while (kind == CORBA::tk_alias)
01789         {
01790           tcvar = tcvar->content_type (ACE_ENV_SINGLE_ARG_PARAMETER);
01791           ACE_TRY_CHECK;
01792 
01793           kind = tcvar->kind (ACE_ENV_SINGLE_ARG_PARAMETER);
01794           ACE_TRY_CHECK;
01795         }
01796 
01797       if (kind != CORBA::tk_value)
01798         {
01799           return 0;
01800         }
01801 
01802       TAO_InputCDR stream (this->cdr_,
01803                            this->byte_order_);
01804 
01805       if (stream >> obj.ref_)
01806         {
01807           return 1;
01808         }
01809     }
01810   ACE_CATCHANY
01811     {
01812       if (TAO_debug_level > 0)
01813         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
01814                              ACE_TEXT ("Exception in CORBA::ValueBase ")
01815                              ACE_TEXT ("extraction\n"));
01816     }
01817   ACE_ENDTRY;
01818 
01819   return 0;
01820 }
01821 
01822 // this is a copying version for unbounded strings Not inline, to
01823 // avoid use in Any.i before definition in ORB.i.
01824 
01825 void
01826 CORBA_Any::operator<<= (const char* s)
01827 {
01828   TAO_OutputCDR stream;
01829   stream << s;
01830   this->_tao_replace (CORBA::_tc_string,
01831                       TAO_ENCAP_BYTE_ORDER,
01832                       stream.begin ());
01833 }
01834 
01835 // And the version for unbounded wide string.
01836 void
01837 CORBA_Any::operator<<= (const CORBA::WChar* s)
01838 {
01839   TAO_OutputCDR stream;
01840   stream << s;
01841   this->_tao_replace (CORBA::_tc_wstring,
01842                       TAO_ENCAP_BYTE_ORDER,
01843                       stream.begin ());
01844 }
01845 
01846 CORBA::Boolean
01847 operator<< (TAO_OutputCDR& cdr,
01848             const CORBA::Any &x)
01849 {
01850   // If a locality-constrained interface is contained at
01851   // any level, the Any cannot be marshaled.
01852   if (x.contains_local ())
01853     {
01854       return 0;
01855     }
01856 
01857   CORBA::TypeCode_var tc = x.type ();
01858 
01859   if (!(cdr << tc.in ()))
01860     {
01861       return 0;
01862     }
01863 
01864   ACE_TRY_NEW_ENV
01865     {
01866       TAO_InputCDR input (x._tao_get_cdr (),
01867                           x._tao_byte_order ());
01868 
01869       CORBA::TypeCode::traverse_status status =
01870         TAO_Marshal_Object::perform_append (tc.in (),
01871                                             &input,
01872                                             &cdr
01873                                             ACE_ENV_ARG_PARAMETER);
01874       ACE_TRY_CHECK;
01875 
01876       if (status != CORBA::TypeCode::TRAVERSE_CONTINUE)
01877         {
01878           return 0;
01879         }
01880     }
01881   ACE_CATCH (CORBA_Exception, ex)
01882     {
01883       return 0;
01884     }
01885   ACE_ENDTRY;
01886 
01887   return 1;
01888 }
01889 
01890 CORBA::Boolean
01891 operator>> (TAO_InputCDR &cdr, CORBA::Any &x)
01892 {
01893   CORBA::TypeCode_var tc;
01894 
01895   if (!(cdr >> tc.out ()))
01896     {
01897       return 0;
01898     }
01899 
01900   ACE_TRY_NEW_ENV
01901     {
01902       // @@ (JP) The following code depends on the fact that
01903       //         TAO_InputCDR does not contain chained message blocks,
01904       //         otherwise <begin> and <end> could be part of
01905       //         different buffers!
01906 
01907       // This will be the start of a new message block.
01908       char *begin = cdr.rd_ptr ();
01909 
01910       // Skip over the next aregument.
01911       CORBA::TypeCode::traverse_status status =
01912         TAO_Marshal_Object::perform_skip (tc.in (),
01913                                           &cdr
01914                                           ACE_ENV_ARG_PARAMETER);
01915       ACE_TRY_CHECK;
01916 
01917       if (status != CORBA::TypeCode::TRAVERSE_CONTINUE)
01918         {
01919           return 0;
01920         }
01921 
01922       // This will be the end of the new message block.
01923       char *end = cdr.rd_ptr ();
01924 
01925       // The ACE_CDR::mb_align() call can shift the rd_ptr by up to
01926       // ACE_CDR::MAX_ALIGNMENT-1 bytes. Similarly, the offset adjustment
01927       // can move the rd_ptr by up to the same amount. We accommodate
01928       // this by including 2 * ACE_CDR::MAX_ALIGNMENT bytes of additional
01929       // space in the message block.
01930       size_t size = end - begin;
01931       ACE_Message_Block mb (size + 2 * ACE_CDR::MAX_ALIGNMENT);
01932       ACE_CDR::mb_align (&mb);
01933       ptr_arith_t offset = ptr_arith_t (begin) % ACE_CDR::MAX_ALIGNMENT;
01934       mb.rd_ptr (offset);
01935       mb.wr_ptr (offset + size);
01936       ACE_OS::memcpy (mb.rd_ptr (), begin, size);
01937 
01938       x.char_translator_ = cdr.char_translator();
01939       x.wchar_translator_ = cdr.wchar_translator();
01940 
01941       // Stick it into the Any. It gets duplicated there.
01942       x._tao_replace (tc.in (),
01943                       cdr.byte_order (),
01944                       &mb);
01945     }
01946   ACE_CATCH (CORBA_Exception, ex)
01947     {
01948       return 0;
01949     }
01950   ACE_ENDTRY;
01951 
01952   return 1;
01953 }
01954 
01955 // ****************************************************************
01956 
01957 CORBA_Any_var::CORBA_Any_var (const CORBA_Any_var& r)
01958   : ptr_ (0)
01959 {
01960   if (r.ptr_ != 0)
01961     {
01962       ACE_NEW (this->ptr_,
01963                CORBA::Any (*r.ptr_));
01964     }
01965 }
01966 
01967 CORBA::Any_var &
01968 CORBA_Any_var::operator= (CORBA::Any *p)
01969 {
01970   if (this->ptr_ != p)
01971     {
01972       delete this->ptr_;
01973 
01974       this->ptr_ = p;
01975     }
01976 
01977   return *this;
01978 }
01979 
01980 CORBA::Any_var &
01981 CORBA_Any_var::operator= (const CORBA::Any_var& r)
01982 {
01983   delete this->ptr_;
01984   this->ptr_ = 0;
01985 
01986   if (r.ptr_ != 0)
01987     {
01988       ACE_NEW_RETURN (this->ptr_,
01989                       CORBA::Any (*r.ptr_),
01990                       *this);
01991     }
01992 
01993   return *this;
01994 }

Generated on Mon Jun 16 13:47:58 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002