Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / tao / DynamicAny / DynUnion_i.cpp
blobbba6b5e1a72824d4dd19a85bc3da3f1a7acc7131
1 // -*- C++ -*-
2 #include "tao/DynamicAny/DynUnion_i.h"
3 #include "tao/DynamicAny/DynEnum_i.h"
4 #include "tao/DynamicAny/DynAnyFactory.h"
5 #include "tao/DynamicAny/DynAnyUtils_T.h"
7 #include "tao/AnyTypeCode/Marshal.h"
8 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
9 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
11 #include "tao/CDR.h"
13 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
15 TAO_DynUnion_i::TAO_DynUnion_i (CORBA::Boolean allow_truncation)
16 : TAO_DynCommon (allow_truncation)
17 , member_slot_ (0u)
21 TAO_DynUnion_i::~TAO_DynUnion_i ()
25 void
26 TAO_DynUnion_i::init_common ()
28 this->ref_to_component_ = false;
29 this->container_is_destroying_ = false;
30 this->has_components_ = true;
31 this->destroyed_ = false;
32 this->component_count_ = 2;
33 this->current_position_ = 0;
34 this->member_slot_ = 0;
37 void
38 TAO_DynUnion_i::init (const CORBA::Any& any)
40 CORBA::TypeCode_var tc = any.type ();
42 CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ());
44 if (kind != CORBA::tk_union)
46 throw DynamicAny::DynAnyFactory::InconsistentTypeCode ();
49 // Initialize the typecode holder.
50 this->type_ = tc;
52 this->init_common ();
54 // Set the from_factory arg to TRUE, so any problems will throw
55 // InconsistentTypeCode.
56 this->set_from_any (any);
59 void
60 TAO_DynUnion_i::init (CORBA::TypeCode_ptr tc)
62 CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc);
64 if (kind != CORBA::tk_union)
66 throw DynamicAny::DynAnyFactory::InconsistentTypeCode ();
69 // Initialize the typecode holder and current index.
70 this->type_ = CORBA::TypeCode::_duplicate (tc);
72 this->init_common ();
74 // member_type()/member_label() do not work with aliased type codes.
75 CORBA::TypeCode_var unaliased_tc =
76 TAO_DynAnyFactory::strip_alias (this->type_.in ());
78 CORBA::Any_var first_label =
79 unaliased_tc->member_label (this->current_position_);
81 // Initialize the discriminator to the label value of the first member.
82 CORBA::TypeCode_var disc_tc = unaliased_tc->discriminator_type ();
83 CORBA::TCKind disc_kind = TAO_DynAnyFactory::unalias (disc_tc.in ());
84 CORBA::TCKind label_kind = TAO_DynAnyFactory::unalias (first_label->_tao_get_typecode ());
85 if (disc_kind == CORBA::tk_enum &&
86 label_kind == CORBA::tk_ulong)
88 // incase the discriminator is an enum type we have to walk
89 // a slightly more complex path because enum labels are
90 // stored as ulong in the union tc
91 this->discriminator_ =
92 TAO::MakeDynAnyUtils::make_dyn_any_t<CORBA::TypeCode_ptr> (
93 disc_tc.in (),
94 disc_tc.in (),
95 this->allow_truncation_ );
96 CORBA::ULong label_val;
97 first_label >>= label_val;
98 TAO_DynEnum_i::_narrow (this->discriminator_.in ())
99 ->set_as_ulong (label_val);
101 else
103 this->discriminator_ =
104 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
105 first_label.in ()._tao_get_typecode (),
106 first_label.in (),
107 this->allow_truncation_ );
110 CORBA::TypeCode_var first_type =
111 unaliased_tc->member_type (this->current_position_);
113 // Recursively initialize the member to its default value.
114 this->member_ =
115 TAO::MakeDynAnyUtils::make_dyn_any_t<CORBA::TypeCode_ptr> (
116 first_type.in (),
117 first_type.in (),
118 this->allow_truncation_ );
121 // ****************************************************************
123 TAO_DynUnion_i *
124 TAO_DynUnion_i::_narrow (CORBA::Object_ptr _tao_objref)
126 if (CORBA::is_nil (_tao_objref))
128 return 0;
131 return dynamic_cast<TAO_DynUnion_i *> (_tao_objref);
134 // This code is common to from_any() and the init() overload that takes
135 // an Any argument.
136 void
137 TAO_DynUnion_i::set_from_any (const CORBA::Any & any)
139 // discriminator_type () does not work with aliased type codes,
140 // only on unions, so strip the alias out of the type code
142 CORBA::TypeCode_var tc =
143 TAO_DynAnyFactory::strip_alias (any._tao_get_typecode ());
145 CORBA::TypeCode_var disc_tc =
146 tc->discriminator_type ();
148 CORBA::Any disc_any;
149 TAO::Unknown_IDL_Type *unk = 0;
151 // Get a CDR stream - if the Any doesn't have one, make one.
152 TAO::Any_Impl *impl = any.impl ();
153 TAO_OutputCDR out;
154 TAO_InputCDR in (static_cast<ACE_Message_Block *> (0));
156 if (impl->encoded ())
158 TAO::Unknown_IDL_Type * const tmp =
159 dynamic_cast<TAO::Unknown_IDL_Type *> (impl);
161 if (!tmp)
162 throw CORBA::INTERNAL ();
164 in = tmp->_tao_get_cdr ();
166 else
168 impl->marshal_value (out);
169 TAO_InputCDR tmp_in (out);
170 in = tmp_in;
173 TAO_InputCDR unk_in (in);
174 ACE_NEW (unk,
175 TAO::Unknown_IDL_Type (disc_tc.in (),
176 unk_in));
178 disc_any.replace (unk);
180 // Need this here because we might have been called from init().
181 if (!CORBA::is_nil (this->discriminator_.in ()))
183 this->discriminator_->destroy ();
186 // Set the discriminator.
187 this->discriminator_ =
188 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
189 disc_any._tao_get_typecode (),
190 disc_any,
191 this->allow_truncation_ );
193 // Move to the next field in the CDR stream.
194 (void) TAO_Marshal_Object::perform_skip (disc_tc.in (), &in);
196 CORBA::TypeCode_var unaliased =
197 TAO_DynAnyFactory::strip_alias (tc.in ());
199 CORBA::ULong const count = unaliased->member_count ();
201 CORBA::Boolean match = false;
202 CORBA::ULong i;
204 // Get the index.
205 for (i = 0; i < count; ++i)
207 CORBA::Any_var label_any = tc->member_label (i);
209 match = this->label_match (label_any.in (), disc_any);
211 if (match)
213 break;
217 // Need this here because we might have been called from init().
218 if (!CORBA::is_nil (this->member_.in ()))
220 this->member_->destroy ();
223 if (match)
225 CORBA::TypeCode_var member_tc = tc->member_type (i);
227 CORBA::Any member_any;
228 TAO::Unknown_IDL_Type *unk = 0;
229 ACE_NEW (unk,
230 TAO::Unknown_IDL_Type (member_tc.in (),
231 in));
232 member_any.replace (unk);
234 this->member_ =
235 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
236 member_any._tao_get_typecode (),
237 member_any,
238 this->allow_truncation_ );
240 this->member_slot_ = i;
242 else
244 // If no match, either the Any contains the default member or the
245 // type code was bad.
247 // default_index() does not work with aliased type codes.
248 CORBA::TypeCode_var unaliased_tc =
249 TAO_DynAnyFactory::strip_alias (this->type_.in ());
251 CORBA::Long default_index =
252 unaliased_tc->default_index ();
254 if (default_index == -1)
256 set_to_no_active_member ();
258 else
260 CORBA::ULong index = static_cast<CORBA::ULong> (default_index);
262 CORBA::TypeCode_var default_tc =
263 tc->member_type (index);
265 CORBA::Any default_any;
266 TAO::Unknown_IDL_Type *unk = 0;
267 ACE_NEW (unk,
268 TAO::Unknown_IDL_Type (default_tc.in (),
269 in));
270 default_any.replace (unk);
272 this->member_ =
273 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
274 default_any._tao_get_typecode (),
275 default_any,
276 this->allow_truncation_ );
278 this->member_slot_ = index;
283 // ****************************************************************
285 DynamicAny::DynAny_ptr
286 TAO_DynUnion_i::get_discriminator ()
288 if (this->destroyed_)
290 throw ::CORBA::OBJECT_NOT_EXIST ();
293 // A deep copy is made only by copy() (CORBA 2.4.2 section 9.2.3.6).
294 // Set the flag so the caller can't destroy.
295 this->set_flag (this->discriminator_.in (), 0);
297 return DynamicAny::DynAny::_duplicate (this->discriminator_.in ());
300 void
301 TAO_DynUnion_i::set_discriminator (DynamicAny::DynAny_ptr value)
303 if (this->destroyed_)
305 throw ::CORBA::OBJECT_NOT_EXIST ();
308 CORBA::TypeCode_var tc = value->type ();
310 CORBA::TypeCode_var disc_tc =
311 this->discriminator_->type ();
313 CORBA::Boolean equivalent = disc_tc->equivalent (tc.in ());
315 if (!equivalent)
317 throw DynamicAny::DynAny::TypeMismatch ();
320 CORBA::Any_var value_any = value->to_any ();
322 CORBA::ULong length =
323 this->type_->member_count ();
325 CORBA::Any_var label_any;
326 CORBA::ULong i;
328 // member_label() does not work with aliased type codes.
329 CORBA::TypeCode_var unaliased_tc =
330 TAO_DynAnyFactory::strip_alias (this->type_.in ());
332 CORBA::Boolean match = 0;
334 for (i = 0; i < length; ++i)
336 label_any = unaliased_tc->member_label (i);
338 match = this->label_match (label_any.in (), value_any.in ());
340 if (match)
342 break;
346 if (match)
348 // If the incoming label value matches the one we already
349 // have, we do nothing.
350 if (i == this->member_slot_)
352 return;
355 // If we got a match, a named member will be active.
356 CORBA::TCKind disc_kind = TAO_DynAnyFactory::unalias (disc_tc.in ());
357 CORBA::TCKind label_kind = TAO_DynAnyFactory::unalias (label_any->_tao_get_typecode ());
358 if (disc_kind == CORBA::tk_enum &&
359 label_kind == CORBA::tk_ulong)
361 // incase the discriminator is an enum type we have to walk
362 // a slightly more complex path because enum labels are
363 // stored as ulong in the union tc
364 CORBA::ULong label_val;
365 label_any >>= label_val;
366 TAO_DynEnum_i::_narrow (this->discriminator_.in ())
367 ->set_as_ulong (label_val);
369 else
371 this->discriminator_->from_any (label_any.in ());
374 // member_type() does not work with aliased type codes.
375 CORBA::TypeCode_var member_tc = unaliased_tc->member_type (i);
377 this->member_->destroy ();
379 // Initialize member to default value.
380 this->member_ =
381 TAO::MakeDynAnyUtils::make_dyn_any_t<CORBA::TypeCode_ptr> (
382 member_tc.in (),
383 member_tc.in (),
384 this->allow_truncation_ );
386 // Named active member (CORBA 2.3.1).
387 this->current_position_ = 1;
388 this->component_count_ = 2;
390 this->member_slot_ = i;
392 // we're through, disc, value has already been set
393 // no need for the copy operation below.
394 return;
396 else
398 // default_index() does not work with aliased type codes.
399 CORBA::TypeCode_var unaliased_tc =
400 TAO_DynAnyFactory::strip_alias (this->type_.in ());
402 // If no match, either the default member or no member is active.
403 CORBA::Long default_index =
404 unaliased_tc->default_index ();
406 if (default_index == -1)
408 // This can't throw InvalidValue - if there's no default case
409 // and all possible labels are used, we'd have had a match above.
410 this->set_to_no_active_member ();
412 else
414 this->set_to_default_member ();
416 this->member_slot_ = static_cast<CORBA::ULong> (default_index);
420 // If we get here, we update the discriminator no matter what.
421 // Any value will correspond to one of the three cases above.
422 this->discriminator_->destroy ();
424 this->discriminator_ = value->copy ();
427 void
428 TAO_DynUnion_i::set_to_default_member ()
430 if (this->destroyed_)
432 throw ::CORBA::OBJECT_NOT_EXIST ();
435 // default_index() does not work with aliased type codes.
436 CORBA::TypeCode_var unaliased_tc =
437 TAO_DynAnyFactory::strip_alias (this->type_.in ());
439 CORBA::Long default_index =
440 unaliased_tc->default_index ();
442 if (default_index == -1)
444 // No explicit default case.
445 throw DynamicAny::DynAny::TypeMismatch ();
447 else
449 CORBA::ULong index = static_cast<CORBA::ULong> (default_index);
451 CORBA::TypeCode_var default_tc =
452 unaliased_tc->member_type (index);
454 this->member_->destroy ();
456 this->member_ =
457 TAO::MakeDynAnyUtils::make_dyn_any_t<CORBA::TypeCode_ptr> (
458 default_tc.in (),
459 default_tc.in (),
460 this->allow_truncation_ );
462 // Default member active (CORBA 2.3.1).
463 this->current_position_ = 0;
464 this->component_count_ = 2;
466 this->member_slot_ = index;
470 void
471 TAO_DynUnion_i::set_to_no_active_member ()
473 if (this->destroyed_)
475 throw ::CORBA::OBJECT_NOT_EXIST ();
478 // default_index() does not work with aliased type codes.
479 CORBA::TypeCode_var unaliased_tc =
480 TAO_DynAnyFactory::strip_alias (this->type_.in ());
482 CORBA::Long default_index =
483 unaliased_tc->default_index ();
485 // Throw an exception is there is an explicit default case or if all
486 // possible case label values are used.
487 if (default_index != -1)
489 throw DynamicAny::DynAny::TypeMismatch ();
491 else
493 CORBA::TypeCode_var disc_tc =
494 this->discriminator_->type ();
496 CORBA::TCKind kind =
497 TAO_DynAnyFactory::unalias (disc_tc.in ());
499 if (kind == CORBA::tk_enum)
501 CORBA::ULong const member_count =
502 this->type_->member_count ();
504 CORBA::ULong const label_count =
505 disc_tc->member_count ();
507 if (member_count == label_count)
509 throw DynamicAny::DynAny::TypeMismatch ();
514 // No active member (CORBA 2.3.1).
515 this->current_position_ = 0;
516 this->component_count_ = 1;
519 CORBA::Boolean
520 TAO_DynUnion_i::has_no_active_member ()
522 if (this->destroyed_)
524 throw ::CORBA::OBJECT_NOT_EXIST ();
527 // No active member (CORBA 2.3.1).
528 return (this->current_position_ == 0 && this->component_count_ == 1);
531 CORBA::TCKind
532 TAO_DynUnion_i::discriminator_kind ()
534 if (this->destroyed_)
536 throw ::CORBA::OBJECT_NOT_EXIST ();
539 CORBA::TypeCode_var tc =
540 this->discriminator_->type ();
542 return TAO_DynAnyFactory::unalias (tc.in ());
545 DynamicAny::DynAny_ptr
546 TAO_DynUnion_i::member ()
548 if (this->destroyed_)
550 throw ::CORBA::OBJECT_NOT_EXIST ();
553 CORBA::Boolean has_no_active_member =
554 this->has_no_active_member ();
556 if (has_no_active_member)
558 throw DynamicAny::DynAny::InvalidValue ();
561 // A deep copy is made only by copy() (CORBA 2.4.2 section 9.2.3.6).
562 // Set the flag so the caller can't destroy.
563 this->set_flag (this->member_.in (), 0);
565 return DynamicAny::DynAny::_duplicate (this->member_.in ());
568 char *
569 TAO_DynUnion_i::member_name ()
571 if (this->destroyed_)
573 throw ::CORBA::OBJECT_NOT_EXIST ();
576 CORBA::Boolean has_no_active_member =
577 this->has_no_active_member ();
579 if (has_no_active_member)
581 throw DynamicAny::DynAny::InvalidValue ();
584 const char *retval = this->type_->member_name (this->member_slot_);
586 return CORBA::string_dup (retval);
589 CORBA::TCKind
590 TAO_DynUnion_i::member_kind ()
592 if (this->destroyed_)
594 throw ::CORBA::OBJECT_NOT_EXIST ();
597 CORBA::Boolean has_no_active_member =
598 this->has_no_active_member ();
600 if (has_no_active_member)
602 throw DynamicAny::DynAny::InvalidValue ();
605 CORBA::TypeCode_var tc = this->member_->type ();
607 return TAO_DynAnyFactory::unalias (tc.in ());
610 // ****************************************************************
612 void
613 TAO_DynUnion_i::from_any (const CORBA::Any& any)
615 if (this->destroyed_)
617 throw ::CORBA::OBJECT_NOT_EXIST ();
620 CORBA::TypeCode_var tc = any.type ();
621 CORBA::Boolean equivalent =
622 this->type_.in ()->equivalent (tc.in ());
624 if (equivalent)
626 // CORBA 2.3.1 section 9.2.3.3.
627 this->current_position_ = 0;
629 // May be changed in set_from_any().
630 this->component_count_ = 2;
632 // Set the from_factory arg to FALSE, so any problems will throw
633 // TypeMismatch.
634 this->set_from_any (any);
636 else
638 throw DynamicAny::DynAny::TypeMismatch ();
642 CORBA::Any_ptr
643 TAO_DynUnion_i::to_any ()
645 if (this->destroyed_)
647 throw ::CORBA::OBJECT_NOT_EXIST ();
650 TAO_OutputCDR out_cdr;
652 // Add the discriminator to the CDR stream.
654 CORBA::TypeCode_var disc_tc =
655 this->discriminator_->type ();
657 CORBA::Any_var disc_any =
658 this->discriminator_->to_any ();
660 TAO::Any_Impl *disc_any_impl = disc_any->impl ();
661 TAO_OutputCDR disc_out_cdr;
662 TAO_InputCDR disc_in_cdr (static_cast<ACE_Message_Block *> (0));
664 if (disc_any_impl->encoded ())
666 TAO::Unknown_IDL_Type * const disc_unk =
667 dynamic_cast<TAO::Unknown_IDL_Type *> (disc_any_impl);
669 if (!disc_unk)
670 throw CORBA::INTERNAL ();
672 disc_in_cdr = disc_unk->_tao_get_cdr ();
674 else
676 disc_any_impl->marshal_value (disc_out_cdr);
677 TAO_InputCDR disc_tmp_in_cdr (disc_out_cdr);
678 disc_in_cdr = disc_tmp_in_cdr;
681 (void) TAO_Marshal_Object::perform_append (disc_tc.in (),
682 &disc_in_cdr,
683 &out_cdr);
685 // Add the member to the CDR stream unless it has no active member.
686 if (this->has_no_active_member () == 0)
688 CORBA::TypeCode_var member_tc =
689 this->member_->type ();
691 CORBA::Any_var member_any =
692 this->member_->to_any ();
694 TAO::Any_Impl *member_any_impl = member_any->impl ();
695 TAO_OutputCDR member_out_cdr;
696 TAO_InputCDR member_in_cdr (static_cast<ACE_Message_Block *> (0));
698 if (member_any_impl->encoded ())
700 TAO::Unknown_IDL_Type * const member_unk =
701 dynamic_cast<TAO::Unknown_IDL_Type *> (member_any_impl);
703 if (!member_unk)
704 throw CORBA::INTERNAL ();
706 member_in_cdr = member_unk->_tao_get_cdr ();
708 else
710 member_any_impl->marshal_value (member_out_cdr);
711 TAO_InputCDR member_tmp_in_cdr (member_out_cdr);
712 member_in_cdr = member_tmp_in_cdr;
715 (void) TAO_Marshal_Object::perform_append (member_tc.in (),
716 &member_in_cdr,
717 &out_cdr);
720 // Make the Any.
721 TAO_InputCDR in_cdr (out_cdr);
723 CORBA::Any_ptr retval = 0;
724 ACE_NEW_THROW_EX (retval,
725 CORBA::Any,
726 CORBA::NO_MEMORY ());
728 TAO::Unknown_IDL_Type *unk = 0;
729 ACE_NEW_THROW_EX (unk,
730 TAO::Unknown_IDL_Type (this->type_.in (),
731 in_cdr),
732 CORBA::NO_MEMORY ());
734 retval->replace (unk);
735 return retval;
738 CORBA::Boolean
739 TAO_DynUnion_i::equal (DynamicAny::DynAny_ptr rhs)
741 if (this->destroyed_)
743 throw ::CORBA::OBJECT_NOT_EXIST ();
746 TAO_DynUnion_i *impl = TAO_DynUnion_i::_narrow (rhs);
748 if (impl == 0)
750 return 0;
753 CORBA::Boolean equivalent =
754 this->type_->equivalent (impl->type_.in ());
756 if (!equivalent)
758 return 0;
761 CORBA::Boolean member_equal =
762 this->member_->equal (impl->member_.in ());
764 CORBA::Boolean disc_equal =
765 this->discriminator_->equal (impl->discriminator_.in ());
767 impl->_remove_ref ();
769 return (member_equal && disc_equal);
772 void
773 TAO_DynUnion_i::destroy ()
775 if (this->destroyed_)
777 throw ::CORBA::OBJECT_NOT_EXIST ();
780 if (!this->ref_to_component_ || this->container_is_destroying_)
782 // Free the two components.
784 if (! CORBA::is_nil (this->member_.in ()))
786 this->set_flag (this->member_.in (), 1);
788 this->member_->destroy ();
791 this->set_flag (this->discriminator_.in (), 1);
793 this->discriminator_->destroy ();
795 this->destroyed_ = 1;
799 DynamicAny::DynAny_ptr
800 TAO_DynUnion_i::current_component ()
802 if (this->destroyed_)
804 throw ::CORBA::OBJECT_NOT_EXIST ();
807 if (this->current_position_ == 1)
809 this->set_flag (this->member_.in (), 0);
811 return DynamicAny::DynAny::_duplicate (this->member_.in ());
813 else
815 this->set_flag (this->discriminator_.in (), 0);
817 return DynamicAny::DynAny::_duplicate (this->discriminator_.in ());
821 // ****************************************************************
823 CORBA::Boolean
824 TAO_DynUnion_i::label_match (const CORBA::Any &my_any,
825 const CORBA::Any &other_any)
827 // Use my_any so we can detect a default case label,
828 // if we are iterating through the union type code's
829 // member_label() calls.
830 CORBA::TypeCode_var tc = my_any.type ();
832 CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ());
834 // No need to do any type checking - it was done before this
835 // call was made.
836 switch (kind)
838 case CORBA::tk_octet:
839 // Default case label - just skip it.
840 return 0;
841 case CORBA::tk_short:
843 CORBA::Short my_val;
844 CORBA::Short other_val;
845 my_any >>= my_val;
846 other_any >>= other_val;
847 return my_val == other_val;
849 case CORBA::tk_long:
851 CORBA::Long my_val;
852 CORBA::Long other_val;
853 my_any >>= my_val;
854 other_any >>= other_val;
855 return my_val == other_val;
857 case CORBA::tk_ushort:
859 CORBA::UShort my_val;
860 CORBA::UShort other_val;
861 my_any >>= my_val;
862 other_any >>= other_val;
863 return my_val == other_val;
865 case CORBA::tk_ulong:
867 CORBA::ULong my_val;
868 CORBA::ULong other_val;
869 my_any >>= my_val;
871 // check whether the discriminator is possibly an enum type
872 // since these get stored as ulong label values as well
873 CORBA::TypeCode_var other_tc = other_any.type ();
874 CORBA::TCKind kind = TAO_DynAnyFactory::unalias (other_tc.in ());
875 if (kind == CORBA::tk_enum)
877 TAO::Any_Impl *other_impl = other_any.impl ();
879 if (other_impl->encoded ())
881 TAO::Unknown_IDL_Type *other_unk =
882 dynamic_cast<TAO::Unknown_IDL_Type *> (other_impl);
884 // We don't want unk's rd_ptr to move, in case we are
885 // shared by another Any, so we use this to copy the
886 // state, not the buffer.
887 TAO_InputCDR for_reading (other_unk->_tao_get_cdr ());
888 for_reading.read_ulong (other_val);
890 else
892 TAO_OutputCDR other_out;
893 other_impl->marshal_value (other_out);
894 TAO_InputCDR other_in (other_out);
895 other_in.read_ulong (other_val);
898 else
899 other_any >>= other_val;
901 return my_val == other_val;
903 case CORBA::tk_boolean:
905 CORBA::Boolean my_val;
906 CORBA::Boolean other_val;
907 my_any >>= CORBA::Any::to_boolean (my_val);
908 other_any >>= CORBA::Any::to_boolean (other_val);
909 return my_val == other_val;
911 case CORBA::tk_char:
913 CORBA::Char my_val;
914 CORBA::Char other_val;
915 my_any >>= CORBA::Any::to_char (my_val);
916 other_any >>= CORBA::Any::to_char (other_val);
917 return my_val == other_val;
919 // For platforms without native 64-bit ints.
920 case CORBA::tk_longlong:
922 CORBA::LongLong my_val;
923 CORBA::LongLong other_val;
924 my_any >>= my_val;
925 other_any >>= other_val;
926 return my_val == other_val;
928 case CORBA::tk_ulonglong:
930 CORBA::ULongLong my_val;
931 CORBA::ULongLong other_val;
932 my_any >>= my_val;
933 other_any >>= other_val;
934 return my_val == other_val;
936 case CORBA::tk_wchar:
938 CORBA::WChar my_val;
939 CORBA::WChar other_val;
940 my_any >>= CORBA::Any::to_wchar (my_val);
941 other_any >>= CORBA::Any::to_wchar (other_val);
942 return my_val == other_val;
944 case CORBA::tk_enum:
946 CORBA::ULong my_val;
947 CORBA::ULong other_val;
949 TAO::Any_Impl *my_impl = my_any.impl ();
951 if (my_impl->encoded ())
953 TAO::Unknown_IDL_Type * const my_unk =
954 dynamic_cast<TAO::Unknown_IDL_Type *> (my_impl);
956 if (!my_unk)
957 throw CORBA::INTERNAL ();
959 // We don't want unk's rd_ptr to move, in case we are shared by
960 // another Any, so we use this to copy the state, not the buffer.
961 TAO_InputCDR for_reading (my_unk->_tao_get_cdr ());
962 for_reading.read_ulong (my_val);
964 else
966 TAO_OutputCDR my_out;
967 my_impl->marshal_value (my_out);
968 TAO_InputCDR my_in (my_out);
969 my_in.read_ulong (my_val);
972 TAO::Any_Impl *other_impl = other_any.impl ();
974 if (other_impl->encoded ())
976 TAO::Unknown_IDL_Type * const other_unk =
977 dynamic_cast<TAO::Unknown_IDL_Type *> (other_impl);
979 if (!other_unk)
980 throw CORBA::INTERNAL ();
982 // We don't want unk's rd_ptr to move, in case we are shared by
983 // another Any, so we use this to copy the state, not the buffer.
984 TAO_InputCDR for_reading (other_unk->_tao_get_cdr ());
985 for_reading.read_ulong (other_val);
987 else
989 TAO_OutputCDR other_out;
990 other_impl->marshal_value (other_out);
991 TAO_InputCDR other_in (other_out);
992 other_in.read_ulong (other_val);
995 return my_val == other_val;
997 // Cannot happen - we've covered all the legal discriminator types.
998 default:
999 return 0;
1003 TAO_END_VERSIONED_NAMESPACE_DECL