Layout changes
[ACE_TAO.git] / TAO / tao / DynamicAny / DynCommon.cpp
blob530d84b842636946f44cec2ff3cb67dd8dbcd0cb
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"
24 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
26 TAO_DynCommon::TAO_DynCommon (CORBA::Boolean allow_truncation)
27 : ref_to_component_ (false)
28 , container_is_destroying_ (false)
29 , has_components_ (false)
30 , destroyed_ (false)
31 , current_position_ (-1)
32 , component_count_ (0)
33 , allow_truncation_ (allow_truncation)
37 TAO_DynCommon::~TAO_DynCommon (void)
41 CORBA::TypeCode_ptr
42 TAO_DynCommon::type (void)
44 if (this->destroyed_)
46 throw ::CORBA::OBJECT_NOT_EXIST ();
49 return CORBA::TypeCode::_duplicate (this->type_.in ());
52 void
53 TAO_DynCommon::assign (DynamicAny::DynAny_ptr dyn_any)
55 if (this->destroyed_)
57 throw ::CORBA::OBJECT_NOT_EXIST ();
60 CORBA::TypeCode_var tc = dyn_any->type ();
62 CORBA::Boolean const equivalent = this->type_.in ()->equivalent (tc.in ());
64 if (equivalent)
66 CORBA::Any_var any = dyn_any->to_any ();
68 this->from_any (any.in ());
70 else
72 throw DynamicAny::DynAny::TypeMismatch ();
76 void
77 TAO_DynCommon::insert_boolean (CORBA::Boolean value)
79 TAO::DynAnyBasicTypeUtils<CORBA::Boolean>::insert_value (value, this);
82 void
83 TAO_DynCommon::insert_octet (CORBA::Octet value)
85 TAO::DynAnyBasicTypeUtils<CORBA::Octet>::insert_value (value, this);
88 void
89 TAO_DynCommon::insert_char (CORBA::Char value)
91 TAO::DynAnyBasicTypeUtils<CORBA::Char>::insert_value (value, this);
94 void
95 TAO_DynCommon::insert_short (CORBA::Short value)
97 TAO::DynAnyBasicTypeUtils<CORBA::Short>::insert_value (value, this);
100 void
101 TAO_DynCommon::insert_ushort (CORBA::UShort value)
103 TAO::DynAnyBasicTypeUtils<CORBA::UShort>::insert_value (value, this);
106 void
107 TAO_DynCommon::insert_long (CORBA::Long value)
109 TAO::DynAnyBasicTypeUtils<CORBA::Long>::insert_value (value, this);
112 void
113 TAO_DynCommon::insert_ulong (CORBA::ULong value)
115 TAO::DynAnyBasicTypeUtils<CORBA::ULong>::insert_value (value, this);
118 void
119 TAO_DynCommon::insert_float (CORBA::Float value)
121 TAO::DynAnyBasicTypeUtils<CORBA::Float>::insert_value (value, this);
124 void
125 TAO_DynCommon::insert_double (CORBA::Double value)
127 TAO::DynAnyBasicTypeUtils<CORBA::Double>::insert_value (value, this);
130 void
131 TAO_DynCommon::insert_string (const char * value)
133 if (this->destroyed_)
135 throw ::CORBA::OBJECT_NOT_EXIST ();
138 if (this->has_components_)
140 DynamicAny::DynAny_var cc =
141 this->check_component ();
143 cc->insert_string (value);
145 else
147 CORBA::TypeCode_var unaliased_tc =
148 TAO_DynAnyFactory::strip_alias (this->type_.in ());
150 CORBA::TCKind const kind =
151 unaliased_tc->kind ();
153 if (kind != CORBA::tk_string)
155 throw DynamicAny::DynAny::TypeMismatch ();
158 CORBA::ULong const bound =
159 unaliased_tc->length ();
161 if (bound > 0 && bound < ACE_OS::strlen (value))
163 throw DynamicAny::DynAny::InvalidValue ();
166 this->any_ <<= CORBA::Any::from_string (const_cast<char *> (value),
167 bound);
171 void
172 TAO_DynCommon::insert_reference (CORBA::Object_ptr value)
174 if (this->destroyed_)
176 throw ::CORBA::OBJECT_NOT_EXIST ();
179 if (this->has_components_)
181 DynamicAny::DynAny_var cc =
182 this->check_component ();
184 cc->insert_reference (value);
186 else
188 CORBA::Boolean good_type = true;
189 CORBA::TCKind const kind =
190 TAO_DynAnyFactory::unalias (this->type_.in ());
192 if (kind != CORBA::tk_objref)
194 good_type = false;
196 else if (!CORBA::is_nil (value))
198 const char *value_id = value->_interface_repository_id ();
200 if (ACE_OS::strcmp (value_id, "IDL:omg.org/CORBA/Object:1.0") != 0)
202 const char *my_id =
203 this->type_->id ();
205 if (ACE_OS::strcmp (value_id, my_id) != 0)
207 good_type = value->_is_a (my_id);
212 if (good_type)
214 TAO_OutputCDR cdr;
216 if (CORBA::is_nil (value))
218 // Empty type hint, no profile.
219 cdr.write_ulong (1);
220 cdr.write_char ('\0');
221 cdr.write_ulong (0);
223 else
225 if (!value->marshal (cdr))
227 throw DynamicAny::DynAny::InvalidValue ();
231 TAO_InputCDR in (cdr);
232 TAO::Unknown_IDL_Type *unk = 0;
233 ACE_NEW (unk,
234 TAO::Unknown_IDL_Type (this->type_.in (),
235 in));
236 this->any_.replace (unk);
238 else
240 throw DynamicAny::DynAny::TypeMismatch ();
245 void
246 TAO_DynCommon::insert_typecode (CORBA::TypeCode_ptr value)
248 TAO::DynAnyBasicTypeUtils<CORBA::TypeCode_ptr>::insert_value (value, this);
251 void
252 TAO_DynCommon::insert_longlong (CORBA::LongLong value)
254 TAO::DynAnyBasicTypeUtils<CORBA::LongLong>::insert_value (value, this);
257 void
258 TAO_DynCommon::insert_ulonglong (CORBA::ULongLong value)
260 TAO::DynAnyBasicTypeUtils<CORBA::ULongLong>::insert_value (value, this);
263 void
264 TAO_DynCommon::insert_longdouble (CORBA::LongDouble value)
266 TAO::DynAnyBasicTypeUtils<CORBA::LongDouble>::insert_value (value,
267 this);
270 void
271 TAO_DynCommon::insert_wchar (CORBA::WChar value)
273 TAO::DynAnyBasicTypeUtils<CORBA::WChar>::insert_value (value,
274 this);
277 void
278 TAO_DynCommon::insert_wstring (const CORBA::WChar * value)
280 if (this->destroyed_)
282 throw ::CORBA::OBJECT_NOT_EXIST ();
285 if (this->has_components_)
287 DynamicAny::DynAny_var cc =
288 this->check_component ();
290 cc->insert_wstring (value);
292 else
294 CORBA::TypeCode_var unaliased_tc =
295 this->check_type_and_unalias (CORBA::_tc_wstring);
297 CORBA::ULong const bound = unaliased_tc->length ();
299 if (bound > 0 && bound < ACE_OS::wslen (value))
301 throw DynamicAny::DynAny::InvalidValue ();
304 this->any_ <<= CORBA::Any::from_wstring (const_cast<CORBA::WChar *> (value),
305 bound);
309 void
310 TAO_DynCommon::insert_any (const CORBA::Any &value)
312 TAO::DynAnyBasicTypeUtils<CORBA::Any>::insert_value (value,
313 this);
316 // @@@ (JP) TODO - optimize - this version was intended by the OMG to
317 // have fewer Any/DynAny conversions than insert_any, not more.
318 void
319 TAO_DynCommon::insert_dyn_any (DynamicAny::DynAny_ptr value)
321 if (this->destroyed_)
323 throw ::CORBA::OBJECT_NOT_EXIST ();
326 CORBA::Any_var any = value->to_any ();
328 this->insert_any (any.in ());
331 void
332 TAO_DynCommon::insert_val (CORBA::ValueBase *value)
334 if (this->destroyed_)
336 throw ::CORBA::OBJECT_NOT_EXIST ();
339 if (this->has_components_)
341 DynamicAny::DynAny_var cc =
342 this->check_component (true);
344 cc->insert_val (value);
346 else
348 CORBA::TCKind kind =
349 TAO_DynAnyFactory::unalias (this->type_.in ());
351 if (kind != CORBA::tk_value)
353 throw DynamicAny::DynAny::TypeMismatch ();
356 // If the arg is 0 we can't do this kind of type checking,
357 // and the call to _tao_marshal() below will handle the
358 // null value correctly.
359 if (value != 0)
361 const char *value_id = value->_tao_obv_repository_id ();
362 const char *my_id =
363 this->type_->id ();
365 // Valuetypes, unlike interfaces, don't have a virtual
366 // method to check for a more derived type when the
367 // repo ids don't match. Valuetypes have only
368 // a static _downcast() method, which can't be used
369 // here, so if the repo ids don't match, we're hosed.
370 if (ACE_OS::strcmp (value_id, my_id) != 0)
372 throw DynamicAny::DynAny::TypeMismatch ();
376 // This will handle null values correctly, or otherwise
377 // make a virtual call to marshal the state.
378 TAO_OutputCDR out;
379 CORBA::Boolean const good_insert =
380 CORBA::ValueBase::_tao_marshal (out, value);
382 if (!good_insert)
384 throw DynamicAny::DynAny::InvalidValue ();
387 TAO_InputCDR in (out);
388 TAO::Unknown_IDL_Type *unk = 0;
389 ACE_NEW (unk,
390 TAO::Unknown_IDL_Type (this->type_.in (), in));
391 this->any_.replace (unk);
395 // ****************************************************************
397 CORBA::Boolean
398 TAO_DynCommon::get_boolean (void)
400 return TAO::DynAnyBasicTypeUtils<CORBA::Boolean>::get_value (this);
403 CORBA::Octet
404 TAO_DynCommon::get_octet (void)
406 return TAO::DynAnyBasicTypeUtils<CORBA::Octet>::get_value (this);
409 CORBA::Char
410 TAO_DynCommon::get_char (void)
412 return TAO::DynAnyBasicTypeUtils<CORBA::Char>::get_value (this);
415 CORBA::Short
416 TAO_DynCommon::get_short (void)
418 return TAO::DynAnyBasicTypeUtils<CORBA::Short>::get_value (this);
421 CORBA::UShort
422 TAO_DynCommon::get_ushort (void)
424 return TAO::DynAnyBasicTypeUtils<CORBA::UShort>::get_value (this);
427 CORBA::Long
428 TAO_DynCommon::get_long (void)
430 return TAO::DynAnyBasicTypeUtils<CORBA::Long>::get_value (this);
433 CORBA::ULong
434 TAO_DynCommon::get_ulong (void)
436 return TAO::DynAnyBasicTypeUtils<CORBA::ULong>::get_value (this);
439 CORBA::Float
440 TAO_DynCommon::get_float (void)
442 return TAO::DynAnyBasicTypeUtils<CORBA::Float>::get_value (this);
445 CORBA::Double
446 TAO_DynCommon::get_double (void)
448 return TAO::DynAnyBasicTypeUtils<CORBA::Double>::get_value (this);
451 char *
452 TAO_DynCommon::get_string (void)
454 if (this->destroyed_)
456 throw ::CORBA::OBJECT_NOT_EXIST ();
459 if (this->has_components_)
461 DynamicAny::DynAny_var cc =
462 this->check_component ();
464 return cc->get_string ();
466 else
468 CORBA::TypeCode_var unaliased_tc =
469 TAO_DynAnyFactory::strip_alias (this->type_.in ());
471 CORBA::TCKind kind =
472 unaliased_tc->kind ();
474 if (kind != CORBA::tk_string)
476 throw DynamicAny::DynAny::TypeMismatch ();
479 char *retval = 0;
481 CORBA::ULong const bound =
482 unaliased_tc->length ();
484 // We will have caught a type mismatch above, so if this fails,
485 // it must be for some other reason.
486 if ((this->any_ >>= CORBA::Any::to_string (retval, bound)) == 0)
488 throw DynamicAny::DynAny::InvalidValue ();
491 return CORBA::string_dup (retval);
495 CORBA::Object_ptr
496 TAO_DynCommon::get_reference (void)
498 if (this->destroyed_)
500 throw ::CORBA::OBJECT_NOT_EXIST ();
503 if (this->has_components_)
505 DynamicAny::DynAny_var cc =
506 this->check_component ();
508 return cc->get_reference ();
510 else
512 CORBA::Object_var retval;
514 if ((this->any_ >>= CORBA::Any::to_object (retval.inout ())) == 0)
516 throw DynamicAny::DynAny::TypeMismatch ();
519 return retval._retn ();
523 CORBA::TypeCode_ptr
524 TAO_DynCommon::get_typecode (void)
526 if (this->destroyed_)
528 throw ::CORBA::OBJECT_NOT_EXIST ();
531 if (this->has_components_)
533 DynamicAny::DynAny_var cc = this->check_component ();
535 return cc->get_typecode ();
537 else
539 CORBA::TypeCode_ptr retval;
541 if ((this->any_ >>= retval) == 0)
543 throw DynamicAny::DynAny::TypeMismatch ();
546 return CORBA::TypeCode::_duplicate (retval);
550 CORBA::LongLong
551 TAO_DynCommon::get_longlong (void)
553 return TAO::DynAnyBasicTypeUtils<CORBA::LongLong>::get_value (this);
556 CORBA::ULongLong
557 TAO_DynCommon::get_ulonglong (void)
559 return TAO::DynAnyBasicTypeUtils<CORBA::ULongLong>::get_value (this);
562 CORBA::LongDouble
563 TAO_DynCommon::get_longdouble (void)
565 return TAO::DynAnyBasicTypeUtils<CORBA::LongDouble>::get_value (this);
568 CORBA::WChar
569 TAO_DynCommon::get_wchar (void)
571 if (this->destroyed_)
573 throw ::CORBA::OBJECT_NOT_EXIST ();
576 if (this->has_components_)
578 DynamicAny::DynAny_var cc = this->check_component ();
580 return cc->get_wchar ();
582 else
584 CORBA::WChar retval;
586 if ((this->any_ >>= CORBA::Any::to_wchar (retval)) == 0)
588 throw DynamicAny::DynAny::TypeMismatch ();
591 return retval;
595 CORBA::WChar *
596 TAO_DynCommon::get_wstring (void)
598 if (this->destroyed_)
600 throw ::CORBA::OBJECT_NOT_EXIST ();
603 if (this->has_components_)
605 DynamicAny::DynAny_var cc =
606 this->check_component ();
608 return cc->get_wstring ();
610 else
612 // @@@ (JP) Someday try to find a way to avoid checking for
613 // type code equivalence twice without risking a throw of
614 // BadKind.
615 CORBA::TypeCode_var unaliased_tc =
616 this->check_type_and_unalias (CORBA::_tc_wstring);
618 CORBA::WChar *retval = 0;
620 CORBA::ULong bound =
621 unaliased_tc->length ();
623 (void) (this->any_ >>= CORBA::Any::to_wstring (retval, bound));
625 return CORBA::wstring_dup (retval);
629 CORBA::Any_ptr
630 TAO_DynCommon::get_any (void)
632 if (this->destroyed_)
634 throw ::CORBA::OBJECT_NOT_EXIST ();
637 if (this->has_components_)
639 DynamicAny::DynAny_var cc =
640 this->check_component ();
642 return cc->get_any ();
644 else
646 const CORBA::Any *tmp = 0;
648 if ((this->any_ >>= tmp) == 0)
650 throw DynamicAny::DynAny::TypeMismatch ();
653 CORBA::Any *retval = 0;
654 ACE_NEW_RETURN (retval,
655 CORBA::Any (*tmp),
657 return retval;
661 // @@@ (JP) TODO - optimize - this version was intended by the OMG to
662 // have fewer Any/DynAny conversions than get_any, not more.
663 DynamicAny::DynAny_ptr
664 TAO_DynCommon::get_dyn_any (void)
666 if (this->destroyed_)
668 throw ::CORBA::OBJECT_NOT_EXIST ();
671 CORBA::Any_var any = this->get_any ();
673 return
674 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
675 any.in ()._tao_get_typecode (),
676 any.in (),
677 this->allow_truncation_ );
680 CORBA::ValueBase *
681 TAO_DynCommon::get_val (void)
683 if (this->destroyed_)
685 throw ::CORBA::OBJECT_NOT_EXIST ();
688 if (this->has_components_)
690 DynamicAny::DynAny_var cc =
691 this->check_component (true);
693 return cc->get_val ();
695 else
697 CORBA::TCKind kind =
698 TAO_DynAnyFactory::unalias (this->type_.in ());
700 if (kind != CORBA::tk_value)
702 throw DynamicAny::DynAny::TypeMismatch ();
705 CORBA::ValueBase_var retval;
706 TAO::Any_Impl *any_impl = this->any_.impl ();
708 if (any_impl == 0)
710 throw DynamicAny::DynAny::InvalidValue ();
713 // This should always be non-zero for dynamic anys.
714 TAO::Unknown_IDL_Type *unk =
715 dynamic_cast<TAO::Unknown_IDL_Type *> (any_impl);
717 // Demarshal from a copy so we can retain ownership of our contents.
718 TAO_InputCDR for_reading (unk->_tao_get_cdr ());
720 CORBA::Boolean good_extract =
721 CORBA::ValueBase::_tao_unmarshal (for_reading,
722 retval.inout ());
724 if (!good_extract)
726 throw DynamicAny::DynAny::InvalidValue ();
729 return retval._retn ();
733 // ****************************************************************
735 CORBA::Boolean
736 TAO_DynCommon::seek (CORBA::Long slot)
738 if (this->destroyed_)
740 throw ::CORBA::OBJECT_NOT_EXIST ();
743 if (this->has_components_ == 0)
745 ACE_UNUSED_ARG (slot);
746 this->current_position_ = -1;
747 return false;
749 else if (slot < 0 || slot >= static_cast<CORBA::Long> (this->component_count_))
751 this->current_position_ = -1;
752 return false;
754 else
756 this->current_position_ = slot;
757 return true;
761 void
762 TAO_DynCommon::rewind (void)
764 if (this->destroyed_)
766 throw ::CORBA::OBJECT_NOT_EXIST ();
769 (void) this->seek (0);
772 CORBA::Boolean
773 TAO_DynCommon::next (void)
775 if (this->destroyed_)
777 throw ::CORBA::OBJECT_NOT_EXIST ();
780 CORBA::Long component_count = static_cast<CORBA::Long> (this->component_count_);
782 if (this->has_components_ == 0
783 || this->current_position_ + 1 >= component_count)
785 this->current_position_ = -1;
786 return false;
788 else
790 ++this->current_position_;
791 return true;
795 DynamicAny::DynAny_ptr
796 TAO_DynCommon::copy (void)
798 if (this->destroyed_)
800 throw ::CORBA::OBJECT_NOT_EXIST ();
803 CORBA::Any_var any = this->to_any ();
805 DynamicAny::DynAny_ptr retval =
806 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
807 any.in ()._tao_get_typecode (),
808 any.in (),
809 this->allow_truncation_ );
811 return retval;
814 CORBA::ULong
815 TAO_DynCommon::component_count (void)
817 if (this->destroyed_)
819 throw ::CORBA::OBJECT_NOT_EXIST ();
822 return this->component_count_;
825 // ****************************************************************
827 void
828 TAO_DynCommon::insert_abstract (CORBA::AbstractBase_ptr value)
830 if (this->destroyed_)
832 throw ::CORBA::OBJECT_NOT_EXIST ();
835 if (this->has_components_)
837 DynamicAny::DynAny_var cc =
838 this->check_component ();
840 cc->insert_abstract (value);
842 else
844 CORBA::Boolean good_type = true;
845 CORBA::TCKind kind =
846 TAO_DynAnyFactory::unalias (this->type_.in ());
848 if (kind != CORBA::tk_abstract_interface)
850 good_type = false;
852 else if (!CORBA::is_nil (value))
854 const char *value_id = value->_interface_repository_id ();
855 int cmp =
856 ACE_OS::strcmp (value_id, "IDL:omg.org/CORBA/AbstractBase:1.0");
858 if (cmp != 0)
860 const char *my_id =
861 this->type_->id ();
863 if (ACE_OS::strcmp (value_id, my_id) != 0)
865 // If 'value' is an objref, this will be a virtual
866 // call. If not, it will just compare to the repo id
867 // above, which we already know won't match. We see
868 // in insert_val() (see comment there) that there
869 // is no way to check for derived valuetypes w/o
870 // type knowledge at compile time.
871 good_type = value->_is_a (my_id);
876 if (good_type)
878 TAO_OutputCDR out;
880 // The CDR insertion operator for AbstractBase handles
881 // all cases - nil, objref and valuetype - polymorphically.
882 if (!(out << value))
884 throw DynamicAny::DynAny::InvalidValue ();
887 TAO_InputCDR in (out);
888 TAO::Unknown_IDL_Type *unk = 0;
889 ACE_NEW (unk,
890 TAO::Unknown_IDL_Type (this->type_.in (), in));
891 this->any_.replace (unk);
893 else
895 throw DynamicAny::DynAny::TypeMismatch ();
900 CORBA::AbstractBase_ptr
901 TAO_DynCommon::get_abstract (void)
903 if (this->destroyed_)
905 throw ::CORBA::OBJECT_NOT_EXIST ();
908 if (this->has_components_)
910 DynamicAny::DynAny_var cc =
911 this->check_component ();
913 return cc->get_abstract ();
915 else
917 CORBA::TCKind kind =
918 TAO_DynAnyFactory::unalias (this->type_.in ());
920 if (kind != CORBA::tk_abstract_interface)
922 throw DynamicAny::DynAny::TypeMismatch ();
925 CORBA::AbstractBase_var retval;
926 TAO::Any_Impl *any_impl = this->any_.impl ();
928 if (any_impl == 0)
930 throw DynamicAny::DynAny::InvalidValue ();
933 // This should always be non-zero for dynamic anys.
934 TAO::Unknown_IDL_Type *unk =
935 dynamic_cast<TAO::Unknown_IDL_Type *> (any_impl);
937 // Make a copy to extract from so we retain ownership of contents.
938 TAO_InputCDR for_reading (unk->_tao_get_cdr ());
940 // The CDR extraction operator for AbstractBase handles
941 // all cases.
942 if (!(for_reading >> retval.inout ()))
944 throw DynamicAny::DynAny::InvalidValue ();
947 return retval._retn ();
951 // ****************************************************************
953 void
954 TAO_DynCommon::insert_boolean_seq (const CORBA::BooleanSeq &value)
956 TAO::DynAnyBasicTypeUtils<CORBA::BooleanSeq>::insert_value (value, this);
959 void
960 TAO_DynCommon::insert_octet_seq (const CORBA::OctetSeq &value)
962 TAO::DynAnyBasicTypeUtils<CORBA::OctetSeq>::insert_value (value, this);
965 void
966 TAO_DynCommon::insert_char_seq (const CORBA::CharSeq &value)
968 TAO::DynAnyBasicTypeUtils<CORBA::CharSeq>::insert_value (value, this);
971 void
972 TAO_DynCommon::insert_short_seq (const CORBA::ShortSeq &value)
974 TAO::DynAnyBasicTypeUtils<CORBA::ShortSeq>::insert_value (value, this);
977 void
978 TAO_DynCommon::insert_ushort_seq (const CORBA::UShortSeq &value)
980 TAO::DynAnyBasicTypeUtils<CORBA::UShortSeq>::insert_value (value, this);
983 void
984 TAO_DynCommon::insert_long_seq (const CORBA::LongSeq &value)
986 TAO::DynAnyBasicTypeUtils<CORBA::LongSeq>::insert_value (value, this);
989 void
990 TAO_DynCommon::insert_ulong_seq (const CORBA::ULongSeq &value)
992 TAO::DynAnyBasicTypeUtils<CORBA::ULongSeq>::insert_value (value, this);
995 void
996 TAO_DynCommon::insert_float_seq (const CORBA::FloatSeq &value)
998 TAO::DynAnyBasicTypeUtils<CORBA::FloatSeq>::insert_value (value, this);
1001 void
1002 TAO_DynCommon::insert_double_seq (const CORBA::DoubleSeq &value)
1004 TAO::DynAnyBasicTypeUtils<CORBA::DoubleSeq>::insert_value (value, this);
1007 void
1008 TAO_DynCommon::insert_longlong_seq (const CORBA::LongLongSeq &value)
1010 TAO::DynAnyBasicTypeUtils<CORBA::LongLongSeq>::insert_value (value, this);
1013 void
1014 TAO_DynCommon::insert_ulonglong_seq (const CORBA::ULongLongSeq &value)
1016 TAO::DynAnyBasicTypeUtils<CORBA::ULongLongSeq>::insert_value (value, this);
1019 void
1020 TAO_DynCommon::insert_longdouble_seq (const CORBA::LongDoubleSeq &value)
1022 TAO::DynAnyBasicTypeUtils<CORBA::LongDoubleSeq>::insert_value (value, this);
1025 void
1026 TAO_DynCommon::insert_wchar_seq (const CORBA::WCharSeq &value)
1028 TAO::DynAnyBasicTypeUtils<CORBA::WCharSeq>::insert_value (value, this);
1031 // ****************************************************************
1033 CORBA::BooleanSeq *
1034 TAO_DynCommon::get_boolean_seq (void)
1036 const CORBA::BooleanSeq *owned =
1037 TAO::DynAnyBasicTypeUtils<CORBA::BooleanSeq>::get_value (this);
1038 return new CORBA::BooleanSeq (*owned);
1041 CORBA::OctetSeq *
1042 TAO_DynCommon::get_octet_seq (void)
1044 const CORBA::OctetSeq *owned =
1045 TAO::DynAnyBasicTypeUtils<CORBA::OctetSeq>::get_value (this);
1046 return new CORBA::OctetSeq (*owned);
1049 CORBA::CharSeq *
1050 TAO_DynCommon::get_char_seq (void)
1052 const CORBA::CharSeq *owned =
1053 TAO::DynAnyBasicTypeUtils<CORBA::CharSeq>::get_value (this);
1054 return new CORBA::CharSeq (*owned);
1057 CORBA::ShortSeq *
1058 TAO_DynCommon::get_short_seq (void)
1060 const CORBA::ShortSeq *owned =
1061 TAO::DynAnyBasicTypeUtils<CORBA::ShortSeq>::get_value (this);
1062 return new CORBA::ShortSeq (*owned);
1065 CORBA::UShortSeq *
1066 TAO_DynCommon::get_ushort_seq (void)
1068 const CORBA::UShortSeq *owned =
1069 TAO::DynAnyBasicTypeUtils<CORBA::UShortSeq>::get_value (this);
1070 return new CORBA::UShortSeq (*owned);
1073 CORBA::LongSeq *
1074 TAO_DynCommon::get_long_seq (void)
1076 const CORBA::LongSeq *owned =
1077 TAO::DynAnyBasicTypeUtils<CORBA::LongSeq>::get_value (this);
1078 return new CORBA::LongSeq (*owned);
1081 CORBA::ULongSeq *
1082 TAO_DynCommon::get_ulong_seq (void)
1084 const CORBA::ULongSeq *owned =
1085 TAO::DynAnyBasicTypeUtils<CORBA::ULongSeq>::get_value (this);
1086 return new CORBA::ULongSeq (*owned);
1089 CORBA::FloatSeq *
1090 TAO_DynCommon::get_float_seq (void)
1092 const CORBA::FloatSeq *owned =
1093 TAO::DynAnyBasicTypeUtils<CORBA::FloatSeq>::get_value (this);
1094 return new CORBA::FloatSeq (*owned);
1097 CORBA::DoubleSeq *
1098 TAO_DynCommon::get_double_seq (void)
1100 const CORBA::DoubleSeq *owned =
1101 TAO::DynAnyBasicTypeUtils<CORBA::DoubleSeq>::get_value (this);
1102 return new CORBA::DoubleSeq (*owned);
1105 CORBA::LongLongSeq *
1106 TAO_DynCommon::get_longlong_seq (void)
1108 const CORBA::LongLongSeq *owned =
1109 TAO::DynAnyBasicTypeUtils<CORBA::LongLongSeq>::get_value (this);
1110 return new CORBA::LongLongSeq (*owned);
1113 CORBA::ULongLongSeq *
1114 TAO_DynCommon::get_ulonglong_seq (void)
1116 const CORBA::ULongLongSeq *owned =
1117 TAO::DynAnyBasicTypeUtils<CORBA::ULongLongSeq>::get_value (this);
1118 return new CORBA::ULongLongSeq (*owned);
1121 CORBA::LongDoubleSeq *
1122 TAO_DynCommon::get_longdouble_seq (void)
1124 const CORBA::LongDoubleSeq *owned =
1125 TAO::DynAnyBasicTypeUtils<CORBA::LongDoubleSeq>::get_value (this);
1126 return new CORBA::LongDoubleSeq (*owned);
1129 CORBA::WCharSeq *
1130 TAO_DynCommon::get_wchar_seq (void)
1132 const CORBA::WCharSeq *owned =
1133 TAO::DynAnyBasicTypeUtils<CORBA::WCharSeq>::get_value (this);
1134 return new CORBA::WCharSeq (*owned);
1137 // ****************************************************************
1139 void
1140 TAO_DynCommon::set_flag (DynamicAny::DynAny_ptr component,
1141 CORBA::Boolean destroying)
1143 CORBA::TypeCode_var tc = component->type ();
1145 CORBA::TCKind tk = TAO_DynAnyFactory::unalias (tc.in ());
1147 switch (tk)
1149 case CORBA::tk_array:
1150 TAO::DynAnyFlagUtils<TAO_DynArray_i>::set_flag_t (component,
1151 destroying);
1152 break;
1153 case CORBA::tk_enum:
1154 TAO::DynAnyFlagUtils<TAO_DynEnum_i>::set_flag_t (component,
1155 destroying);
1156 break;
1157 case CORBA::tk_sequence:
1158 if (TAO_DynCommon::is_basic_type_seq (tc.in ()))
1160 TAO::DynAnyFlagUtils<TAO_DynAny_i>::set_flag_t (component,
1161 destroying);
1163 else
1165 TAO::DynAnyFlagUtils<TAO_DynSequence_i>::set_flag_t (component,
1166 destroying);
1168 break;
1169 case CORBA::tk_struct:
1170 TAO::DynAnyFlagUtils<TAO_DynStruct_i>::set_flag_t (component,
1171 destroying);
1172 break;
1173 case CORBA::tk_union:
1174 TAO::DynAnyFlagUtils<TAO_DynUnion_i>::set_flag_t (component,
1175 destroying);
1176 break;
1177 case CORBA::tk_value:
1178 TAO::DynAnyFlagUtils<TAO_DynValue_i>::set_flag_t (component,
1179 destroying);
1180 break;
1181 case CORBA::tk_value_box:
1182 TAO::DynAnyFlagUtils<TAO_DynValueBox_i>::set_flag_t (component,
1183 destroying);
1184 break;
1185 case CORBA::tk_fixed:
1186 throw ::CORBA::NO_IMPLEMENT ();
1187 default:
1188 TAO::DynAnyFlagUtils<TAO_DynAny_i>::set_flag_t (component,
1189 destroying);
1190 break;
1194 DynamicAny::DynAny_ptr
1195 TAO_DynCommon::check_component (CORBA::Boolean isValueType)
1197 if (this->current_position_ == -1)
1199 throw DynamicAny::DynAny::InvalidValue ();
1202 DynamicAny::DynAny_var cc =
1203 this->current_component ();
1205 CORBA::TypeCode_var tc = cc->type ();
1207 // We are here because we are a component that is the target of
1208 // an insert_*() call on our container. It is
1209 // illegal to insert anything into a component that itself has
1210 // components.
1211 switch (TAO_DynAnyFactory::unalias (tc.in ()))
1213 case CORBA::tk_array:
1214 case CORBA::tk_except:
1215 case CORBA::tk_struct:
1216 case CORBA::tk_union:
1217 throw DynamicAny::DynAny::TypeMismatch ();
1219 case CORBA::tk_value:
1220 if (!isValueType)
1222 throw DynamicAny::DynAny::TypeMismatch ();
1224 break;
1226 case CORBA::tk_sequence:
1227 if (!TAO_DynCommon::is_basic_type_seq (tc.in ()))
1229 throw DynamicAny::DynAny::TypeMismatch ();
1231 break;
1233 default:
1234 break;
1237 return cc._retn ();
1240 void
1241 TAO_DynCommon::check_type (CORBA::TypeCode_ptr tc)
1243 CORBA::Boolean const equivalent =
1244 this->type_->equivalent (tc);
1246 if (!equivalent)
1248 throw DynamicAny::DynAny::TypeMismatch ();
1252 bool
1253 TAO_DynCommon::is_basic_type_seq (CORBA::TypeCode_ptr tc)
1255 return (tc->equal (CORBA::_tc_BooleanSeq)
1256 || tc->equal (CORBA::_tc_OctetSeq)
1257 || tc->equal (CORBA::_tc_CharSeq)
1258 || tc->equal (CORBA::_tc_WCharSeq)
1259 || tc->equal (CORBA::_tc_ShortSeq)
1260 || tc->equal (CORBA::_tc_UShortSeq)
1261 || tc->equal (CORBA::_tc_LongSeq)
1262 || tc->equal (CORBA::_tc_ULongSeq)
1263 || tc->equal (CORBA::_tc_LongLongSeq)
1264 || tc->equal (CORBA::_tc_ULongLongSeq)
1265 || tc->equal (CORBA::_tc_FloatSeq)
1266 || tc->equal (CORBA::_tc_DoubleSeq)
1267 || tc->equal (CORBA::_tc_LongDoubleSeq));
1270 CORBA::Boolean
1271 TAO_DynCommon::has_components (void) const
1273 return this->has_components_;
1276 CORBA::Boolean
1277 TAO_DynCommon::destroyed (void) const
1279 return this->destroyed_;
1282 CORBA::Any &
1283 TAO_DynCommon::the_any (void)
1285 return this->any_;
1288 void
1289 TAO_DynCommon::container_is_destroying (CORBA::Boolean val)
1291 this->container_is_destroying_ = val;
1294 void
1295 TAO_DynCommon::ref_to_component (CORBA::Boolean val)
1297 this->ref_to_component_ = val;
1300 CORBA::TypeCode_ptr
1301 TAO_DynCommon::check_type_and_unalias (CORBA::TypeCode_ptr tc)
1303 this->check_type (tc);
1305 return TAO_DynAnyFactory::strip_alias (tc);
1308 TAO_END_VERSIONED_NAMESPACE_DECL