00001
00002
00003 #include "tao/AnyTypeCode/Any.h"
00004 #include "tao/AnyTypeCode/Any_Basic_Impl.h"
00005 #include "tao/AnyTypeCode/Any_Impl_T.h"
00006 #include "tao/AnyTypeCode/Any_Special_Impl_T.h"
00007 #include "tao/AnyTypeCode/Any_Dual_Impl_T.h"
00008 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
00009 #include "tao/AnyTypeCode/TypeCode.h"
00010 #include "tao/AnyTypeCode/TypeCode_Constants.h"
00011 #include "tao/CDR.h"
00012 #include "tao/SystemException.h"
00013
00014 #include "ace/Log_Msg.h"
00015 #include "ace/OS_NS_string.h"
00016 #include "ace/OS_NS_wchar.h"
00017 #include "ace/OS_Memory.h"
00018
00019 #if !defined (__ACE_INLINE__)
00020 # include "tao/AnyTypeCode/Any.inl"
00021 #endif
00022
00023 ACE_RCSID (AnyTypeCode,
00024 Any,
00025 "$Id: Any.cpp 78809 2007-07-06 10:24:12Z parsons $")
00026
00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00028
00029 using namespace TAO;
00030
00031 CORBA::Any::Any (void)
00032 : impl_ (0)
00033 {
00034 }
00035
00036 CORBA::Any::Any (const CORBA::Any &rhs)
00037 : impl_ (rhs.impl_)
00038 {
00039 if (this->impl_ != 0)
00040 {
00041 this->impl_->_add_ref ();
00042 }
00043 }
00044
00045 CORBA::Any::~Any (void)
00046 {
00047 if (this->impl_ != 0)
00048 {
00049 this->impl_->_remove_ref ();
00050 }
00051 }
00052
00053 CORBA::Any &
00054 CORBA::Any::operator= (const CORBA::Any &rhs)
00055 {
00056 if (this->impl_ != rhs.impl_)
00057 {
00058 if (this->impl_ != 0)
00059 {
00060 this->impl_->_remove_ref ();
00061 }
00062
00063 this->impl_ = rhs.impl_;
00064
00065 if (this->impl_ != 0)
00066 {
00067 this->impl_->_add_ref ();
00068 }
00069 }
00070
00071 return *this;
00072 }
00073
00074 void
00075 CORBA::Any::replace (TAO::Any_Impl *new_impl)
00076 {
00077 ACE_ASSERT (new_impl != 0);
00078
00079 if (this->impl_ != 0)
00080 {
00081 this->impl_->_remove_ref ();
00082 }
00083
00084 this->impl_ = new_impl;
00085 }
00086
00087 CORBA::TypeCode_ptr
00088 CORBA::Any::type (void) const
00089 {
00090 if (this->impl_ != 0)
00091 {
00092 return this->impl_->type ();
00093 }
00094
00095 return CORBA::TypeCode::_duplicate (CORBA::_tc_null);
00096 }
00097
00098 CORBA::TypeCode_ptr
00099 CORBA::Any::_tao_get_typecode (void) const
00100 {
00101 if (this->impl_ != 0)
00102 {
00103 return this->impl_->_tao_get_typecode ();
00104 }
00105
00106 return CORBA::_tc_null;
00107 }
00108
00109 void
00110 CORBA::Any::_tao_set_typecode (const CORBA::TypeCode_ptr tc)
00111 {
00112 if (this->impl_ == 0)
00113 {
00114 ACE_NEW (this->impl_,
00115 TAO::Unknown_IDL_Type (tc));
00116 }
00117 else
00118 {
00119 this->impl_->type (tc);
00120 }
00121 }
00122
00123 int
00124 CORBA::Any::_tao_byte_order (void) const
00125 {
00126 if (this->impl_ != 0)
00127 {
00128 return this->impl_->_tao_byte_order ();
00129 }
00130
00131 return TAO_ENCAP_BYTE_ORDER;
00132 }
00133
00134 void
00135 CORBA::Any::type (CORBA::TypeCode_ptr tc
00136 )
00137 {
00138 CORBA::Boolean equiv = false;
00139
00140 if (this->impl_ != 0)
00141 {
00142 equiv = this->impl_->_tao_get_typecode ()->equivalent (tc);
00143 }
00144
00145 if (equiv)
00146 {
00147 this->impl_->type (tc);
00148 }
00149 else
00150 {
00151 throw ::CORBA::BAD_TYPECODE ();
00152 }
00153 }
00154
00155 void
00156 CORBA::Any::_tao_any_destructor (void *x)
00157 {
00158 CORBA::Any *tmp = static_cast<CORBA::Any *> (x);
00159 delete tmp;
00160 }
00161
00162 CORBA::Any::to_object::to_object (CORBA::Object_out obj)
00163 : ref_ (obj.ptr ())
00164 {
00165 }
00166
00167 CORBA::Any::to_abstract_base::to_abstract_base (CORBA::AbstractBase_ptr &obj)
00168 : ref_ (obj)
00169 {
00170 }
00171
00172 CORBA::Any::to_value::to_value (CORBA::ValueBase *& obj)
00173 : ref_ (obj)
00174 {
00175 }
00176
00177 CORBA::Boolean
00178 CORBA::Any::checked_to_object (CORBA::Object_ptr &_tao_elem) const
00179 {
00180 if (this->impl_ == 0)
00181 {
00182 return 0;
00183 }
00184
00185 return this->impl_->to_object (_tao_elem);
00186 }
00187
00188 CORBA::Boolean
00189 CORBA::Any::checked_to_value (CORBA::ValueBase *&_tao_elem) const
00190 {
00191 if (this->impl_ == 0)
00192 {
00193 return false;
00194 }
00195
00196 return this->impl_->to_value (_tao_elem);
00197 }
00198
00199 CORBA::Boolean
00200 CORBA::Any::checked_to_abstract_base (CORBA::AbstractBase_ptr &_tao_elem) const
00201 {
00202 if (this->impl_ == 0)
00203 {
00204 return false;
00205 }
00206
00207 return this->impl_->to_abstract_base (_tao_elem);
00208 }
00209
00210
00211
00212 CORBA::Any_var::Any_var (const CORBA::Any_var &r)
00213 : ptr_ (0)
00214 {
00215 if (r.ptr_ != 0)
00216 {
00217 ACE_NEW (this->ptr_,
00218 CORBA::Any (*r.ptr_));
00219 }
00220 }
00221
00222 CORBA::Any_var &
00223 CORBA::Any_var::operator= (CORBA::Any *p)
00224 {
00225 if (this->ptr_ != p)
00226 {
00227 delete this->ptr_;
00228 this->ptr_ = p;
00229 }
00230
00231 return *this;
00232 }
00233
00234 CORBA::Any_var &
00235 CORBA::Any_var::operator= (const CORBA::Any_var &r)
00236 {
00237 delete this->ptr_;
00238 this->ptr_ = 0;
00239
00240 if (r.ptr_ != 0)
00241 {
00242 ACE_NEW_RETURN (this->ptr_,
00243 CORBA::Any (*r.ptr_),
00244 *this);
00245 }
00246
00247 return *this;
00248 }
00249
00250
00251
00252 CORBA::Boolean
00253 operator<< (TAO_OutputCDR &cdr, const CORBA::Any &any)
00254 {
00255 TAO::Any_Impl *impl = any.impl ();
00256
00257 if (impl != 0)
00258 {
00259 return impl->marshal (cdr);
00260 }
00261
00262 return (cdr << CORBA::_tc_null);
00263 }
00264
00265 CORBA::Boolean
00266 operator>> (TAO_InputCDR &cdr, CORBA::Any &any)
00267 {
00268 CORBA::TypeCode_var tc;
00269
00270 if ((cdr >> tc.out ()) == 0)
00271 {
00272 return false;
00273 }
00274
00275 try
00276 {
00277 TAO::Unknown_IDL_Type *impl = 0;
00278 ACE_NEW_RETURN (impl,
00279 TAO::Unknown_IDL_Type (tc.in ()),
00280 false);
00281
00282 any.replace (impl);
00283 impl->_tao_decode (cdr);
00284 }
00285 catch (const ::CORBA::Exception&)
00286 {
00287 return false;
00288 }
00289
00290 return true;
00291 }
00292
00293 #if defined (GEN_OSTREAM_OPS)
00294
00295 std::ostream &
00296 operator<< (std::ostream &strm, const CORBA::Any &)
00297 {
00298 return strm << "CORBA::Any";
00299 }
00300
00301 #endif
00302
00303
00304
00305
00306
00307 void
00308 CORBA::Any::operator<<= (CORBA::Any::from_boolean b)
00309 {
00310 TAO::Any_Basic_Impl::insert (*this, CORBA::_tc_boolean, &b.val_);
00311 }
00312
00313 void
00314 CORBA::Any::operator<<= (CORBA::Any::from_octet o)
00315 {
00316 TAO::Any_Basic_Impl::insert (*this, CORBA::_tc_octet, &o.val_);
00317 }
00318
00319 void
00320 CORBA::Any::operator<<= (CORBA::Any::from_char c)
00321 {
00322 TAO::Any_Basic_Impl::insert (*this, CORBA::_tc_char, &c.val_);
00323 }
00324
00325 void
00326 CORBA::Any::operator<<= (CORBA::Any::from_wchar wc)
00327 {
00328 TAO::Any_Basic_Impl::insert (*this, CORBA::_tc_wchar, &wc.val_);
00329 }
00330
00331 void
00332 CORBA::Any::operator<<= (CORBA::Any::from_string s)
00333 {
00334 if (s.bound_ > 0 && s.val_ != 0 && ACE_OS::strlen (s.val_) > s.bound_)
00335 {
00336 return;
00337 }
00338
00339 TAO::Any_Special_Impl_T<
00340 char,
00341 CORBA::Any::from_string,
00342 CORBA::Any::to_string
00343 >::insert (*this,
00344 TAO::Any_Impl::_tao_any_string_destructor,
00345 CORBA::_tc_string,
00346 s.nocopy_ ? s.val_ : CORBA::string_dup (s.val_),
00347 s.bound_);
00348 }
00349
00350 void
00351 CORBA::Any::operator<<= (CORBA::Any::from_wstring ws)
00352 {
00353 if (ws.bound_ > 0 && ws.val_ != 0 && ACE_OS::wslen (ws.val_) > ws.bound_)
00354 {
00355 return;
00356 }
00357
00358 TAO::Any_Special_Impl_T<
00359 CORBA::WChar,
00360 CORBA::Any::from_wstring,
00361 CORBA::Any::to_wstring
00362 >::insert (*this,
00363 TAO::Any_Impl::_tao_any_wstring_destructor,
00364 CORBA::_tc_wstring,
00365 ws.nocopy_ ? ws.val_ : CORBA::wstring_dup (ws.val_),
00366 ws.bound_);
00367 }
00368
00369
00370
00371 void
00372 operator<<= (CORBA::Any &any, CORBA::Short s)
00373 {
00374 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_short, &s);
00375 }
00376
00377 void
00378 operator<<= (CORBA::Any &any, CORBA::UShort us)
00379 {
00380 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_ushort, &us);
00381 }
00382
00383 void
00384 operator<<= (CORBA::Any &any, CORBA::Long l)
00385 {
00386 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_long, &l);
00387 }
00388
00389 void
00390 operator<<= (CORBA::Any &any, CORBA::ULong ul)
00391 {
00392 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_ulong, &ul);
00393 }
00394
00395 void
00396 operator<<= (CORBA::Any &any, CORBA::LongLong ll)
00397 {
00398 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_longlong, &ll);
00399 }
00400
00401 void
00402 operator<<= (CORBA::Any &any, CORBA::ULongLong ull)
00403 {
00404 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_ulonglong, &ull);
00405 }
00406
00407 void
00408 operator<<= (CORBA::Any &any, CORBA::Float f)
00409 {
00410 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_float, &f);
00411 }
00412
00413 void
00414 operator<<= (CORBA::Any &any, CORBA::Double d)
00415 {
00416 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_double, &d);
00417 }
00418
00419 void
00420 operator<<= (CORBA::Any &any, CORBA::LongDouble ld)
00421 {
00422 TAO::Any_Basic_Impl::insert (any, CORBA::_tc_longdouble, &ld);
00423 }
00424
00425
00426 void
00427 operator<<= (CORBA::Any &any, const CORBA::Any &a)
00428 {
00429 if (0 == &a)
00430 any <<= static_cast<CORBA::Any *>( 0 );
00431 else
00432 TAO::Any_Dual_Impl_T<CORBA::Any>::insert_copy (
00433 any,
00434 CORBA::Any::_tao_any_destructor,
00435 CORBA::_tc_any,
00436 a
00437 );
00438 }
00439
00440
00441 void
00442 operator<<= (CORBA::Any &any, CORBA::Any *a)
00443 {
00444 TAO::Any_Dual_Impl_T<CORBA::Any>::insert (any,
00445 CORBA::Any::_tao_any_destructor,
00446 CORBA::_tc_any,
00447 a);
00448 }
00449
00450
00451 void
00452 operator<<= (CORBA::Any &any, CORBA::TypeCode_ptr tc)
00453 {
00454 CORBA::TypeCode_ptr dup = CORBA::TypeCode::_duplicate (tc);
00455 any <<= &dup;
00456 }
00457
00458
00459 void
00460 operator<<= (CORBA::Any &any, CORBA::TypeCode_ptr * tc)
00461 {
00462 TAO::Any_Impl_T<CORBA::TypeCode>::insert (
00463 any,
00464 CORBA::TypeCode::_tao_any_destructor,
00465 CORBA::_tc_TypeCode,
00466 *tc
00467 );
00468 }
00469
00470
00471 void
00472 operator<<= (CORBA::Any &any, const CORBA::Object_ptr obj)
00473 {
00474 CORBA::Object_ptr dup = CORBA::Object::_duplicate (obj);
00475 any <<= &dup;
00476 }
00477
00478
00479 void
00480 operator<<= (CORBA::Any &any, CORBA::Object_ptr *objptr)
00481 {
00482 TAO::Any_Impl_T<CORBA::Object>::insert (any,
00483 CORBA::Object::_tao_any_destructor,
00484 CORBA::_tc_Object,
00485 *objptr);
00486 }
00487
00488
00489
00490
00491 void
00492 operator<<= (CORBA::Any &any, const char *s)
00493 {
00494 TAO::Any_Special_Impl_T<
00495 char,
00496 CORBA::Any::from_string,
00497 CORBA::Any::to_string
00498 >::insert (any,
00499 TAO::Any_Impl::_tao_any_string_destructor,
00500 CORBA::_tc_string,
00501 CORBA::string_dup (s),
00502 0);
00503 }
00504
00505 void
00506 operator<<= (CORBA::Any &any, const CORBA::WChar *ws)
00507 {
00508 TAO::Any_Special_Impl_T<
00509 CORBA::WChar,
00510 CORBA::Any::from_wstring,
00511 CORBA::Any::to_wstring
00512 >::insert (any,
00513 TAO::Any_Impl::_tao_any_wstring_destructor,
00514 CORBA::_tc_wstring,
00515 CORBA::wstring_dup (ws),
00516 0);
00517 }
00518
00519
00520
00521
00522
00523
00524
00525 CORBA::Boolean
00526 CORBA::Any::operator>>= (CORBA::Any::to_boolean b) const
00527 {
00528 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_boolean, &b.ref_);
00529 }
00530
00531 CORBA::Boolean
00532 CORBA::Any::operator>>= (CORBA::Any::to_octet o) const
00533 {
00534 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_octet, &o.ref_);
00535 }
00536
00537 CORBA::Boolean
00538 CORBA::Any::operator>>= (CORBA::Any::to_char c) const
00539 {
00540 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_char, &c.ref_);
00541 }
00542
00543 CORBA::Boolean
00544 CORBA::Any::operator>>= (CORBA::Any::to_wchar wc) const
00545 {
00546 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_wchar, &wc.ref_);
00547 }
00548
00549 CORBA::Boolean
00550 CORBA::Any::operator>>= (CORBA::Any::to_string s) const
00551 {
00552 return
00553 TAO::Any_Special_Impl_T<
00554 char,
00555 CORBA::Any::from_string,
00556 CORBA::Any::to_string
00557 >::extract (*this,
00558 TAO::Any_Impl::_tao_any_string_destructor,
00559 CORBA::_tc_string,
00560 s.val_,
00561 s.bound_);
00562 }
00563
00564 CORBA::Boolean
00565 CORBA::Any::operator>>= (CORBA::Any::to_wstring ws) const
00566 {
00567 return
00568 TAO::Any_Special_Impl_T<
00569 CORBA::WChar,
00570 CORBA::Any::from_wstring,
00571 CORBA::Any::to_wstring
00572 >::extract (*this,
00573 TAO::Any_Impl::_tao_any_wstring_destructor,
00574 CORBA::_tc_wstring,
00575 ws.val_,
00576 ws.bound_);
00577 }
00578
00579 CORBA::Boolean
00580 CORBA::Any::operator>>= (CORBA::Any::to_object obj) const
00581 {
00582 return this->checked_to_object (obj.ref_);
00583 }
00584
00585 CORBA::Boolean
00586 CORBA::Any::operator>>= (CORBA::Any::to_abstract_base obj) const
00587 {
00588 return this->checked_to_abstract_base (obj.ref_);
00589 }
00590
00591 CORBA::Boolean
00592 CORBA::Any::operator>>= (CORBA::Any::to_value obj) const
00593 {
00594 return this->checked_to_value (obj.ref_);
00595 }
00596
00597
00598
00599 CORBA::Boolean
00600 operator>>= (const CORBA::Any &any, CORBA::Short &s)
00601 {
00602 return TAO::Any_Basic_Impl::extract (any, CORBA::_tc_short, &s);
00603 }
00604
00605 CORBA::Boolean
00606 operator>>= (const CORBA::Any &any, CORBA::UShort &us)
00607 {
00608 return TAO::Any_Basic_Impl::extract (any,
00609 CORBA::_tc_ushort,
00610 &us);
00611 }
00612
00613 CORBA::Boolean
00614 operator>>= (const CORBA::Any &any, CORBA::Long &l)
00615 {
00616 return TAO::Any_Basic_Impl::extract (any,
00617 CORBA::_tc_long,
00618 &l);
00619 }
00620
00621 CORBA::Boolean
00622 operator>>= (const CORBA::Any &any, CORBA::ULong &ul)
00623 {
00624 return TAO::Any_Basic_Impl::extract (any,
00625 CORBA::_tc_ulong,
00626 &ul);
00627 }
00628
00629 CORBA::Boolean
00630 operator>>= (const CORBA::Any &any, CORBA::LongLong &ll)
00631 {
00632 return
00633 TAO::Any_Basic_Impl::extract (any,
00634 CORBA::_tc_longlong,
00635 &ll);
00636 }
00637
00638 CORBA::Boolean
00639 operator>>= (const CORBA::Any &any, CORBA::ULongLong &ull)
00640 {
00641 return
00642 TAO::Any_Basic_Impl::extract (any,
00643 CORBA::_tc_ulonglong,
00644 &ull);
00645 }
00646
00647 CORBA::Boolean
00648 operator>>= (const CORBA::Any &any, CORBA::Float &f)
00649 {
00650 return TAO::Any_Basic_Impl::extract (any,
00651 CORBA::_tc_float,
00652 &f);
00653 }
00654
00655 CORBA::Boolean
00656 operator>>= (const CORBA::Any &any, CORBA::Double &d)
00657 {
00658 return TAO::Any_Basic_Impl::extract (any,
00659 CORBA::_tc_double,
00660 &d);
00661 }
00662
00663 CORBA::Boolean
00664 operator>>= (const CORBA::Any &any, CORBA::LongDouble &ld)
00665 {
00666 return
00667 TAO::Any_Basic_Impl::extract (any,
00668 CORBA::_tc_longdouble,
00669 &ld);
00670 }
00671
00672 CORBA::Boolean
00673 operator>>= (const CORBA::Any &any, const CORBA::Any *&a)
00674 {
00675 return TAO::Any_Dual_Impl_T<CORBA::Any>::extract (
00676 any,
00677 CORBA::Any::_tao_any_destructor,
00678 CORBA::_tc_any,
00679 a
00680 );
00681 }
00682
00683 CORBA::Boolean
00684 operator>>= (const CORBA::Any &any, const CORBA::Char *&s)
00685 {
00686 return
00687 TAO::Any_Special_Impl_T<
00688 char,
00689 CORBA::Any::from_string,
00690 CORBA::Any::to_string
00691 >::extract (any,
00692 TAO::Any_Impl::_tao_any_string_destructor,
00693 CORBA::_tc_string,
00694 s,
00695 0);
00696 }
00697
00698 CORBA::Boolean
00699 operator>>= (const CORBA::Any &any, const CORBA::WChar *&ws)
00700 {
00701 return
00702 TAO::Any_Special_Impl_T<
00703 CORBA::WChar,
00704 CORBA::Any::from_wstring,
00705 CORBA::Any::to_wstring
00706 >::extract (any,
00707 TAO::Any_Impl::_tao_any_wstring_destructor,
00708 CORBA::_tc_wstring,
00709 ws,
00710 0);
00711 }
00712
00713 CORBA::Boolean
00714 operator>>= (const CORBA::Any &any, CORBA::TypeCode_ptr &tc)
00715 {
00716 return TAO::Any_Impl_T<CORBA::TypeCode>::extract (
00717 any,
00718 CORBA::TypeCode::_tao_any_destructor,
00719 CORBA::_tc_TypeCode,
00720 tc
00721 );
00722 }
00723
00724
00725
00726
00727 namespace TAO
00728 {
00729 template<>
00730 CORBA::Boolean
00731 Any_Impl_T<CORBA::Object>::to_object (
00732 CORBA::Object_ptr &_tao_elem
00733 ) const
00734 {
00735 _tao_elem = CORBA::Object::_duplicate (this->value_);
00736 return true;
00737 }
00738 }
00739
00740 TAO_END_VERSIONED_NAMESPACE_DECL