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 90603 2010-06-15 14:03:49Z 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 void
00520 operator <<= (CORBA::Any &any, const std::string & str)
00521 {
00522 any <<= str.c_str ();
00523 }
00524
00525 void
00526 operator <<= (CORBA::Any &, std::string *)
00527 {
00528
00529 }
00530
00531
00532
00533
00534
00535
00536
00537 CORBA::Boolean
00538 CORBA::Any::operator>>= (CORBA::Any::to_boolean b) const
00539 {
00540 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_boolean, &b.ref_);
00541 }
00542
00543 CORBA::Boolean
00544 CORBA::Any::operator>>= (CORBA::Any::to_octet o) const
00545 {
00546 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_octet, &o.ref_);
00547 }
00548
00549 CORBA::Boolean
00550 CORBA::Any::operator>>= (CORBA::Any::to_char c) const
00551 {
00552 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_char, &c.ref_);
00553 }
00554
00555 CORBA::Boolean
00556 CORBA::Any::operator>>= (CORBA::Any::to_wchar wc) const
00557 {
00558 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_wchar, &wc.ref_);
00559 }
00560
00561 CORBA::Boolean
00562 CORBA::Any::operator>>= (CORBA::Any::to_string s) const
00563 {
00564 return
00565 TAO::Any_Special_Impl_T<
00566 char,
00567 CORBA::Any::from_string,
00568 CORBA::Any::to_string
00569 >::extract (*this,
00570 TAO::Any_Impl::_tao_any_string_destructor,
00571 CORBA::_tc_string,
00572 s.val_,
00573 s.bound_);
00574 }
00575
00576 CORBA::Boolean
00577 CORBA::Any::operator>>= (CORBA::Any::to_wstring ws) const
00578 {
00579 return
00580 TAO::Any_Special_Impl_T<
00581 CORBA::WChar,
00582 CORBA::Any::from_wstring,
00583 CORBA::Any::to_wstring
00584 >::extract (*this,
00585 TAO::Any_Impl::_tao_any_wstring_destructor,
00586 CORBA::_tc_wstring,
00587 ws.val_,
00588 ws.bound_);
00589 }
00590
00591 CORBA::Boolean
00592 CORBA::Any::operator>>= (CORBA::Any::to_object obj) const
00593 {
00594 return this->checked_to_object (obj.ref_);
00595 }
00596
00597 CORBA::Boolean
00598 CORBA::Any::operator>>= (CORBA::Any::to_abstract_base obj) const
00599 {
00600 return this->checked_to_abstract_base (obj.ref_);
00601 }
00602
00603 CORBA::Boolean
00604 CORBA::Any::operator>>= (CORBA::Any::to_value obj) const
00605 {
00606 return this->checked_to_value (obj.ref_);
00607 }
00608
00609
00610
00611 CORBA::Boolean
00612 operator>>= (const CORBA::Any &any, CORBA::Short &s)
00613 {
00614 return TAO::Any_Basic_Impl::extract (any, CORBA::_tc_short, &s);
00615 }
00616
00617 CORBA::Boolean
00618 operator>>= (const CORBA::Any &any, CORBA::UShort &us)
00619 {
00620 return TAO::Any_Basic_Impl::extract (any,
00621 CORBA::_tc_ushort,
00622 &us);
00623 }
00624
00625 CORBA::Boolean
00626 operator>>= (const CORBA::Any &any, CORBA::Long &l)
00627 {
00628 return TAO::Any_Basic_Impl::extract (any,
00629 CORBA::_tc_long,
00630 &l);
00631 }
00632
00633 CORBA::Boolean
00634 operator>>= (const CORBA::Any &any, CORBA::ULong &ul)
00635 {
00636 return TAO::Any_Basic_Impl::extract (any,
00637 CORBA::_tc_ulong,
00638 &ul);
00639 }
00640
00641 CORBA::Boolean
00642 operator>>= (const CORBA::Any &any, CORBA::LongLong &ll)
00643 {
00644 return
00645 TAO::Any_Basic_Impl::extract (any,
00646 CORBA::_tc_longlong,
00647 &ll);
00648 }
00649
00650 CORBA::Boolean
00651 operator>>= (const CORBA::Any &any, CORBA::ULongLong &ull)
00652 {
00653 return
00654 TAO::Any_Basic_Impl::extract (any,
00655 CORBA::_tc_ulonglong,
00656 &ull);
00657 }
00658
00659 CORBA::Boolean
00660 operator>>= (const CORBA::Any &any, CORBA::Float &f)
00661 {
00662 return TAO::Any_Basic_Impl::extract (any,
00663 CORBA::_tc_float,
00664 &f);
00665 }
00666
00667 CORBA::Boolean
00668 operator>>= (const CORBA::Any &any, CORBA::Double &d)
00669 {
00670 return TAO::Any_Basic_Impl::extract (any,
00671 CORBA::_tc_double,
00672 &d);
00673 }
00674
00675 CORBA::Boolean
00676 operator>>= (const CORBA::Any &any, CORBA::LongDouble &ld)
00677 {
00678 return
00679 TAO::Any_Basic_Impl::extract (any,
00680 CORBA::_tc_longdouble,
00681 &ld);
00682 }
00683
00684 CORBA::Boolean
00685 operator>>= (const CORBA::Any &any, const CORBA::Any *&a)
00686 {
00687 return TAO::Any_Dual_Impl_T<CORBA::Any>::extract (
00688 any,
00689 CORBA::Any::_tao_any_destructor,
00690 CORBA::_tc_any,
00691 a
00692 );
00693 }
00694
00695 CORBA::Boolean
00696 operator>>= (const CORBA::Any &any, const CORBA::Char *&s)
00697 {
00698 return
00699 TAO::Any_Special_Impl_T<
00700 char,
00701 CORBA::Any::from_string,
00702 CORBA::Any::to_string
00703 >::extract (any,
00704 TAO::Any_Impl::_tao_any_string_destructor,
00705 CORBA::_tc_string,
00706 s,
00707 0);
00708 }
00709
00710 CORBA::Boolean
00711 operator>>= (const CORBA::Any &any, const CORBA::WChar *&ws)
00712 {
00713 return
00714 TAO::Any_Special_Impl_T<
00715 CORBA::WChar,
00716 CORBA::Any::from_wstring,
00717 CORBA::Any::to_wstring
00718 >::extract (any,
00719 TAO::Any_Impl::_tao_any_wstring_destructor,
00720 CORBA::_tc_wstring,
00721 ws,
00722 0);
00723 }
00724
00725 CORBA::Boolean
00726 operator>>= (const CORBA::Any &any, CORBA::TypeCode_ptr &tc)
00727 {
00728 return TAO::Any_Impl_T<CORBA::TypeCode>::extract (
00729 any,
00730 CORBA::TypeCode::_tao_any_destructor,
00731 CORBA::_tc_TypeCode,
00732 tc
00733 );
00734 }
00735
00736 CORBA::Boolean
00737 operator >>= (const CORBA::Any &any, std::string &str)
00738 {
00739 const char *buf = 0;
00740 CORBA::Boolean flag = any >>= buf;
00741 str.assign (buf);
00742 ACE::strdelete (const_cast <char *> (buf));
00743 return flag;
00744 }
00745
00746
00747
00748
00749 namespace TAO
00750 {
00751 template<>
00752 CORBA::Boolean
00753 Any_Impl_T<CORBA::Object>::to_object (
00754 CORBA::Object_ptr &_tao_elem
00755 ) const
00756 {
00757 _tao_elem = CORBA::Object::_duplicate (this->value_);
00758 return true;
00759 }
00760 }
00761
00762 TAO_END_VERSIONED_NAMESPACE_DECL