summaryrefslogtreecommitdiff
path: root/TAO/tests
diff options
context:
space:
mode:
authorjp4 <jp4@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-09-18 22:32:55 +0000
committerjp4 <jp4@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-09-18 22:32:55 +0000
commitbfcdd702b07e9ba5d95f6d34f9786bd72ed9cb85 (patch)
tree078fc66cef722ac9cdee431e6fdec801b7e0ab1c /TAO/tests
parent46433d977a5217fac59d6f737f2f931612651601 (diff)
downloadATCD-bfcdd702b07e9ba5d95f6d34f9786bd72ed9cb85.tar.gz
*** empty log message ***
Diffstat (limited to 'TAO/tests')
-rw-r--r--TAO/tests/DynAny_Test/DynAny_i.cpp2
-rw-r--r--TAO/tests/DynAny_Test/DynAny_i.h2
-rw-r--r--TAO/tests/DynAny_Test/DynArray_i.cpp2
-rw-r--r--TAO/tests/DynAny_Test/DynArray_i.h2
-rw-r--r--TAO/tests/DynAny_Test/DynSequence_i.cpp2
-rw-r--r--TAO/tests/DynAny_Test/DynSequence_i.h2
-rw-r--r--TAO/tests/DynAny_Test/DynStruct_i.cpp2
-rw-r--r--TAO/tests/DynAny_Test/DynStruct_i.h2
-rw-r--r--TAO/tests/DynAny_Test/DynUnion_i.cpp1110
-rw-r--r--TAO/tests/DynAny_Test/DynUnion_i.h137
-rw-r--r--TAO/tests/DynAny_Test/README.txt79
-rw-r--r--TAO/tests/DynAny_Test/da_tests.idl30
-rw-r--r--TAO/tests/DynAny_Test/driver.cpp31
13 files changed, 1231 insertions, 172 deletions
diff --git a/TAO/tests/DynAny_Test/DynAny_i.cpp b/TAO/tests/DynAny_Test/DynAny_i.cpp
index c3cd5b4c3f2..9d73de9515e 100644
--- a/TAO/tests/DynAny_Test/DynAny_i.cpp
+++ b/TAO/tests/DynAny_Test/DynAny_i.cpp
@@ -314,7 +314,7 @@ DynAny_i::insert_wchar (CORBA::WChar value, CORBA::Environment &env)
}
void
-DynAny_i::insert_any (CORBA::Any& value, CORBA::Environment &env)
+DynAny_i::insert_any (const CORBA::Any& value, CORBA::Environment &env)
{
if (this->value_.type ()->kind (env) == CORBA::tk_any)
this->value_ <<= value;
diff --git a/TAO/tests/DynAny_Test/DynAny_i.h b/TAO/tests/DynAny_Test/DynAny_i.h
index 94b25f721cd..211e1176942 100644
--- a/TAO/tests/DynAny_Test/DynAny_i.h
+++ b/TAO/tests/DynAny_Test/DynAny_i.h
@@ -70,7 +70,7 @@ public:
CORBA::Environment &env);
void insert_wchar (CORBA::WChar value,
CORBA::Environment &env);
- void insert_any (CORBA::Any& value,
+ void insert_any (const CORBA::Any& value,
CORBA::Environment &env);
CORBA::Boolean get_boolean (CORBA::Environment &env);
diff --git a/TAO/tests/DynAny_Test/DynArray_i.cpp b/TAO/tests/DynAny_Test/DynArray_i.cpp
index 087aef2dd59..44f84f133ef 100644
--- a/TAO/tests/DynAny_Test/DynArray_i.cpp
+++ b/TAO/tests/DynAny_Test/DynArray_i.cpp
@@ -504,7 +504,7 @@ DynArray_i::insert_wchar (CORBA::WChar value, CORBA::Environment &env)
}
void
-DynArray_i::insert_any (CORBA::Any& value, CORBA::Environment &env)
+DynArray_i::insert_any (const CORBA::Any& value, CORBA::Environment &env)
{
if (this->get_element_type (env)->kind (env) == CORBA::tk_any)
{
diff --git a/TAO/tests/DynAny_Test/DynArray_i.h b/TAO/tests/DynAny_Test/DynArray_i.h
index ef1f4864e92..4052617fa42 100644
--- a/TAO/tests/DynAny_Test/DynArray_i.h
+++ b/TAO/tests/DynAny_Test/DynArray_i.h
@@ -76,7 +76,7 @@ public:
CORBA::Environment &env);
void insert_wchar (CORBA::WChar value,
CORBA::Environment &env);
- void insert_any (CORBA::Any& value,
+ void insert_any (const CORBA::Any& value,
CORBA::Environment &env);
CORBA::Boolean get_boolean (CORBA::Environment &env);
diff --git a/TAO/tests/DynAny_Test/DynSequence_i.cpp b/TAO/tests/DynAny_Test/DynSequence_i.cpp
index 790ed8f488b..dcf443ce1ea 100644
--- a/TAO/tests/DynAny_Test/DynSequence_i.cpp
+++ b/TAO/tests/DynAny_Test/DynSequence_i.cpp
@@ -532,7 +532,7 @@ DynSequence_i::insert_wchar (CORBA::WChar value, CORBA::Environment &env)
}
void
-DynSequence_i::insert_any (CORBA::Any& value, CORBA::Environment &env)
+DynSequence_i::insert_any (const CORBA::Any& value, CORBA::Environment &env)
{
if (this->get_element_type (env)->kind (env) == CORBA::tk_any)
{
diff --git a/TAO/tests/DynAny_Test/DynSequence_i.h b/TAO/tests/DynAny_Test/DynSequence_i.h
index 7366b450405..4e349ec89c8 100644
--- a/TAO/tests/DynAny_Test/DynSequence_i.h
+++ b/TAO/tests/DynAny_Test/DynSequence_i.h
@@ -80,7 +80,7 @@ public:
CORBA::Environment &env);
void insert_wchar (CORBA::WChar value,
CORBA::Environment &env);
- void insert_any (CORBA::Any& value,
+ void insert_any (const CORBA::Any& value,
CORBA::Environment &env);
CORBA::Boolean get_boolean (CORBA::Environment &env);
diff --git a/TAO/tests/DynAny_Test/DynStruct_i.cpp b/TAO/tests/DynAny_Test/DynStruct_i.cpp
index bf00c3acf87..7ff057a7660 100644
--- a/TAO/tests/DynAny_Test/DynStruct_i.cpp
+++ b/TAO/tests/DynAny_Test/DynStruct_i.cpp
@@ -508,7 +508,7 @@ DynStruct_i::insert_wchar (CORBA::WChar value, CORBA::Environment &env)
}
void
-DynStruct_i::insert_any (CORBA::Any& value, CORBA::Environment &env)
+DynStruct_i::insert_any (const CORBA::Any& value, CORBA::Environment &env)
{
if (DynAny_i::unalias (this->type_.in ()->member_type (this->index_), env)
== CORBA::tk_any)
diff --git a/TAO/tests/DynAny_Test/DynStruct_i.h b/TAO/tests/DynAny_Test/DynStruct_i.h
index 29df04926b9..4cecaab74d3 100644
--- a/TAO/tests/DynAny_Test/DynStruct_i.h
+++ b/TAO/tests/DynAny_Test/DynStruct_i.h
@@ -79,7 +79,7 @@ public:
CORBA::Environment &env);
void insert_wchar (CORBA::WChar value,
CORBA::Environment &env);
- void insert_any (CORBA::Any& value,
+ void insert_any (const CORBA::Any& value,
CORBA::Environment &env);
CORBA::Boolean get_boolean (CORBA::Environment &env);
diff --git a/TAO/tests/DynAny_Test/DynUnion_i.cpp b/TAO/tests/DynAny_Test/DynUnion_i.cpp
index aba4d8274b5..263c3a33b82 100644
--- a/TAO/tests/DynAny_Test/DynUnion_i.cpp
+++ b/TAO/tests/DynAny_Test/DynUnion_i.cpp
@@ -23,69 +23,38 @@ DynUnion_i::DynUnion_i (const CORBA_Any& any)
{
CORBA::Environment env;
- CORBA::TypeCode_ptr arg_tc = any.type ();
-
- if (DynAny_i::unalias (arg_tc, env) == CORBA::tk_union)
+ if (DynAny_i::unalias (any.type (), env) == CORBA::tk_union)
{
- CORBA::TypeCode_ptr disc_tc = arg_tc->discriminator_type (env);
-
- // Get the CDR stream of the argument.
- ACE_Message_Block* mb =
- ACE_Message_Block::duplicate (any._tao_get_cdr ());
-
- TAO_InputCDR cdr (mb);
-
- CORBA_Any disc_any (disc_tc,
- cdr.start ());
-
- cdr.skip (disc_tc);
-
- this->discriminator_ = DynAny_i::create_dyn_any (disc_any,
- env);
-
- CORBA::ULong count = arg_tc->member_count (env);
- CORBA::ULong i, index;
+ // Initialize the typecode holder
+ this->type_ = any.type ();
- for (i = 0; i < count; i++)
- {
- CORBA_Any label_any = *arg_tc->member_label (i,
- env);
+ this->set_from_any (any, env);
+ }
+ else
+ env.exception (new DynAny_i::InconsistentTypeCode);
+}
- if (label_any.type ()->kind (env) == CORBA::tk_octet)
- {
- index = arg_tc->default_index (env);
+DynUnion_i::DynUnion_i (CORBA_TypeCode_ptr tc)
+{
+ CORBA::Environment env;
- break;
- }
- else if (0 /* TODO: Code for comparison of any values goes here */)
- {
- index = i;
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_union)
+ {
+ // Initialize the typecode holder
+ this->type_ = CORBA::TypeCode::_duplicate (tc);
- break;
- }
- }
+ CORBA::TypeCode_ptr disc_tc = tc->discriminator_type (env);
- if (i == count)
- env.exception (new DynAny_i::InconsistentTypeCode);
- else
- {
- CORBA_Any member_any (arg_tc->member_type (index,
- env),
- cdr.start ());
+ // Get a typecode into the discriminator holder.
+ this->discriminator_ = DynAny_i::create_dyn_any (disc_tc, env);
- this->member_ = DynAny_i::create_dyn_any (member_any,
- env);
- }
+ // To be filled in by from_any() or assign().
+ this->member_ = 0;
}
else
env.exception (new DynAny_i::InconsistentTypeCode);
}
-DynUnion_i::DynUnion_i (CORBA_TypeCode_ptr tc)
-{
- // TODO
-}
-
DynUnion_i::~DynUnion_i (void)
{
}
@@ -93,53 +62,1064 @@ DynUnion_i::~DynUnion_i (void)
/////////////////////////////////////////////////////////////////////
// Functions specific to DynUnion
+// If an invalid value has been passed in to the discriminator,
+// we don't save it but instead set the member index to the
+// default value, if one exists.
CORBA::Boolean
DynUnion_i::set_as_default (CORBA::Environment& env)
{
- // TODO
- return 0;
+ if ((CORBA::Long) this->index_ == this->type_->default_index (env))
+ return 1;
+ else
+ return 0;
+}
+
+void
+DynUnion_i::set_as_default (CORBA::Boolean set_as_default,
+ CORBA::Environment&)
+{
+ // Set_as_default should be treated as read-only and
+ // probably will be in a future spec. For now, since
+ // the IDL compiler generated the virtual function,
+ // we override it as a no-op.
}
DynAny_ptr
DynUnion_i::discriminator (CORBA::Environment& env)
{
- // TODO
- return 0;
+ return this->discriminator_.in ();
}
TCKind
DynUnion_i::discriminator_kind (CORBA::Environment& env)
{
- // TODO
- return CORBA::tk_null;
+ return this->type_->discriminator_type (env)->kind (env);
}
DynAny_ptr
DynUnion_i::member (CORBA::Environment& env)
{
- // TODO
- return 0;
+ return this->member_.in ();
}
char*
DynUnion_i::member_name (CORBA::Environment& env)
{
- // TODO
- return 0;
+ return CORBA::string_dup (this->type_->member_name (this->index_, env));
}
+// If a valid member name is supplied, this function creates a new
+// member which is NOT initialized.
void
DynUnion_i::member_name (const char* member_name,
CORBA::Environment& env)
{
- // TODO
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ if (!ACE_OS::strcmp (member_name, this->type_->member_name (i, env)))
+ {
+ // No sense doing anything if we're just "resetting" to the
+ // current member.
+ if (i == this->index_)
+ return;
+ else
+ {
+ this->member_ =
+ DynAny_i::create_dyn_any (this->type_->member_type (i, env),
+ env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+ }
}
-TCKind
+CORBA::TCKind
DynUnion_i::member_kind (CORBA::Environment& env)
{
- // TODO
- return CORBA::tk_null;
+ return this->type_->member_type (this->index_, env)->kind (env);
+}
+
+//////////////////////////////////////////////////////////////////////
+// Common functions
+
+void
+DynUnion_i::assign (DynAny_ptr dyn_any, CORBA::Environment &env)
+{
+ // *dyn_any->to_any raises Invalid if arg is bad.
+ if (this->type_->equal (dyn_any->type (env), env))
+ this->from_any (*dyn_any->to_any (env), env);
+ else
+ env.exception (new DynAny::Invalid);
+}
+
+DynAny_ptr
+DynUnion_i::copy (CORBA::Environment &env)
+{
+ CORBA_Any_ptr a = this->to_any (env);
+ return DynAny_i::create_dyn_any (*a, env);
+}
+
+void
+DynUnion_i::destroy (CORBA::Environment &env)
+{
+ // Free the two DynAnys.
+ this->member_->destroy (env);
+ this->discriminator_->destroy (env);
+
+ // Free the top level
+ CORBA::release (this->_this (env));
+}
+
+void
+DynUnion_i::from_any (const CORBA_Any& any,
+ CORBA::Environment &env)
+{
+ if (this->type_.in ()->equal (any.type (), env))
+ this->set_from_any (any, env);
+ else
+ env.exception (new DynAny::Invalid);
+}
+
+CORBA::Any_ptr
+DynUnion_i::to_any (CORBA::Environment& env)
+{
+ // Both Dynanys must have been initialied.
+ if (this->member_.in () == 0 || this->discriminator_.in () == 0)
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+
+ TAO_OutputCDR out_cdr;
+
+ // Add the discriminator to the CDR stream.
+
+ CORBA_TypeCode_ptr disc_tc = this->discriminator_->type (env);
+
+ CORBA_Any_ptr disc_any = this->discriminator_->to_any (env);
+
+ ACE_Message_Block* disc_mb =
+ ACE_Message_Block::duplicate (disc_any->_tao_get_cdr ());
+
+ TAO_InputCDR disc_cdr (disc_mb);
+
+ out_cdr.append (disc_tc, &disc_cdr, env);
+
+ // Add the member to the CDR stream.
+
+ CORBA_TypeCode_ptr member_tc = this->member_->type (env);
+
+ CORBA_Any_ptr member_any = this->member_->to_any (env);
+
+ ACE_Message_Block* member_mb =
+ ACE_Message_Block::duplicate (member_any->_tao_get_cdr ());
+
+ TAO_InputCDR member_cdr (member_mb);
+
+ out_cdr.append (member_tc, &member_cdr, env);
+
+ // Make the Any.
+ TAO_InputCDR in_cdr (out_cdr);
+
+ return new CORBA_Any (this->type (env),
+ in_cdr.start ());
+}
+
+CORBA::TypeCode_ptr
+DynUnion_i::type (CORBA::Environment &)
+{
+ return this->type_.in ();
+}
+
+DynAny_ptr
+DynUnion_i::current_component (CORBA::Environment &env)
+{
+ return this->member_.in ();
+}
+
+CORBA::Boolean
+DynUnion_i::next (CORBA::Environment &env)
+{
+ if (this->index_ + 1 == this->type_->member_count (env))
+ return 0;
+
+ ++this->index_;
+
+ this->member_ =
+ DynAny_i::create_dyn_any (this->type_->member_type (this->index_, env),
+ env);
+ return 1;
+}
+
+CORBA::Boolean
+DynUnion_i::seek (CORBA::Long index, CORBA::Environment &env)
+{
+ if (index < 0 || index >= (CORBA::Long) this->type_->member_count (env))
+ return 0;
+
+ this->index_ = index;
+
+ this->member_ =
+ DynAny_i::create_dyn_any (this->type_->member_type (this->index_, env),
+ env);
+ return 1;
+}
+
+void
+DynUnion_i::rewind (CORBA::Environment &env)
+{
+ if (this->index_ == 0)
+ return;
+
+ this->index_ = 0;
+
+ this->member_ =
+ DynAny_i::create_dyn_any (this->type_->member_type (this->index_, env),
+ env);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// Insert and get functions
+//
+// Note that next() is not called in the body of these functions as it is
+// with DynStruct, DynSequence and DynArray. It doesn't seem to make sense
+// for unions.
+
+//**************************INSERT FUNCTIONS**********************************
+
+void
+DynUnion_i::insert_boolean (CORBA::Boolean value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_boolean)
+ this->member_->insert_boolean (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_boolean)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_boolean (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_octet (CORBA::Octet value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_octet)
+ this->member_->insert_octet (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_octet)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_octet (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_char (CORBA::Char value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_char)
+ this->member_->insert_char (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_char)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_char (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_short (CORBA::Short value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_short)
+ this->member_->insert_short (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_short)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_short (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_long (CORBA::Long value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_long)
+ this->member_->insert_long (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_long)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_long (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
}
+void
+DynUnion_i::insert_ushort (CORBA::UShort value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_ushort)
+ this->member_->insert_ushort (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_ushort)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_ushort (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_ulong (CORBA::ULong value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_ulong)
+ this->member_->insert_ulong (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_ulong)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_ulong (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_float (CORBA::Float value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_float)
+ this->member_->insert_float (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_float)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_float (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_double (CORBA::Double value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_double)
+ this->member_->insert_double (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_double)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_double (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_string (CORBA::String value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_string)
+ this->member_->insert_string (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_string)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_string (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_reference (CORBA::Object_ptr value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_objref)
+ this->member_->insert_reference (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_objref)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_reference (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_typecode (CORBA::TypeCode_ptr value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_TypeCode)
+ this->member_->insert_typecode (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_TypeCode)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_typecode (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_longlong (CORBA::LongLong value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_longlong)
+ this->member_->insert_longlong (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_longlong)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_longlong (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_ulonglong (CORBA::ULongLong value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_ulonglong)
+ this->member_->insert_ulonglong (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_ulonglong)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_ulonglong (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_wchar (CORBA::WChar value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_wchar)
+ this->member_->insert_wchar (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_wchar)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_wchar (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+void
+DynUnion_i::insert_any (const CORBA::Any& value, CORBA::Environment &env)
+{
+ if (DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_any)
+ this->member_->insert_any (value, env);
+ else
+ {
+ CORBA::ULong count = this->type_->member_count (env);
+
+ for (CORBA::ULong i = 0; i < count; i++)
+ {
+ CORBA::TypeCode_ptr tc = this->type_->member_type (i, env);
+
+ if (DynAny_i::unalias (tc, env) == CORBA::tk_any)
+ {
+ this->member_ = DynAny_i::create_dyn_any (tc, env);
+ this->member_->insert_any (value, env);
+ this->discriminator_ =
+ DynAny_i::create_dyn_any (*this->type_->member_label (i, env), env);
+ this->index_ = i;
+ return;
+ }
+ }
+
+ env.exception (new DynAny::InvalidValue);
+ }
+}
+
+//*********************************GET FUNCTIONS*********************************
+
+CORBA::Boolean
+DynUnion_i::get_boolean (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_boolean)
+ return this->member_->get_boolean (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::Octet
+DynUnion_i::get_octet (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_octet)
+ return this->member_->get_octet (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::Char
+DynUnion_i::get_char (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_char)
+ return this->member_->get_char (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::Short
+DynUnion_i::get_short (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_short)
+ return this->member_->get_short (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::Long
+DynUnion_i::get_long (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_long)
+ return this->member_->get_long (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::UShort
+DynUnion_i::get_ushort(CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_ushort)
+ return this->member_->get_ushort (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::ULong
+DynUnion_i::get_ulong (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_ulong)
+ return this->member_->get_ulong (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::Float
+DynUnion_i::get_float (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_float)
+ return this->member_->get_float (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::Double
+DynUnion_i::get_double (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_double)
+ return this->member_->get_double (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::String
+DynUnion_i::get_string (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_string)
+ return this->member_->get_string (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::TypeCode_ptr
+DynUnion_i::get_typecode (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_TypeCode)
+ return this->member_->get_typecode (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::Object_ptr
+DynUnion_i::get_reference (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_objref)
+ return this->member_->get_reference (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::LongLong
+DynUnion_i::get_longlong (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_longlong)
+ return this->member_->get_longlong (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::ULongLong
+DynUnion_i::get_ulonglong (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_ulonglong)
+ return this->member_->get_ulonglong (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::WChar
+DynUnion_i::get_wchar (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_wchar)
+ return this->member_->get_wchar (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+CORBA::Any_ptr
+DynUnion_i::get_any (CORBA::Environment &env)
+{
+ if (this->member_.in () &&
+ DynAny_i::unalias (this->member_->type (env), env) == CORBA::tk_any)
+ return this->member_->get_any (env);
+ else
+ {
+ env.exception (new DynAny::Invalid);
+ return 0;
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// Private functions
+
+// Template class that serves as a functor for all types except those
+// specifically defined below.
+template <class Type>
+CORBA::Boolean
+DynUnion_i::Extractor<Type>::check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any)
+{
+ inside_any >>= this->member_index_;
+ outside_any >>= this->arg_index_;
+ return this->member_index_ == this->arg_index_;
+}
+
+// Need some explicit definitions for these types:
+
+CORBA::Boolean
+DynUnion_i::Extractor<CORBA::Boolean>::check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any)
+{
+ CORBA::Any::to_boolean member_struct (this->member_index_);
+ CORBA::Any::to_boolean arg_struct (this->arg_index_);
+ inside_any >>= member_struct;
+ outside_any >>= arg_struct;
+ return member_struct.ref_ == arg_struct.ref_;
+}
+
+CORBA::Boolean
+DynUnion_i::Extractor<CORBA::Char>::check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any)
+{
+ CORBA::Any::to_char member_struct (this->member_index_);
+ CORBA::Any::to_char arg_struct (this->arg_index_);
+ inside_any >>= member_struct;
+ outside_any >>= arg_struct;
+ return member_struct.ref_ == arg_struct.ref_;
+}
+
+CORBA::Boolean
+DynUnion_i::WChar_extractor::check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any)
+{
+ CORBA::Any::to_wchar member_struct (this->member_index_);
+ CORBA::Any::to_wchar arg_struct (this->arg_index_);
+ inside_any >>= member_struct;
+ outside_any >>= arg_struct;
+ return member_struct.ref_ == arg_struct.ref_;
+}
+
+CORBA::Boolean
+DynUnion_i::Enum_extractor::check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any)
+{
+ // Get the CDR stream of one argument...
+ ACE_Message_Block* mb =
+ ACE_Message_Block::duplicate (inside_any._tao_get_cdr ());
+
+ TAO_InputCDR inside_cdr (mb);
+
+ inside_cdr.read_ulong (this->member_index_);
+
+ // And of the other...
+ mb = ACE_Message_Block::duplicate (outside_any._tao_get_cdr ());
+
+ TAO_InputCDR outside_cdr (mb);
+
+ outside_cdr.read_ulong (this->arg_index_);
+
+ return this->member_index_ == this->arg_index_;
+}
+
+// Functor factory.
+DynUnion_i::Extractor_base*
+DynUnion_i::get_extractor (CORBA::TCKind kind)
+{
+ switch (kind)
+ {
+ case CORBA::tk_short:
+ return new Extractor<CORBA::Short>;
+ case CORBA::tk_long:
+ return new Extractor<CORBA::Long>;
+ case CORBA::tk_ushort:
+ return new Extractor<CORBA::UShort>;
+ case CORBA::tk_ulong:
+ return new Extractor<CORBA::ULong>;
+ case CORBA::tk_boolean:
+ return new Extractor<CORBA::Boolean>;
+ case CORBA::tk_char:
+ return new Extractor<CORBA::Char>;
+ case CORBA::tk_longlong:
+ return new Extractor<CORBA::LongLong>;
+ case CORBA::tk_ulonglong:
+ return new Extractor<CORBA::ULongLong>;
+ case CORBA::tk_wchar:
+ return new WChar_extractor;
+ case CORBA::tk_enum:
+ return new Enum_extractor;
+ default:
+ return 0;
+ }
+}
+
+// This code is common to from_any and the constructor taking an Any
+// argument.
+void
+DynUnion_i::set_from_any (const CORBA_Any& any,
+ CORBA::Environment &env)
+{
+ // Get the CDR stream of the argument.
+ ACE_Message_Block* mb =
+ ACE_Message_Block::duplicate (any._tao_get_cdr ());
+
+ TAO_InputCDR cdr (mb);
+
+ CORBA_TypeCode_ptr disc_tc = any.type ()->discriminator_type (env);
+
+ CORBA_Any disc_any (disc_tc,
+ cdr.start ());
+
+ // Set the discriminator holder.
+ this->discriminator_ = DynAny_i::create_dyn_any (disc_any, env);
+
+ cdr.skip (disc_tc);
+
+ CORBA::ULong count = any.type ()->member_count (env);
+ CORBA::ULong i;
+ CORBA::Long default_index = -1;
+
+ CORBA::TCKind discriminator_kind = disc_tc->kind (env);
+
+ Extractor_base* functor = this->get_extractor (discriminator_kind);
+
+ // Get the index.
+ for (i = 0; i < count; i++)
+ {
+ CORBA_Any label_any = *any.type ()->member_label (i, env);
+
+ CORBA::TCKind label_kind = label_any.type ()->kind (env);
+
+ // If there is a default index, note the value but don't call
+ // check_match.
+ if (label_kind == CORBA::tk_octet)
+ {
+ default_index = i;
+ continue;
+ }
+ // Check if values match.
+ else if (functor->check_match (disc_any,
+ label_any))
+ {
+ this->index_ = i;
+ break;
+ }
+ }
+
+ delete functor;
+
+ if (i == count && default_index == -1)
+ env.exception (new DynAny::Invalid);
+ else
+ {
+ if (i == count && default_index != -1)
+ this->index_ = default_index;
+
+ CORBA_Any member_any (any.type ()->member_type (this->index_, env),
+ cdr.start ());
+
+ this->member_ = DynAny_i::create_dyn_any (member_any,
+ env);
+ }
+}
diff --git a/TAO/tests/DynAny_Test/DynUnion_i.h b/TAO/tests/DynAny_Test/DynUnion_i.h
index fe7e339d08e..282780f3e17 100644
--- a/TAO/tests/DynAny_Test/DynUnion_i.h
+++ b/TAO/tests/DynAny_Test/DynUnion_i.h
@@ -23,19 +23,134 @@ public:
DynUnion_i (CORBA_TypeCode_ptr tc);
~DynUnion_i (void);
- CORBA::Boolean set_as_default (CORBA::Environment& env);
- DynAny_ptr discriminator (CORBA::Environment& env);
- TCKind discriminator_kind (CORBA::Environment& env);
- DynAny_ptr member (CORBA::Environment& env);
- char* member_name (CORBA::Environment& env);
- void member_name (const char* member_name, CORBA::Environment& env);
- TCKind member_kind (CORBA::Environment& env);
+ // Functions specific to DynUnion
+ CORBA::Boolean set_as_default (CORBA::Environment& env);
+ void set_as_default (CORBA::Boolean set_as_default,
+ CORBA::Environment&);
+ DynAny_ptr discriminator (CORBA::Environment& env);
+ TCKind discriminator_kind (CORBA::Environment& env);
+ DynAny_ptr member (CORBA::Environment& env);
+ char* member_name (CORBA::Environment& env);
+ void member_name (const char* member_name,
+ CORBA::Environment& env);
+ TCKind member_kind (CORBA::Environment& env);
+
+ // Common functions
+ void assign (DynAny_ptr dyn_any,
+ CORBA::Environment &env);
+ DynAny_ptr copy (CORBA::Environment &env);
+ void destroy (CORBA::Environment &env);
+ void from_any (const CORBA::Any& any,
+ CORBA::Environment &env);
+ CORBA::Any_ptr to_any (CORBA::Environment &env);
+ CORBA::TypeCode_ptr type (CORBA::Environment &);
+ DynAny_ptr current_component (CORBA::Environment &env);
+ CORBA::Boolean next (CORBA::Environment &env);
+ CORBA::Boolean seek (CORBA::Long index,
+ CORBA::Environment &env);
+ void rewind (CORBA::Environment &env);
+
+ // The insert and get functions.
+
+ void insert_boolean (CORBA::Boolean value,
+ CORBA::Environment &env);
+ void insert_octet (CORBA::Octet value,
+ CORBA::Environment &env);
+ void insert_char (CORBA::Char value,
+ CORBA::Environment &env);
+ void insert_short (CORBA::Short value,
+ CORBA::Environment &env);
+ void insert_ushort (CORBA::UShort value,
+ CORBA::Environment &env);
+ void insert_long (CORBA::Long value,
+ CORBA::Environment &env);
+ void insert_ulong (CORBA::ULong value,
+ CORBA::Environment &env);
+ void insert_float (CORBA::Float value,
+ CORBA::Environment &env);
+ void insert_double (CORBA::Double value,
+ CORBA::Environment &env);
+ void insert_string (char * value,
+ CORBA::Environment &env);
+ void insert_reference (CORBA::Object_ptr value,
+ CORBA::Environment &env);
+ void insert_typecode (CORBA::TypeCode_ptr value,
+ CORBA::Environment &env);
+ void insert_longlong (CORBA::LongLong value,
+ CORBA::Environment &env);
+ void insert_ulonglong (CORBA::ULongLong value,
+ CORBA::Environment &env);
+ void insert_wchar (CORBA::WChar value,
+ CORBA::Environment &env);
+ void insert_any (const CORBA::Any& value,
+ CORBA::Environment &env);
+
+ CORBA::Boolean get_boolean (CORBA::Environment &env);
+ CORBA::Octet get_octet (CORBA::Environment &env);
+ CORBA::Char get_char (CORBA::Environment &env);
+ CORBA::Short get_short (CORBA::Environment &env);
+ CORBA::UShort get_ushort (CORBA::Environment &env);
+ CORBA::Long get_long (CORBA::Environment &env);
+ CORBA::ULong get_ulong (CORBA::Environment &env);
+ CORBA::Float get_float (CORBA::Environment &env);
+ CORBA::Double get_double (CORBA::Environment &env);
+ char * get_string (CORBA::Environment &env);
+ CORBA::Object_ptr get_reference (CORBA::Environment &env);
+ CORBA::TypeCode_ptr get_typecode (CORBA::Environment &env);
+ CORBA::LongLong get_longlong (CORBA::Environment &env);
+ CORBA::ULongLong get_ulonglong (CORBA::Environment &env);
+ CORBA::WChar get_wchar (CORBA::Environment &env);
+ CORBA::Any_ptr get_any (CORBA::Environment &env);
private:
- CORBA::Long default_index_;
- DynAny_var discriminator_;
- CORBA::TCKind discriminator_kind_;
- DynAny_var member_;
+ CORBA::TypeCode_var type_;
+ DynAny_var discriminator_;
+ CORBA::ULong index_;
+ DynAny_var member_;
+
+ class Extractor_base
+ {
+ public:
+ virtual
+ CORBA::Boolean check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any) = 0;
+ };
+
+ template <class Type>
+ class Extractor : public Extractor_base
+ {
+ public:
+ CORBA::Boolean check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any);
+ private:
+ Type arg_index_,
+ member_index_;
+ };
+
+ class WChar_extractor : public Extractor_base
+ {
+ public:
+ CORBA::Boolean check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any);
+ private:
+ CORBA::WChar arg_index_,
+ member_index_;
+ };
+
+ class Enum_extractor : public Extractor_base
+ {
+ public:
+ CORBA::Boolean check_match (const CORBA_Any& inside_any,
+ const CORBA_Any& outside_any);
+ private:
+ CORBA::ULong arg_index_,
+ member_index_;
+ };
+
+ Extractor_base* get_extractor (CORBA::TCKind kind);
+
+ void set_from_any (const CORBA_Any& any,
+ CORBA::Environment &env);
};
#endif /* DYNUNION_I_H */
diff --git a/TAO/tests/DynAny_Test/README.txt b/TAO/tests/DynAny_Test/README.txt
deleted file mode 100644
index 522284d05b0..00000000000
--- a/TAO/tests/DynAny_Test/README.txt
+++ /dev/null
@@ -1,79 +0,0 @@
-
- *********** DynAny_Test ****************
-
- updated 9/17/98.
-
-
-What we have so far starts with the DynAny.idl file. Since TCKind is
-a return type in one or two of the functions, another file called
-tckind.idl is included in DynAny.idl, but is not included in the NT project
-build. This causes the TAO IDL compiler to generate include statements for
-files called tckindC.h and tckindS.h which don't exist, so these statements
-must be commented out of the generated source files. Note that tckind.idl
-contains a copy of the TCKind enum in Orb.h, so if the TCKind enum ever
-changes, there will be a choice of recompiling from scratch or doing an
-extensive search and edit for code depending on this enum.
-
-Since the IDL generated source files have had to be modifed, the .idl files
-are collected in a separate "project" in the VC workspace, so source files
-are not regenerated automatically every time the IDL compiler gets rebuilt.
-The VC project names "client" and "server" mean nothing.
-
-The _i classes inherit from the POA_ classes generated by the IDL compiler,
-not from DynAny_i. This leads to some repeated code (mostly in the insert
-and get functions, the other common functions being slightly different
-for each class), but allows specialization of classes, notably DynAny_i.
-Since the basic DynAny_i instances will populate the lowest level of any
-complex DynAny, this class has been kept as lightweight as possible.
-Thus this bridge pattern has some advantages to offset the increased
-footprint, but it may be changed when the files are moved into TAO.
-
-The insert_xxx and get_xxx functions in POA_DynAny (in DynAnyS.h),
-which were generated as pure virtual, have been modified to be
-non-virtual. This is because DynEnum_i, which inherits from
-POA_DynEnum which inherits from POA_DynAny, does not override
-these functions (nor does POA_DynEnum).
-
-The file da_tests.idl contains some data structures that have been used
-for debugging (nothing yet for DynUnion). The file driver.cpp has been
-used for this debugging, and the contents of these two files are in
-flux. There is as yet no test to run.
-
-****************Some things to note about DynUnion:
-
-The spec is vague on the action of set_as_default
-and member_name and there seems to be disparity in the interpretation of
-the spec by other vendors. In this implementation, they are interpreted
-as follows:
-
-set_as_default -
- Treated as read-only, the assignment version is included to
- override the virtual function, but has an empty body. The
- fetch version returns TRUE if the DynUnion has a default
- value and that default value is the active member.
-
-member_name
- Fetch version just returns the name of the active member. The
- assignment version makes active the member with the supplied
- name (if it is valid), but does not save the previous value,
- so to be meaningful, an insert or assignment should be done
- after this operation, since the new active member will be
- uninitialized.
-
-If a non-valid label is supplied for initialization or assignment
-(in the typecode of an Any supplied to the constructor or to
-from_any, for example), and there is a default index, the member
-index will be set to the default value and the label will be stored
-in the member DynAny holding the descriminator. If there is
-not a default index, an exception will be thrown.
-
-For the DynUnion functions next(), seek() and rewind(), a new
-uninitialized member will be created and the original will be lost.
-I can't see what use these functions have when used with DynUnion,
-but a behavior has been defined. If some behavior as yet unforeseen
-turns out to be useful, these functions can always be changed.
-
-The spec calls for the seek() function to take an argument of
-type Long, which is only one of ten types that a DynUnion label
-can have, so the argument to seek() must refer to an index and
-not to a label.
diff --git a/TAO/tests/DynAny_Test/da_tests.idl b/TAO/tests/DynAny_Test/da_tests.idl
index b7f3ebe4476..a38177bcea8 100644
--- a/TAO/tests/DynAny_Test/da_tests.idl
+++ b/TAO/tests/DynAny_Test/da_tests.idl
@@ -10,10 +10,12 @@ module DynAnyTests
string str;
};
+typedef short foo;
+
struct test_struct {
- short s;
+ foo f;
double d;
- enclosed_struct es;
+// enclosed_struct es;
};
typedef sequence<enclosed_struct> test_seq;
@@ -21,10 +23,26 @@ module DynAnyTests
const unsigned long DIM = 3;
typedef long test_array [DIM];
+// typedef long twin_array [DIM];
+
enum test_enum {
- ZERO,
- ONE,
- TWO,
- THREE
+ ZEROTH,
+ FIRST,
+ SECOND,
+ THIRD
};
+
+ union test_union switch (test_enum)
+ {
+ case SECOND:
+ TypeCode tc;
+ case FIRST:
+ short s;
+ case THIRD:
+ string str;
+ case ZEROTH:
+ octet o;
+// default:
+// char c;
+ };
}; \ No newline at end of file
diff --git a/TAO/tests/DynAny_Test/driver.cpp b/TAO/tests/DynAny_Test/driver.cpp
index 7ce2fd9ffd6..420c3b20b49 100644
--- a/TAO/tests/DynAny_Test/driver.cpp
+++ b/TAO/tests/DynAny_Test/driver.cpp
@@ -13,13 +13,12 @@
//
// ============================================================================
-
-
#include "DynAny_i.h"
#include "DynStruct_i.h"
#include "DynSequence_i.h"
#include "DynArray_i.h"
#include "DynEnum_i.h"
+#include "DynUnion_i.h"
#include "da_testsC.cpp"
int main (int argc, char* argv[])
@@ -27,6 +26,32 @@ int main (int argc, char* argv[])
CORBA::Environment env;
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, 0, env);
-
+ DynAnyTests::test_union* tu;
+
+ tu->_d (DynAnyTests::SECOND);
+
+// DynAnyTests::enclosed_struct es_in;
+// tu.ts ().l = -222;
+// const char* val = "boing";
+// tu->str (val);
+
+ tu->tc (CORBA::_tc_double);
+
+ CORBA_Any a;
+ a <<= tu;
+
+// DynUnion_i du (DynAnyTests::_tc_test_union);
+ DynUnion_i du (a);
+
+// du.from_any (a, env);
+
+ CORBA_Any* a_out = du.to_any (env);
+
+ DynAnyTests::test_union* tu_out;
+// DynAnyTests::test_enum te_out;
+ *a_out >>= tu_out;
+
+ du.destroy (env);
+
return 0;
} \ No newline at end of file