2 #include "tao/AnyTypeCode/Any.h"
3 #include "tao/AnyTypeCode/Any_Basic_Impl.h"
4 #include "tao/AnyTypeCode/Any_Impl_T.h"
5 #include "tao/AnyTypeCode/Any_Special_Impl_T.h"
6 #include "tao/AnyTypeCode/Any_Dual_Impl_T.h"
7 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
8 #include "tao/AnyTypeCode/TypeCode.h"
9 #include "tao/AnyTypeCode/TypeCode_Constants.h"
11 #include "tao/SystemException.h"
13 #include "ace/Log_Msg.h"
14 #include "ace/OS_NS_string.h"
15 #include "ace/OS_NS_wchar.h"
16 #include "ace/OS_Memory.h"
19 #if !defined (__ACE_INLINE__)
20 # include "tao/AnyTypeCode/Any.inl"
21 #endif /* ! __ACE_INLINE__ */
23 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
27 CORBA::Any::Any (const CORBA::Any
&rhs
)
32 this->impl_
->_add_ref ();
40 this->impl_
->_remove_ref ();
45 CORBA::Any::operator= (const CORBA::Any
&rhs
)
47 if (this->impl_
!= rhs
.impl_
)
51 this->impl_
->_remove_ref ();
54 this->impl_
= rhs
.impl_
;
58 this->impl_
->_add_ref ();
66 CORBA::Any::replace (TAO::Any_Impl
*new_impl
)
68 ACE_ASSERT (new_impl
!= 0);
72 this->impl_
->_remove_ref ();
75 this->impl_
= new_impl
;
79 CORBA::Any::type () const
83 return this->impl_
->type ();
86 return CORBA::TypeCode::_duplicate (CORBA::_tc_null
);
90 CORBA::Any::_tao_get_typecode () const
94 return this->impl_
->_tao_get_typecode ();
97 return CORBA::_tc_null
;
101 CORBA::Any::_tao_set_typecode (const CORBA::TypeCode_ptr tc
)
105 ACE_NEW (this->impl_
,
106 TAO::Unknown_IDL_Type (tc
));
110 this->impl_
->type (tc
);
115 CORBA::Any::_tao_byte_order () const
119 return this->impl_
->_tao_byte_order ();
122 return TAO_ENCAP_BYTE_ORDER
;
126 CORBA::Any::type (CORBA::TypeCode_ptr tc
)
128 CORBA::Boolean equiv
= false;
132 equiv
= this->impl_
->_tao_get_typecode ()->equivalent (tc
);
137 this->impl_
->type (tc
);
141 throw ::CORBA::BAD_TYPECODE ();
146 CORBA::Any::_tao_any_destructor (void *x
)
148 CORBA::Any
*tmp
= static_cast<CORBA::Any
*> (x
);
152 CORBA::Any::to_object::to_object (CORBA::Object_out obj
)
157 CORBA::Any::to_abstract_base::to_abstract_base (CORBA::AbstractBase_ptr
&obj
)
162 CORBA::Any::to_value::to_value (CORBA::ValueBase
*& obj
)
168 CORBA::Any::checked_to_object (CORBA::Object_ptr
&_tao_elem
) const
175 return this->impl_
->to_object (_tao_elem
);
179 CORBA::Any::checked_to_value (CORBA::ValueBase
*&_tao_elem
) const
186 return this->impl_
->to_value (_tao_elem
);
190 CORBA::Any::checked_to_abstract_base (CORBA::AbstractBase_ptr
&_tao_elem
) const
197 return this->impl_
->to_abstract_base (_tao_elem
);
200 // ****************************************************************
202 CORBA::Any_var::Any_var (const CORBA::Any_var
&r
)
207 CORBA::Any (*r
.ptr_
));
212 CORBA::Any_var::operator= (CORBA::Any
*p
)
224 CORBA::Any_var::operator= (const CORBA::Any_var
&r
)
227 this->ptr_
= nullptr;
231 ACE_NEW_RETURN (this->ptr_
,
232 CORBA::Any (*r
.ptr_
),
239 // ***********************************************************************
242 operator<< (TAO_OutputCDR
&cdr
, const CORBA::Any
&any
)
244 TAO::Any_Impl
*impl
= any
.impl ();
248 return impl
->marshal (cdr
);
251 return (cdr
<< CORBA::_tc_null
);
255 operator>> (TAO_InputCDR
&cdr
, CORBA::Any
&any
)
257 CORBA::TypeCode_var tc
;
259 if (!(cdr
>> tc
.out ()))
266 TAO::Unknown_IDL_Type
*impl
= nullptr;
267 ACE_NEW_RETURN (impl
,
268 TAO::Unknown_IDL_Type (tc
.in ()),
272 impl
->_tao_decode (cdr
);
274 catch (const ::CORBA::Exception
&)
282 #if defined (GEN_OSTREAM_OPS)
285 operator<< (std::ostream
&strm
, const CORBA::Any
&)
287 return strm
<< "CORBA::Any";
290 #endif /* GEN_OSTREAM_OPS */
292 // =======================================================================
294 // Insertion of the special basic types.
297 CORBA::Any::operator<<= (CORBA::Any::from_boolean b
)
299 TAO::Any_Basic_Impl::insert (*this, CORBA::_tc_boolean
, &b
.val_
);
303 CORBA::Any::operator<<= (CORBA::Any::from_octet o
)
305 TAO::Any_Basic_Impl::insert (*this, CORBA::_tc_octet
, &o
.val_
);
309 CORBA::Any::operator<<= (CORBA::Any::from_char c
)
311 TAO::Any_Basic_Impl::insert (*this, CORBA::_tc_char
, &c
.val_
);
315 CORBA::Any::operator<<= (CORBA::Any::from_wchar wc
)
317 TAO::Any_Basic_Impl::insert (*this, CORBA::_tc_wchar
, &wc
.val_
);
321 CORBA::Any::operator<<= (CORBA::Any::from_string s
)
323 if (s
.bound_
> 0 && s
.val_
!= 0 && std::strlen (s
.val_
) > s
.bound_
)
328 TAO::Any_Special_Impl_T
<
330 CORBA::Any::from_string
,
331 CORBA::Any::to_string
333 TAO::Any_Impl::_tao_any_string_destructor
,
335 s
.nocopy_
? s
.val_
: CORBA::string_dup (s
.val_
),
340 CORBA::Any::operator<<= (CORBA::Any::from_wstring ws
)
342 if (ws
.bound_
> 0 && ws
.val_
!= 0 && ACE_OS::wslen (ws
.val_
) > ws
.bound_
)
347 TAO::Any_Special_Impl_T
<
349 CORBA::Any::from_wstring
,
350 CORBA::Any::to_wstring
352 TAO::Any_Impl::_tao_any_wstring_destructor
,
354 ws
.nocopy_
? ws
.val_
: CORBA::wstring_dup (ws
.val_
),
358 // Insertion of the other basic types.
363 operator<<= (CORBA::Any
&any
, CORBA::Short s
)
365 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_short
, &s
);
369 operator<<= (CORBA::Any
&any
, CORBA::UShort us
)
371 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_ushort
, &us
);
375 operator<<= (CORBA::Any
&any
, CORBA::Long l
)
377 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_long
, &l
);
381 operator<<= (CORBA::Any
&any
, CORBA::ULong ul
)
383 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_ulong
, &ul
);
387 operator<<= (CORBA::Any
&any
, CORBA::LongLong ll
)
389 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_longlong
, &ll
);
393 operator<<= (CORBA::Any
&any
, CORBA::ULongLong ull
)
395 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_ulonglong
, &ull
);
399 operator<<= (CORBA::Any
&any
, CORBA::Float f
)
401 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_float
, &f
);
405 operator<<= (CORBA::Any
&any
, CORBA::Double d
)
407 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_double
, &d
);
411 operator<<= (CORBA::Any
&any
, CORBA::LongDouble ld
)
413 TAO::Any_Basic_Impl::insert (any
, CORBA::_tc_longdouble
, &ld
);
416 // Insertion of Any - copying.
418 operator<<= (CORBA::Any
&any
, const CORBA::Any
&a
)
420 TAO::Any_Dual_Impl_T
<CORBA::Any
>::insert_copy (
422 CORBA::Any::_tao_any_destructor
,
427 // Insertion of Any - non-copying.
429 operator<<= (CORBA::Any
&any
, CORBA::Any
*a
)
431 TAO::Any_Dual_Impl_T
<CORBA::Any
>::insert (any
,
432 CORBA::Any::_tao_any_destructor
,
437 // Insertion of TypeCode - copying.
439 operator<<= (CORBA::Any
&any
, CORBA::TypeCode_ptr tc
)
441 CORBA::TypeCode_ptr dup
= CORBA::TypeCode::_duplicate (tc
);
445 // Insertion of TypeCode - non-copying.
447 operator<<= (CORBA::Any
&any
, CORBA::TypeCode_ptr
* tc
)
449 TAO::Any_Impl_T
<CORBA::TypeCode
>::insert (
451 CORBA::TypeCode::_tao_any_destructor
,
456 // Insertion of CORBA object - copying.
458 operator<<= (CORBA::Any
&any
, const CORBA::Object_ptr obj
)
460 CORBA::Object_ptr dup
= CORBA::Object::_duplicate (obj
);
464 // Insertion of CORBA object - non-copying.
466 operator<<= (CORBA::Any
&any
, CORBA::Object_ptr
*objptr
)
468 TAO::Any_Impl_T
<CORBA::Object
>::insert (any
,
469 CORBA::Object::_tao_any_destructor
,
474 // These are copying versions for unbounded (w)strings. They are not inlined,
475 // to avoid use in Any.inl before definition in ORB.inl.
478 operator<<= (CORBA::Any
&any
, const char *s
)
480 TAO::Any_Special_Impl_T
<
482 CORBA::Any::from_string
,
483 CORBA::Any::to_string
485 TAO::Any_Impl::_tao_any_string_destructor
,
487 CORBA::string_dup (s
),
492 operator<<= (CORBA::Any
&any
, const CORBA::WChar
*ws
)
494 TAO::Any_Special_Impl_T
<
496 CORBA::Any::from_wstring
,
497 CORBA::Any::to_wstring
499 TAO::Any_Impl::_tao_any_wstring_destructor
,
501 CORBA::wstring_dup (ws
),
506 operator <<= (CORBA::Any
&any
, const std::string
& str
)
508 any
<<= str
.c_str ();
512 operator <<= (CORBA::Any
&, std::string
*)
517 #if !defined(ACE_LACKS_STD_WSTRING)
519 operator <<= (CORBA::Any
&any
, const std::wstring
& str
)
521 any
<<= str
.c_str ();
525 operator <<= (CORBA::Any
&, std::wstring
*)
531 // Extraction: these are safe and hence we have to check that the
532 // typecode of the Any is equal to the one we are trying to extract
535 // Extraction into the special basic types.
538 CORBA::Any::operator>>= (CORBA::Any::to_boolean b
) const
540 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_boolean
, &b
.ref_
);
544 CORBA::Any::operator>>= (CORBA::Any::to_octet o
) const
546 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_octet
, &o
.ref_
);
550 CORBA::Any::operator>>= (CORBA::Any::to_char c
) const
552 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_char
, &c
.ref_
);
556 CORBA::Any::operator>>= (CORBA::Any::to_wchar wc
) const
558 return TAO::Any_Basic_Impl::extract (*this, CORBA::_tc_wchar
, &wc
.ref_
);
562 CORBA::Any::operator>>= (CORBA::Any::to_string s
) const
565 TAO::Any_Special_Impl_T
<
567 CORBA::Any::from_string
,
568 CORBA::Any::to_string
570 TAO::Any_Impl::_tao_any_string_destructor
,
577 CORBA::Any::operator>>= (CORBA::Any::to_wstring ws
) const
580 TAO::Any_Special_Impl_T
<
582 CORBA::Any::from_wstring
,
583 CORBA::Any::to_wstring
585 TAO::Any_Impl::_tao_any_wstring_destructor
,
592 CORBA::Any::operator>>= (CORBA::Any::to_object obj
) const
594 return this->checked_to_object (obj
.ref_
);
598 CORBA::Any::operator>>= (CORBA::Any::to_abstract_base obj
) const
600 return this->checked_to_abstract_base (obj
.ref_
);
604 CORBA::Any::operator>>= (CORBA::Any::to_value obj
) const
606 return this->checked_to_value (obj
.ref_
);
609 // Extraction into the other basic types.
612 operator>>= (const CORBA::Any
&any
, CORBA::Short
&s
)
614 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_short
, std::addressof(s
));
618 operator>>= (const CORBA::Any
&any
, CORBA::UShort
&us
)
620 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_ushort
, std::addressof(us
));
624 operator>>= (const CORBA::Any
&any
, CORBA::Long
&l
)
626 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_long
, std::addressof(l
));
630 operator>>= (const CORBA::Any
&any
, CORBA::ULong
&ul
)
632 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_ulong
, std::addressof(ul
));
636 operator>>= (const CORBA::Any
&any
, CORBA::LongLong
&ll
)
638 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_longlong
, std::addressof(ll
));
642 operator>>= (const CORBA::Any
&any
, CORBA::ULongLong
&ull
)
644 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_ulonglong
, std::addressof(ull
));
648 operator>>= (const CORBA::Any
&any
, CORBA::Float
&f
)
650 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_float
, std::addressof(f
));
654 operator>>= (const CORBA::Any
&any
, CORBA::Double
&d
)
656 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_double
, std::addressof(d
));
660 operator>>= (const CORBA::Any
&any
, CORBA::LongDouble
&ld
)
662 return TAO::Any_Basic_Impl::extract (any
, CORBA::_tc_longdouble
, std::addressof(ld
));
666 operator>>= (const CORBA::Any
&any
, const CORBA::Any
*&a
)
668 return TAO::Any_Dual_Impl_T
<CORBA::Any
>::extract (
670 CORBA::Any::_tao_any_destructor
,
676 operator>>= (const CORBA::Any
&any
, const CORBA::Char
*&s
)
679 TAO::Any_Special_Impl_T
<
681 CORBA::Any::from_string
,
682 CORBA::Any::to_string
684 TAO::Any_Impl::_tao_any_string_destructor
,
691 operator>>= (const CORBA::Any
&any
, const CORBA::WChar
*&ws
)
694 TAO::Any_Special_Impl_T
<
696 CORBA::Any::from_wstring
,
697 CORBA::Any::to_wstring
699 TAO::Any_Impl::_tao_any_wstring_destructor
,
706 operator>>= (const CORBA::Any
&any
, CORBA::TypeCode_ptr
&tc
)
708 return TAO::Any_Impl_T
<CORBA::TypeCode
>::extract (
710 CORBA::TypeCode::_tao_any_destructor
,
716 operator >>= (const CORBA::Any
&any
, std::string
&str
)
718 const char *buf
= nullptr;
719 CORBA::Boolean
const flag
= any
>>= buf
;
729 #if !defined(ACE_LACKS_STD_WSTRING)
731 operator >>= (const CORBA::Any
&any
, std::wstring
&str
)
733 const wchar_t *buf
= nullptr;
734 CORBA::Boolean
const flag
= any
>>= buf
;
747 // ================================================================
748 // Any_Impl_T template specializations.
754 Any_Impl_T
<CORBA::Object
>::to_object (CORBA::Object_ptr
&_tao_elem
) const
756 _tao_elem
= CORBA::Object::_duplicate (this->value_
);
761 TAO_END_VERSIONED_NAMESPACE_DECL