Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / DynamicAny / DynCommon.cpp
bloba9b0606205a3c9da2ceb3bf398ab66a2db6950bc
1 // -*- C++ -*-
2 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
3 #include "tao/Valuetype/AbstractBase.h"
5 #include "tao/DynamicAny/DynCommon.h"
7 #include "tao/DynamicAny/DynAnyFactory.h"
8 #include "tao/DynamicAny/DynAny_i.h"
9 #include "tao/DynamicAny/DynArray_i.h"
10 #include "tao/DynamicAny/DynEnum_i.h"
11 #include "tao/DynamicAny/DynSequence_i.h"
12 #include "tao/DynamicAny/DynStruct_i.h"
13 #include "tao/DynamicAny/DynUnion_i.h"
14 #include "tao/DynamicAny/DynAnyUtils_T.h"
16 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
17 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
19 #include "tao/CDR.h"
21 #include "ace/OS_NS_wchar.h"
22 #include "ace/OS_NS_string.h"
23 #include <cstring>
25 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
27 TAO_DynCommon::TAO_DynCommon (CORBA::Boolean allow_truncation)
28 : ref_to_component_ (false)
29 , container_is_destroying_ (false)
30 , has_components_ (false)
31 , destroyed_ (false)
32 , current_position_ (-1)
33 , component_count_ (0)
34 , allow_truncation_ (allow_truncation)
38 TAO_DynCommon::~TAO_DynCommon ()
42 CORBA::TypeCode_ptr
43 TAO_DynCommon::type ()
45 if (this->destroyed_)
47 throw ::CORBA::OBJECT_NOT_EXIST ();
50 return CORBA::TypeCode::_duplicate (this->type_.in ());
53 void
54 TAO_DynCommon::assign (DynamicAny::DynAny_ptr dyn_any)
56 if (this->destroyed_)
58 throw ::CORBA::OBJECT_NOT_EXIST ();
61 CORBA::TypeCode_var tc = dyn_any->type ();
63 CORBA::Boolean const equivalent = this->type_.in ()->equivalent (tc.in ());
65 if (equivalent)
67 CORBA::Any_var any = dyn_any->to_any ();
69 this->from_any (any.in ());
71 else
73 throw DynamicAny::DynAny::TypeMismatch ();
77 void
78 TAO_DynCommon::insert_boolean (CORBA::Boolean value)
80 TAO::DynAnyBasicTypeUtils<CORBA::Boolean>::insert_value (value, this);
83 void
84 TAO_DynCommon::insert_octet (CORBA::Octet value)
86 TAO::DynAnyBasicTypeUtils<CORBA::Octet>::insert_value (value, this);
89 void
90 TAO_DynCommon::insert_char (CORBA::Char value)
92 TAO::DynAnyBasicTypeUtils<CORBA::Char>::insert_value (value, this);
95 void
96 TAO_DynCommon::insert_short (CORBA::Short value)
98 TAO::DynAnyBasicTypeUtils<CORBA::Short>::insert_value (value, this);
101 void
102 TAO_DynCommon::insert_ushort (CORBA::UShort value)
104 TAO::DynAnyBasicTypeUtils<CORBA::UShort>::insert_value (value, this);
107 void
108 TAO_DynCommon::insert_long (CORBA::Long value)
110 TAO::DynAnyBasicTypeUtils<CORBA::Long>::insert_value (value, this);
113 void
114 TAO_DynCommon::insert_ulong (CORBA::ULong value)
116 TAO::DynAnyBasicTypeUtils<CORBA::ULong>::insert_value (value, this);
119 void
120 TAO_DynCommon::insert_float (CORBA::Float value)
122 TAO::DynAnyBasicTypeUtils<CORBA::Float>::insert_value (value, this);
125 void
126 TAO_DynCommon::insert_double (CORBA::Double value)
128 TAO::DynAnyBasicTypeUtils<CORBA::Double>::insert_value (value, this);
131 void
132 TAO_DynCommon::insert_string (const char * value)
134 if (this->destroyed_)
136 throw ::CORBA::OBJECT_NOT_EXIST ();
139 if (this->has_components_)
141 DynamicAny::DynAny_var cc =
142 this->check_component ();
144 cc->insert_string (value);
146 else
148 CORBA::TypeCode_var unaliased_tc =
149 TAO_DynAnyFactory::strip_alias (this->type_.in ());
151 CORBA::TCKind const kind =
152 unaliased_tc->kind ();
154 if (kind != CORBA::tk_string)
156 throw DynamicAny::DynAny::TypeMismatch ();
159 CORBA::ULong const bound =
160 unaliased_tc->length ();
162 if (bound > 0 && bound < std::strlen (value))
164 throw DynamicAny::DynAny::InvalidValue ();
167 this->any_ <<= CORBA::Any::from_string (const_cast<char *> (value),
168 bound);
172 void
173 TAO_DynCommon::insert_reference (CORBA::Object_ptr value)
175 if (this->destroyed_)
177 throw ::CORBA::OBJECT_NOT_EXIST ();
180 if (this->has_components_)
182 DynamicAny::DynAny_var cc =
183 this->check_component ();
185 cc->insert_reference (value);
187 else
189 CORBA::Boolean good_type = true;
190 CORBA::TCKind const kind =
191 TAO_DynAnyFactory::unalias (this->type_.in ());
193 if (kind != CORBA::tk_objref)
195 good_type = false;
197 else if (!CORBA::is_nil (value))
199 const char *value_id = value->_interface_repository_id ();
201 if (ACE_OS::strcmp (value_id, "IDL:omg.org/CORBA/Object:1.0") != 0)
203 const char *my_id =
204 this->type_->id ();
206 if (ACE_OS::strcmp (value_id, my_id) != 0)
208 good_type = value->_is_a (my_id);
213 if (good_type)
215 TAO_OutputCDR cdr;
217 if (CORBA::is_nil (value))
219 // Empty type hint, no profile.
220 cdr.write_ulong (1);
221 cdr.write_char ('\0');
222 cdr.write_ulong (0);
224 else
226 if (!value->marshal (cdr))
228 throw DynamicAny::DynAny::InvalidValue ();
232 TAO_InputCDR in (cdr);
233 TAO::Unknown_IDL_Type *unk = 0;
234 ACE_NEW (unk,
235 TAO::Unknown_IDL_Type (this->type_.in (),
236 in));
237 this->any_.replace (unk);
239 else
241 throw DynamicAny::DynAny::TypeMismatch ();
246 void
247 TAO_DynCommon::insert_typecode (CORBA::TypeCode_ptr value)
249 TAO::DynAnyBasicTypeUtils<CORBA::TypeCode_ptr>::insert_value (value, this);
252 void
253 TAO_DynCommon::insert_longlong (CORBA::LongLong value)
255 TAO::DynAnyBasicTypeUtils<CORBA::LongLong>::insert_value (value, this);
258 void
259 TAO_DynCommon::insert_ulonglong (CORBA::ULongLong value)
261 TAO::DynAnyBasicTypeUtils<CORBA::ULongLong>::insert_value (value, this);
264 void
265 TAO_DynCommon::insert_longdouble (CORBA::LongDouble value)
267 TAO::DynAnyBasicTypeUtils<CORBA::LongDouble>::insert_value (value,
268 this);
271 void
272 TAO_DynCommon::insert_wchar (CORBA::WChar value)
274 TAO::DynAnyBasicTypeUtils<CORBA::WChar>::insert_value (value,
275 this);
278 void
279 TAO_DynCommon::insert_wstring (const CORBA::WChar * value)
281 if (this->destroyed_)
283 throw ::CORBA::OBJECT_NOT_EXIST ();
286 if (this->has_components_)
288 DynamicAny::DynAny_var cc =
289 this->check_component ();
291 cc->insert_wstring (value);
293 else
295 CORBA::TypeCode_var unaliased_tc =
296 this->check_type_and_unalias (CORBA::_tc_wstring);
298 CORBA::ULong const bound = unaliased_tc->length ();
300 if (bound > 0 && bound < ACE_OS::wslen (value))
302 throw DynamicAny::DynAny::InvalidValue ();
305 this->any_ <<= CORBA::Any::from_wstring (const_cast<CORBA::WChar *> (value),
306 bound);
310 void
311 TAO_DynCommon::insert_any (const CORBA::Any &value)
313 TAO::DynAnyBasicTypeUtils<CORBA::Any>::insert_value (value,
314 this);
317 // @@@ (JP) TODO - optimize - this version was intended by the OMG to
318 // have fewer Any/DynAny conversions than insert_any, not more.
319 void
320 TAO_DynCommon::insert_dyn_any (DynamicAny::DynAny_ptr value)
322 if (this->destroyed_)
324 throw ::CORBA::OBJECT_NOT_EXIST ();
327 CORBA::Any_var any = value->to_any ();
329 this->insert_any (any.in ());
332 void
333 TAO_DynCommon::insert_val (CORBA::ValueBase *value)
335 if (this->destroyed_)
337 throw ::CORBA::OBJECT_NOT_EXIST ();
340 if (this->has_components_)
342 DynamicAny::DynAny_var cc =
343 this->check_component (true);
345 cc->insert_val (value);
347 else
349 CORBA::TCKind kind =
350 TAO_DynAnyFactory::unalias (this->type_.in ());
352 if (kind != CORBA::tk_value)
354 throw DynamicAny::DynAny::TypeMismatch ();
357 // If the arg is 0 we can't do this kind of type checking,
358 // and the call to _tao_marshal() below will handle the
359 // null value correctly.
360 if (value != 0)
362 const char *value_id = value->_tao_obv_repository_id ();
363 const char *my_id =
364 this->type_->id ();
366 // Valuetypes, unlike interfaces, don't have a virtual
367 // method to check for a more derived type when the
368 // repo ids don't match. Valuetypes have only
369 // a static _downcast() method, which can't be used
370 // here, so if the repo ids don't match, we're hosed.
371 if (ACE_OS::strcmp (value_id, my_id) != 0)
373 throw DynamicAny::DynAny::TypeMismatch ();
377 // This will handle null values correctly, or otherwise
378 // make a virtual call to marshal the state.
379 TAO_OutputCDR out;
380 CORBA::Boolean const good_insert =
381 CORBA::ValueBase::_tao_marshal (out, value);
383 if (!good_insert)
385 throw DynamicAny::DynAny::InvalidValue ();
388 TAO_InputCDR in (out);
389 TAO::Unknown_IDL_Type *unk = 0;
390 ACE_NEW (unk,
391 TAO::Unknown_IDL_Type (this->type_.in (), in));
392 this->any_.replace (unk);
396 // ****************************************************************
398 CORBA::Boolean
399 TAO_DynCommon::get_boolean ()
401 return TAO::DynAnyBasicTypeUtils<CORBA::Boolean>::get_value (this);
404 CORBA::Octet
405 TAO_DynCommon::get_octet ()
407 return TAO::DynAnyBasicTypeUtils<CORBA::Octet>::get_value (this);
410 CORBA::Char
411 TAO_DynCommon::get_char ()
413 return TAO::DynAnyBasicTypeUtils<CORBA::Char>::get_value (this);
416 CORBA::Short
417 TAO_DynCommon::get_short ()
419 return TAO::DynAnyBasicTypeUtils<CORBA::Short>::get_value (this);
422 CORBA::UShort
423 TAO_DynCommon::get_ushort ()
425 return TAO::DynAnyBasicTypeUtils<CORBA::UShort>::get_value (this);
428 CORBA::Long
429 TAO_DynCommon::get_long ()
431 return TAO::DynAnyBasicTypeUtils<CORBA::Long>::get_value (this);
434 CORBA::ULong
435 TAO_DynCommon::get_ulong ()
437 return TAO::DynAnyBasicTypeUtils<CORBA::ULong>::get_value (this);
440 CORBA::Float
441 TAO_DynCommon::get_float ()
443 return TAO::DynAnyBasicTypeUtils<CORBA::Float>::get_value (this);
446 CORBA::Double
447 TAO_DynCommon::get_double ()
449 return TAO::DynAnyBasicTypeUtils<CORBA::Double>::get_value (this);
452 char *
453 TAO_DynCommon::get_string ()
455 if (this->destroyed_)
457 throw ::CORBA::OBJECT_NOT_EXIST ();
460 if (this->has_components_)
462 DynamicAny::DynAny_var cc =
463 this->check_component ();
465 return cc->get_string ();
467 else
469 CORBA::TypeCode_var unaliased_tc =
470 TAO_DynAnyFactory::strip_alias (this->type_.in ());
472 CORBA::TCKind kind =
473 unaliased_tc->kind ();
475 if (kind != CORBA::tk_string)
477 throw DynamicAny::DynAny::TypeMismatch ();
480 char *retval = 0;
482 CORBA::ULong const bound =
483 unaliased_tc->length ();
485 // We will have caught a type mismatch above, so if this fails,
486 // it must be for some other reason.
487 if ((this->any_ >>= CORBA::Any::to_string (retval, bound)) == 0)
489 throw DynamicAny::DynAny::InvalidValue ();
492 return CORBA::string_dup (retval);
496 CORBA::Object_ptr
497 TAO_DynCommon::get_reference ()
499 if (this->destroyed_)
501 throw ::CORBA::OBJECT_NOT_EXIST ();
504 if (this->has_components_)
506 DynamicAny::DynAny_var cc =
507 this->check_component ();
509 return cc->get_reference ();
511 else
513 CORBA::Object_var retval;
515 if ((this->any_ >>= CORBA::Any::to_object (retval.inout ())) == 0)
517 throw DynamicAny::DynAny::TypeMismatch ();
520 return retval._retn ();
524 CORBA::TypeCode_ptr
525 TAO_DynCommon::get_typecode ()
527 if (this->destroyed_)
529 throw ::CORBA::OBJECT_NOT_EXIST ();
532 if (this->has_components_)
534 DynamicAny::DynAny_var cc = this->check_component ();
536 return cc->get_typecode ();
538 else
540 CORBA::TypeCode_ptr retval;
542 if ((this->any_ >>= retval) == 0)
544 throw DynamicAny::DynAny::TypeMismatch ();
547 return CORBA::TypeCode::_duplicate (retval);
551 CORBA::LongLong
552 TAO_DynCommon::get_longlong ()
554 return TAO::DynAnyBasicTypeUtils<CORBA::LongLong>::get_value (this);
557 CORBA::ULongLong
558 TAO_DynCommon::get_ulonglong ()
560 return TAO::DynAnyBasicTypeUtils<CORBA::ULongLong>::get_value (this);
563 CORBA::LongDouble
564 TAO_DynCommon::get_longdouble ()
566 return TAO::DynAnyBasicTypeUtils<CORBA::LongDouble>::get_value (this);
569 CORBA::WChar
570 TAO_DynCommon::get_wchar ()
572 if (this->destroyed_)
574 throw ::CORBA::OBJECT_NOT_EXIST ();
577 if (this->has_components_)
579 DynamicAny::DynAny_var cc = this->check_component ();
581 return cc->get_wchar ();
583 else
585 CORBA::WChar retval;
587 if ((this->any_ >>= CORBA::Any::to_wchar (retval)) == 0)
589 throw DynamicAny::DynAny::TypeMismatch ();
592 return retval;
596 CORBA::WChar *
597 TAO_DynCommon::get_wstring ()
599 if (this->destroyed_)
601 throw ::CORBA::OBJECT_NOT_EXIST ();
604 if (this->has_components_)
606 DynamicAny::DynAny_var cc =
607 this->check_component ();
609 return cc->get_wstring ();
611 else
613 // @@@ (JP) Someday try to find a way to avoid checking for
614 // type code equivalence twice without risking a throw of
615 // BadKind.
616 CORBA::TypeCode_var unaliased_tc =
617 this->check_type_and_unalias (CORBA::_tc_wstring);
619 CORBA::WChar *retval = 0;
621 CORBA::ULong bound =
622 unaliased_tc->length ();
624 (void) (this->any_ >>= CORBA::Any::to_wstring (retval, bound));
626 return CORBA::wstring_dup (retval);
630 CORBA::Any_ptr
631 TAO_DynCommon::get_any ()
633 if (this->destroyed_)
635 throw ::CORBA::OBJECT_NOT_EXIST ();
638 if (this->has_components_)
640 DynamicAny::DynAny_var cc =
641 this->check_component ();
643 return cc->get_any ();
645 else
647 const CORBA::Any *tmp = 0;
649 if ((this->any_ >>= tmp) == 0)
651 throw DynamicAny::DynAny::TypeMismatch ();
654 CORBA::Any *retval = 0;
655 ACE_NEW_RETURN (retval,
656 CORBA::Any (*tmp),
658 return retval;
662 // @@@ (JP) TODO - optimize - this version was intended by the OMG to
663 // have fewer Any/DynAny conversions than get_any, not more.
664 DynamicAny::DynAny_ptr
665 TAO_DynCommon::get_dyn_any ()
667 if (this->destroyed_)
669 throw ::CORBA::OBJECT_NOT_EXIST ();
672 CORBA::Any_var any = this->get_any ();
674 return
675 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
676 any.in ()._tao_get_typecode (),
677 any.in (),
678 this->allow_truncation_ );
681 CORBA::ValueBase *
682 TAO_DynCommon::get_val ()
684 if (this->destroyed_)
686 throw ::CORBA::OBJECT_NOT_EXIST ();
689 if (this->has_components_)
691 DynamicAny::DynAny_var cc =
692 this->check_component (true);
694 return cc->get_val ();
696 else
698 CORBA::TCKind kind =
699 TAO_DynAnyFactory::unalias (this->type_.in ());
701 if (kind != CORBA::tk_value)
703 throw DynamicAny::DynAny::TypeMismatch ();
706 CORBA::ValueBase_var retval;
707 TAO::Any_Impl *any_impl = this->any_.impl ();
709 if (any_impl == 0)
711 throw DynamicAny::DynAny::InvalidValue ();
714 // This should always be non-zero for dynamic anys.
715 TAO::Unknown_IDL_Type *unk =
716 dynamic_cast<TAO::Unknown_IDL_Type *> (any_impl);
718 // Demarshal from a copy so we can retain ownership of our contents.
719 TAO_InputCDR for_reading (unk->_tao_get_cdr ());
721 CORBA::Boolean good_extract =
722 CORBA::ValueBase::_tao_unmarshal (for_reading,
723 retval.inout ());
725 if (!good_extract)
727 throw DynamicAny::DynAny::InvalidValue ();
730 return retval._retn ();
734 // ****************************************************************
736 CORBA::Boolean
737 TAO_DynCommon::seek (CORBA::Long slot)
739 if (this->destroyed_)
741 throw ::CORBA::OBJECT_NOT_EXIST ();
744 if (this->has_components_ == 0)
746 ACE_UNUSED_ARG (slot);
747 this->current_position_ = -1;
748 return false;
750 else if (slot < 0 || slot >= static_cast<CORBA::Long> (this->component_count_))
752 this->current_position_ = -1;
753 return false;
755 else
757 this->current_position_ = slot;
758 return true;
762 void
763 TAO_DynCommon::rewind ()
765 if (this->destroyed_)
767 throw ::CORBA::OBJECT_NOT_EXIST ();
770 (void) this->seek (0);
773 CORBA::Boolean
774 TAO_DynCommon::next ()
776 if (this->destroyed_)
778 throw ::CORBA::OBJECT_NOT_EXIST ();
781 CORBA::Long component_count = static_cast<CORBA::Long> (this->component_count_);
783 if (this->has_components_ == 0
784 || this->current_position_ + 1 >= component_count)
786 this->current_position_ = -1;
787 return false;
789 else
791 ++this->current_position_;
792 return true;
796 DynamicAny::DynAny_ptr
797 TAO_DynCommon::copy ()
799 if (this->destroyed_)
801 throw ::CORBA::OBJECT_NOT_EXIST ();
804 CORBA::Any_var any = this->to_any ();
806 DynamicAny::DynAny_ptr retval =
807 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
808 any.in ()._tao_get_typecode (),
809 any.in (),
810 this->allow_truncation_ );
812 return retval;
815 CORBA::ULong
816 TAO_DynCommon::component_count ()
818 if (this->destroyed_)
820 throw ::CORBA::OBJECT_NOT_EXIST ();
823 return this->component_count_;
826 // ****************************************************************
828 void
829 TAO_DynCommon::insert_abstract (CORBA::AbstractBase_ptr value)
831 if (this->destroyed_)
833 throw ::CORBA::OBJECT_NOT_EXIST ();
836 if (this->has_components_)
838 DynamicAny::DynAny_var cc =
839 this->check_component ();
841 cc->insert_abstract (value);
843 else
845 CORBA::Boolean good_type = true;
846 CORBA::TCKind kind =
847 TAO_DynAnyFactory::unalias (this->type_.in ());
849 if (kind != CORBA::tk_abstract_interface)
851 good_type = false;
853 else if (!CORBA::is_nil (value))
855 const char *value_id = value->_interface_repository_id ();
856 int cmp =
857 ACE_OS::strcmp (value_id, "IDL:omg.org/CORBA/AbstractBase:1.0");
859 if (cmp != 0)
861 const char *my_id =
862 this->type_->id ();
864 if (ACE_OS::strcmp (value_id, my_id) != 0)
866 // If 'value' is an objref, this will be a virtual
867 // call. If not, it will just compare to the repo id
868 // above, which we already know won't match. We see
869 // in insert_val() (see comment there) that there
870 // is no way to check for derived valuetypes w/o
871 // type knowledge at compile time.
872 good_type = value->_is_a (my_id);
877 if (good_type)
879 TAO_OutputCDR out;
881 // The CDR insertion operator for AbstractBase handles
882 // all cases - nil, objref and valuetype - polymorphically.
883 if (!(out << value))
885 throw DynamicAny::DynAny::InvalidValue ();
888 TAO_InputCDR in (out);
889 TAO::Unknown_IDL_Type *unk = 0;
890 ACE_NEW (unk,
891 TAO::Unknown_IDL_Type (this->type_.in (), in));
892 this->any_.replace (unk);
894 else
896 throw DynamicAny::DynAny::TypeMismatch ();
901 CORBA::AbstractBase_ptr
902 TAO_DynCommon::get_abstract ()
904 if (this->destroyed_)
906 throw ::CORBA::OBJECT_NOT_EXIST ();
909 if (this->has_components_)
911 DynamicAny::DynAny_var cc =
912 this->check_component ();
914 return cc->get_abstract ();
916 else
918 CORBA::TCKind kind =
919 TAO_DynAnyFactory::unalias (this->type_.in ());
921 if (kind != CORBA::tk_abstract_interface)
923 throw DynamicAny::DynAny::TypeMismatch ();
926 CORBA::AbstractBase_var retval;
927 TAO::Any_Impl *any_impl = this->any_.impl ();
929 if (any_impl == 0)
931 throw DynamicAny::DynAny::InvalidValue ();
934 // This should always be non-zero for dynamic anys.
935 TAO::Unknown_IDL_Type *unk =
936 dynamic_cast<TAO::Unknown_IDL_Type *> (any_impl);
938 // Make a copy to extract from so we retain ownership of contents.
939 TAO_InputCDR for_reading (unk->_tao_get_cdr ());
941 // The CDR extraction operator for AbstractBase handles
942 // all cases.
943 if (!(for_reading >> retval.inout ()))
945 throw DynamicAny::DynAny::InvalidValue ();
948 return retval._retn ();
952 // ****************************************************************
954 void
955 TAO_DynCommon::insert_boolean_seq (const CORBA::BooleanSeq &value)
957 TAO::DynAnyBasicTypeUtils<CORBA::BooleanSeq>::insert_value (value, this);
960 void
961 TAO_DynCommon::insert_octet_seq (const CORBA::OctetSeq &value)
963 TAO::DynAnyBasicTypeUtils<CORBA::OctetSeq>::insert_value (value, this);
966 void
967 TAO_DynCommon::insert_char_seq (const CORBA::CharSeq &value)
969 TAO::DynAnyBasicTypeUtils<CORBA::CharSeq>::insert_value (value, this);
972 void
973 TAO_DynCommon::insert_short_seq (const CORBA::ShortSeq &value)
975 TAO::DynAnyBasicTypeUtils<CORBA::ShortSeq>::insert_value (value, this);
978 void
979 TAO_DynCommon::insert_ushort_seq (const CORBA::UShortSeq &value)
981 TAO::DynAnyBasicTypeUtils<CORBA::UShortSeq>::insert_value (value, this);
984 void
985 TAO_DynCommon::insert_long_seq (const CORBA::LongSeq &value)
987 TAO::DynAnyBasicTypeUtils<CORBA::LongSeq>::insert_value (value, this);
990 void
991 TAO_DynCommon::insert_ulong_seq (const CORBA::ULongSeq &value)
993 TAO::DynAnyBasicTypeUtils<CORBA::ULongSeq>::insert_value (value, this);
996 void
997 TAO_DynCommon::insert_float_seq (const CORBA::FloatSeq &value)
999 TAO::DynAnyBasicTypeUtils<CORBA::FloatSeq>::insert_value (value, this);
1002 void
1003 TAO_DynCommon::insert_double_seq (const CORBA::DoubleSeq &value)
1005 TAO::DynAnyBasicTypeUtils<CORBA::DoubleSeq>::insert_value (value, this);
1008 void
1009 TAO_DynCommon::insert_longlong_seq (const CORBA::LongLongSeq &value)
1011 TAO::DynAnyBasicTypeUtils<CORBA::LongLongSeq>::insert_value (value, this);
1014 void
1015 TAO_DynCommon::insert_ulonglong_seq (const CORBA::ULongLongSeq &value)
1017 TAO::DynAnyBasicTypeUtils<CORBA::ULongLongSeq>::insert_value (value, this);
1020 void
1021 TAO_DynCommon::insert_longdouble_seq (const CORBA::LongDoubleSeq &value)
1023 TAO::DynAnyBasicTypeUtils<CORBA::LongDoubleSeq>::insert_value (value, this);
1026 void
1027 TAO_DynCommon::insert_wchar_seq (const CORBA::WCharSeq &value)
1029 TAO::DynAnyBasicTypeUtils<CORBA::WCharSeq>::insert_value (value, this);
1032 // ****************************************************************
1034 CORBA::BooleanSeq *
1035 TAO_DynCommon::get_boolean_seq ()
1037 const CORBA::BooleanSeq *owned =
1038 TAO::DynAnyBasicTypeUtils<CORBA::BooleanSeq>::get_value (this);
1039 return new CORBA::BooleanSeq (*owned);
1042 CORBA::OctetSeq *
1043 TAO_DynCommon::get_octet_seq ()
1045 const CORBA::OctetSeq *owned =
1046 TAO::DynAnyBasicTypeUtils<CORBA::OctetSeq>::get_value (this);
1047 return new CORBA::OctetSeq (*owned);
1050 CORBA::CharSeq *
1051 TAO_DynCommon::get_char_seq ()
1053 const CORBA::CharSeq *owned =
1054 TAO::DynAnyBasicTypeUtils<CORBA::CharSeq>::get_value (this);
1055 return new CORBA::CharSeq (*owned);
1058 CORBA::ShortSeq *
1059 TAO_DynCommon::get_short_seq ()
1061 const CORBA::ShortSeq *owned =
1062 TAO::DynAnyBasicTypeUtils<CORBA::ShortSeq>::get_value (this);
1063 return new CORBA::ShortSeq (*owned);
1066 CORBA::UShortSeq *
1067 TAO_DynCommon::get_ushort_seq ()
1069 const CORBA::UShortSeq *owned =
1070 TAO::DynAnyBasicTypeUtils<CORBA::UShortSeq>::get_value (this);
1071 return new CORBA::UShortSeq (*owned);
1074 CORBA::LongSeq *
1075 TAO_DynCommon::get_long_seq ()
1077 const CORBA::LongSeq *owned =
1078 TAO::DynAnyBasicTypeUtils<CORBA::LongSeq>::get_value (this);
1079 return new CORBA::LongSeq (*owned);
1082 CORBA::ULongSeq *
1083 TAO_DynCommon::get_ulong_seq ()
1085 const CORBA::ULongSeq *owned =
1086 TAO::DynAnyBasicTypeUtils<CORBA::ULongSeq>::get_value (this);
1087 return new CORBA::ULongSeq (*owned);
1090 CORBA::FloatSeq *
1091 TAO_DynCommon::get_float_seq ()
1093 const CORBA::FloatSeq *owned =
1094 TAO::DynAnyBasicTypeUtils<CORBA::FloatSeq>::get_value (this);
1095 return new CORBA::FloatSeq (*owned);
1098 CORBA::DoubleSeq *
1099 TAO_DynCommon::get_double_seq ()
1101 const CORBA::DoubleSeq *owned =
1102 TAO::DynAnyBasicTypeUtils<CORBA::DoubleSeq>::get_value (this);
1103 return new CORBA::DoubleSeq (*owned);
1106 CORBA::LongLongSeq *
1107 TAO_DynCommon::get_longlong_seq ()
1109 const CORBA::LongLongSeq *owned =
1110 TAO::DynAnyBasicTypeUtils<CORBA::LongLongSeq>::get_value (this);
1111 return new CORBA::LongLongSeq (*owned);
1114 CORBA::ULongLongSeq *
1115 TAO_DynCommon::get_ulonglong_seq ()
1117 const CORBA::ULongLongSeq *owned =
1118 TAO::DynAnyBasicTypeUtils<CORBA::ULongLongSeq>::get_value (this);
1119 return new CORBA::ULongLongSeq (*owned);
1122 CORBA::LongDoubleSeq *
1123 TAO_DynCommon::get_longdouble_seq ()
1125 const CORBA::LongDoubleSeq *owned =
1126 TAO::DynAnyBasicTypeUtils<CORBA::LongDoubleSeq>::get_value (this);
1127 return new CORBA::LongDoubleSeq (*owned);
1130 CORBA::WCharSeq *
1131 TAO_DynCommon::get_wchar_seq ()
1133 const CORBA::WCharSeq *owned =
1134 TAO::DynAnyBasicTypeUtils<CORBA::WCharSeq>::get_value (this);
1135 return new CORBA::WCharSeq (*owned);
1138 // ****************************************************************
1140 void
1141 TAO_DynCommon::set_flag (DynamicAny::DynAny_ptr component,
1142 CORBA::Boolean destroying)
1144 CORBA::TypeCode_var tc = component->type ();
1146 CORBA::TCKind tk = TAO_DynAnyFactory::unalias (tc.in ());
1148 switch (tk)
1150 case CORBA::tk_array:
1151 TAO::DynAnyFlagUtils<TAO_DynArray_i>::set_flag_t (component,
1152 destroying);
1153 break;
1154 case CORBA::tk_enum:
1155 TAO::DynAnyFlagUtils<TAO_DynEnum_i>::set_flag_t (component,
1156 destroying);
1157 break;
1158 case CORBA::tk_sequence:
1159 if (TAO_DynCommon::is_basic_type_seq (tc.in ()))
1161 TAO::DynAnyFlagUtils<TAO_DynAny_i>::set_flag_t (component,
1162 destroying);
1164 else
1166 TAO::DynAnyFlagUtils<TAO_DynSequence_i>::set_flag_t (component,
1167 destroying);
1169 break;
1170 case CORBA::tk_struct:
1171 TAO::DynAnyFlagUtils<TAO_DynStruct_i>::set_flag_t (component,
1172 destroying);
1173 break;
1174 case CORBA::tk_union:
1175 TAO::DynAnyFlagUtils<TAO_DynUnion_i>::set_flag_t (component,
1176 destroying);
1177 break;
1178 case CORBA::tk_value:
1179 TAO::DynAnyFlagUtils<TAO_DynValue_i>::set_flag_t (component,
1180 destroying);
1181 break;
1182 case CORBA::tk_value_box:
1183 TAO::DynAnyFlagUtils<TAO_DynValueBox_i>::set_flag_t (component,
1184 destroying);
1185 break;
1186 case CORBA::tk_fixed:
1187 throw ::CORBA::NO_IMPLEMENT ();
1188 default:
1189 TAO::DynAnyFlagUtils<TAO_DynAny_i>::set_flag_t (component,
1190 destroying);
1191 break;
1195 DynamicAny::DynAny_ptr
1196 TAO_DynCommon::check_component (CORBA::Boolean isValueType)
1198 if (this->current_position_ == -1)
1200 throw DynamicAny::DynAny::InvalidValue ();
1203 DynamicAny::DynAny_var cc =
1204 this->current_component ();
1206 CORBA::TypeCode_var tc = cc->type ();
1208 // We are here because we are a component that is the target of
1209 // an insert_*() call on our container. It is
1210 // illegal to insert anything into a component that itself has
1211 // components.
1212 switch (TAO_DynAnyFactory::unalias (tc.in ()))
1214 case CORBA::tk_array:
1215 case CORBA::tk_except:
1216 case CORBA::tk_struct:
1217 case CORBA::tk_union:
1218 throw DynamicAny::DynAny::TypeMismatch ();
1220 case CORBA::tk_value:
1221 if (!isValueType)
1223 throw DynamicAny::DynAny::TypeMismatch ();
1225 break;
1227 case CORBA::tk_sequence:
1228 if (!TAO_DynCommon::is_basic_type_seq (tc.in ()))
1230 throw DynamicAny::DynAny::TypeMismatch ();
1232 break;
1234 default:
1235 break;
1238 return cc._retn ();
1241 void
1242 TAO_DynCommon::check_type (CORBA::TypeCode_ptr tc)
1244 CORBA::Boolean const equivalent =
1245 this->type_->equivalent (tc);
1247 if (!equivalent)
1249 throw DynamicAny::DynAny::TypeMismatch ();
1253 bool
1254 TAO_DynCommon::is_basic_type_seq (CORBA::TypeCode_ptr tc)
1256 return (tc->equal (CORBA::_tc_BooleanSeq)
1257 || tc->equal (CORBA::_tc_OctetSeq)
1258 || tc->equal (CORBA::_tc_CharSeq)
1259 || tc->equal (CORBA::_tc_WCharSeq)
1260 || tc->equal (CORBA::_tc_ShortSeq)
1261 || tc->equal (CORBA::_tc_UShortSeq)
1262 || tc->equal (CORBA::_tc_LongSeq)
1263 || tc->equal (CORBA::_tc_ULongSeq)
1264 || tc->equal (CORBA::_tc_LongLongSeq)
1265 || tc->equal (CORBA::_tc_ULongLongSeq)
1266 || tc->equal (CORBA::_tc_FloatSeq)
1267 || tc->equal (CORBA::_tc_DoubleSeq)
1268 || tc->equal (CORBA::_tc_LongDoubleSeq));
1271 CORBA::Boolean
1272 TAO_DynCommon::has_components () const
1274 return this->has_components_;
1277 CORBA::Boolean
1278 TAO_DynCommon::destroyed () const
1280 return this->destroyed_;
1283 CORBA::Any &
1284 TAO_DynCommon::the_any ()
1286 return this->any_;
1289 void
1290 TAO_DynCommon::container_is_destroying (CORBA::Boolean val)
1292 this->container_is_destroying_ = val;
1295 void
1296 TAO_DynCommon::ref_to_component (CORBA::Boolean val)
1298 this->ref_to_component_ = val;
1301 CORBA::TypeCode_ptr
1302 TAO_DynCommon::check_type_and_unalias (CORBA::TypeCode_ptr tc)
1304 this->check_type (tc);
1306 return TAO_DynAnyFactory::strip_alias (tc);
1309 TAO_END_VERSIONED_NAMESPACE_DECL