summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOssama Othman <ossama-othman@users.noreply.github.com>2004-09-26 08:22:07 +0000
committerOssama Othman <ossama-othman@users.noreply.github.com>2004-09-26 08:22:07 +0000
commitfdf4177a2ac49215b9b2e1ca3561233cc5c26a70 (patch)
treedaa32ae56592b9a5c4d7258ed57aac3b61b774eb
parent61c98059e3803fd5fd8782711862a69546f18902 (diff)
downloadATCD-fdf4177a2ac49215b9b2e1ca3561233cc5c26a70.tar.gz
*** empty log message ***
-rw-r--r--TAO/tao/TypeCode/Enum_TypeCode.cpp12
-rw-r--r--TAO/tao/TypeCode/Struct_TypeCode.cpp3
-rw-r--r--TAO/tao/TypeCode/TypeCode_Case.cpp135
-rw-r--r--TAO/tao/TypeCode/TypeCode_Case.h157
-rw-r--r--TAO/tao/TypeCode/TypeCode_Case.inl52
-rw-r--r--TAO/tao/TypeCode/TypeCode_Default_Case.cpp26
-rw-r--r--TAO/tao/TypeCode/TypeCode_Default_Case.h18
-rw-r--r--TAO/tao/TypeCode/TypeCode_Default_Case.inl3
-rw-r--r--TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp51
-rw-r--r--TAO/tao/TypeCode/TypeCode_Non_Default_Case.h18
-rw-r--r--TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl3
-rw-r--r--TAO/tao/TypeCode/Union_TypeCode.cpp94
-rw-r--r--TAO/tao/TypeCode/Union_TypeCode.h10
-rw-r--r--TAO/tao/TypeCode/Union_TypeCode.inl10
14 files changed, 376 insertions, 216 deletions
diff --git a/TAO/tao/TypeCode/Enum_TypeCode.cpp b/TAO/tao/TypeCode/Enum_TypeCode.cpp
index a3646acfb81..c67b0c71b9e 100644
--- a/TAO/tao/TypeCode/Enum_TypeCode.cpp
+++ b/TAO/tao/TypeCode/Enum_TypeCode.cpp
@@ -175,7 +175,7 @@ TAO::TypeCode::Enum<StringType,
if (this->nenumerators_ > 0)
{
- // Dynamically conenum a new array of enumerators stripped of
+ // Dynamically construct a new array of enumerators stripped of
// member names.
ACE_NEW_THROW_EX (tc_enumerators,
@@ -184,6 +184,16 @@ TAO::TypeCode::Enum<StringType,
ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
safe_enumerators.reset (enumerators);
+
+ static char const * empty_name = "";
+
+ for (CORBA::ULong i = 0; i < this->nenumerators_; ++i)
+ {
+ // Member names will be stripped, i.e. not embedded within
+ // the compact TypeCode.
+
+ tc_enumerators[i].name = empty_name;
+ }
}
TAO_TypeCodeFactory_Adapter * adapter =
diff --git a/TAO/tao/TypeCode/Struct_TypeCode.cpp b/TAO/tao/TypeCode/Struct_TypeCode.cpp
index 5248aa7a032..ddd563696d0 100644
--- a/TAO/tao/TypeCode/Struct_TypeCode.cpp
+++ b/TAO/tao/TypeCode/Struct_TypeCode.cpp
@@ -217,11 +217,14 @@ TAO::TypeCode::Struct<StringType,
safe_fields.reset (fields);
+ static char const * empty_name = "";
+
for (CORBA::ULong i = 0; i < this->nfields_; ++i)
{
// Member names will be stripped, i.e. not embedded within
// the compact TypeCode.
+ tc_fields[i].name = empty_name;
tc_fields[i].type =
&(*(this->fields_[i].type)->get_compact_typecode (
ACE_ENV_ARG_PARAMETER));
diff --git a/TAO/tao/TypeCode/TypeCode_Case.cpp b/TAO/tao/TypeCode/TypeCode_Case.cpp
index 137b00ac8a8..16ad4990110 100644
--- a/TAO/tao/TypeCode/TypeCode_Case.cpp
+++ b/TAO/tao/TypeCode/TypeCode_Case.cpp
@@ -3,92 +3,85 @@
#ifndef TAO_TYPECODE_CASE_CPP
#define TAO_TYPECODE_CASE_CPP
-#include "TypeCode_Case.h"
-
-#include "tao/CDR.h"
-#include "tao/Any.h"
+#include "TypeCode_Case_Base.h"
#ifndef __ACE_INLINE__
-# include "tao/TypeCode_Case.inl"
+# include "tao/TypeCode_Case_Base.inl"
#endif /* __ACE_INLINE__ */
-namespace TAO
-{
- namespace TypeCode
- {
- template <typename T>
- struct Case_Traits
- {
- inline static T any_from (T v)
- {
- return v;
- }
- };
-
- // Specializations for types that require wrapper for Any
- // insertion. Note that we only define specializations for types
- // that can be used in an IDL union discriminator.
-
- template <>
- struct Case_Traits<CORBA::Boolean>
- {
- inline static CORBA::Any::from_boolean any_from (CORBA::Boolean v)
- {
- return CORBA::Any::from_boolean (v);
- }
- };
-
- template <>
- struct Case_Traits<CORBA::Char>
- {
- inline static CORBA::Any::from_char any_from (CORBA::Char v)
- {
- return CORBA::Any::from_char (v);
- }
- };
-
- template <>
- struct Case_Traits<CORBA::WChar>
- {
- inline static CORBA::Any::from_wchar any_from (CORBA::WChar v)
- {
- return CORBA::Any::from_wchar (v);
- }
- };
-
- } // End TypeCode namespace
-} // End TAO namespace
-
-// ----------------------------------------------------------------
-
-template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE>
-bool
-TAO::TypeCode::Case<DISCRIMINATOR_TYPE, STRING_TYPE>::marshal_label (
- TAO_OutputCDR & cdr) const
+
+template <typename STRING_TYPE>
+char const *
+TAO::TypeCode::Case<STRING_TYPE>::~Case (void)
{
- return (cdr << this->label_);
+ if (this->type_)
+ CORBA::release (*(this->type_));
}
-template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE>
-CORBA::Any *
-TAO::TypeCode::Case<DISCRIMINATOR_TYPE, STRING_TYPE>::label (
- ACE_ENV_SINGLE_ARG_DECL) const
+template <typename STRING_TYPE>
+bool
+TAO::TypeCode::Case<STRING_TYPE>::equal (CORBA::ULong index,
+ CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const
{
- CORBA::Any * value;
+ // Check case names.
+ char const * const lhs_name = this->name ();
+ char const * const rhs_name = tc->member_name (index
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (0);
- ACE_NEW_THROW_EX (value,
- CORBA::Any,
- CORBA::NO_MEMORY ());
+ if (ACE_OS::strcmp (lhs_name, rhs_name) != 0)
+ return 0;
+
+ // Check case TypeCodes.
+ CORBA::TypeCode_ptr const lhs_tc = this->type ();
+ CORBA::TypeCode_var const rhs_tc =
+ tc->member_type (index
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
- CORBA::Any_var safe_value (value);
+ CORBA::Boolean const equal_members =
+ lhs_tc->equal (rhs_tc.in ()
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (0);
- *value <<=
- TAO::TypeCode::Case_Traits<DISCRIMINATOR_TYPE>::any_from (this->label_);
+ if (!equal_members)
+ return 0;
- return safe_value._retn ();
+ // Check case labels.
+ return this->equal_labels (index,
+ tc
+ ACE_ENV_ARG_PARAMETER);
}
+template <typename STRING_TYPE>
+bool
+TAO::TypeCode::Case<STRING_TYPE>::equivalent (CORBA::ULong index,
+ CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const
+{
+ // Member names are ignore when determining equivalence.
+
+ // Check case TypeCodes.
+ CORBA::TypeCode_ptr const lhs_tc = this->type ();
+ CORBA::TypeCode_var const rhs_tc =
+ tc->member_type (index
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (0);
+ CORBA::Boolean const equivalent_members =
+ lhs_tc->equivalent (rhs_tc.in ()
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (0);
+
+ if (!equivalent_members)
+ return 0;
+
+ // Check case labels.
+ // The labels must be equal when determining equivalence, too.
+ return this->equal_labels (index,
+ tc
+ ACE_ENV_ARG_PARAMETER);
+}
#endif /* TAO_TYPECODE_CASE_CPP */
diff --git a/TAO/tao/TypeCode/TypeCode_Case.h b/TAO/tao/TypeCode/TypeCode_Case.h
index e97e9e15f78..f57f5b3cc30 100644
--- a/TAO/tao/TypeCode/TypeCode_Case.h
+++ b/TAO/tao/TypeCode/TypeCode_Case.h
@@ -2,18 +2,18 @@
//=============================================================================
/**
- * @file TypeCode_Case.h
+ * @file TypeCode_Case_Base.h
*
* $Id$
*
- * Header file for @c TAO::TypeCode::Case type.
+ * Header file for @c TAO::TypeCode::Case_Base type.
*
* @author Ossama Othman
*/
//=============================================================================
-#ifndef TAO_TYPECODE_CASE_H
-#define TAO_TYPECODE_CASE_H
+#ifndef TAO_TYPECODE_CASE_BASE_H
+#define TAO_TYPECODE_CASE_BASE_H
#include /**/ "ace/pre.h"
@@ -23,8 +23,14 @@
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
-#include "tao/TypeCode_Case_Base.h"
+namespace CORBA
+{
+ class TypeCode;
+ typedef TypeCode* TypeCode_ptr;
+
+ class Any;
+}
namespace TAO
{
@@ -34,74 +40,101 @@ namespace TAO
/**
* @class Case
*
- * @brief Representation of an OMG IDL defined @c union @c case.
- *
- * A @c Case contains the corresponding case label value, name and
- * pointer to the @c CORBA::TypeCode for a given OMG IDL @c union
- * @c case. For
- * example, the cases in following OMG IDL @c union:
- *
- * \code
- * union Foo switch (short)
- * {
- * case 0:
- * case 1: short a;
- * case 2: long b;
- * default: octet c;
- * };
- * \endcode
- *
- * would be represented using the following statically instantiated
- * @c TAO::TypeCode::Case array:
- *
- * \code
- * TAO::TypeCode::Case<CORBA::Short, char const *> _tao_cases_Foo[] =
- * {
- * { Case<CORBA::Short, char const *> (0, "a", &CORBA::_tc_short),
- * { Case<CORBA::Short, char const *> (1, "b", &CORBA::_tc_short),
- * { Case<CORBA::Short, char const *> (2, "c", &CORBA::_tc_long)
- * };
- * \endcode
+ * @brief Abstract base class for that represents an IDL @c union
+ * case/member.
*
- * The @c default case is passed directly to the
- * @c TAO::TypeCode::Union constructor.
- *
- * The template parameter @a DISCRIMINATOR_TYPE is the
- * corresponding C++ type for the IDL defined @c union
- * discriminator type. For example, a @c union with an IDL @c
- * short discriminator will have a corresponding @c CORBA::Short
- * C++ type. This template parameter is necessary to allow the
- * actual @c case label value to be stored as its actual type,
- * which is particularly important when marshaling that value into
- * a CDR stream.
- *
- * The template parameter @a STRING_TYPE is either @c char @c
- * const @c * or @c CORBA::String_var. The latter is only used
- * when creating @c CORBA::tk_union @c TypeCode dynamically, such
- * as through the TypeCodeFactory.
+ * This class hides the actual IDL @c union member label value
+ * from the @c TAO::TypeCode::Union class by relying on a
+ * CORBA::Any return value that corresponds to the @c
+ * CORBA::TypeCode::member_label() return type. It also allows
+ * the @c TAO::TypeCode::Union class to marshal the member label
+ * values into a CDR stream without knowledge of the underlying
+ * member label values.
*/
- template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE>
- class Case : public Case_Base<STRING_TYPE>
+ template <typename STRING_TYPE>
+ class Case
{
public:
/// Constructor.
- Case (DISCRIMINATOR_TYPE member_label,
- char const * member_name,
- CORBA::TypeCode_ptr * member_type);
+ Case (char const * name,
+ CORBA::TypeCode_ptr * tc);
+
+ /// Destructor.
+ virtual ~Case (void);
/// Return the IDL @c union case label value embedded within a
/// @c CORBA::Any.
- virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const;
+ virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const = 0;
+
+ /// Get the name of the @c union case/member.
+ char const * name (void) const;
+
+ /// Get the @c CORBA::TypeCode of the @c union case/member.
+ /**
+ * @note The reference count is not manipulated by this method,
+ * i.e., ownership is retained by this class.
+ */
+ CORBA::TypeCode_ptr type (void) const;
/// Marshal this IDL @c union member into the given output CDR
/// stream.
- virtual bool marshal_label (TAO_OutputCDR & cdr) const;
+ bool marshal (TAO_OutputCDR & cdr) const;
+
+ /// Check for equality of the @c case attributes contained by this
+ /// class and the corresponding member attributes at index "@a
+ /// index" in the given @c TypeCode @a tc.
+ bool equal (CORBA::ULong index,
+ CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const;
+
+ /// Check for equivalence of the @c case attributes contained by
+ /// this class and the corresponding member attributes at index
+ /// "@a index" in the given @c TypeCode @a tc.
+ bool equivalent (CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const;
+
+ protected:
+
+ /// Marshal the IDL @c union @c case label value into the given
+ /// output CDR stream.
+ virtual bool marshal_label (TAO_OutputCDR & cdr) const = 0;
+
+ /// Verify equality of member labels.
+ /**
+ * Performing member label equality comparisons in the @c Case
+ * subclass allows us to avoid performing interpretive
+ * extraction of the value from the @c Any returned from the
+ * "right hand side" operand @c TypeCode since the @c Case
+ * subclass already knows what type and value should be
+ * extracted from the @c Any.
+ *
+ * @param index Member index of given @c TypeCode @a tc being
+ * tested.
+ * @param tc The @c TypeCode whose member "@a index" label is
+ * being tested.
+ */
+ virtual bool equal_label (CORBA::ULong index,
+ CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const = 0;
private:
- /// IDL @c union case/member label value.
- DISCRIMINATOR_TYPE const label_;
+ /// The name of the case.
+ STRING_TYPE const name_;
+
+ /// Pointer to the @c CORBA::TypeCode of the case.
+ /**
+ * A pointer to the @c CORBA::TypeCode_ptr rather than the
+ * @c CORBA::TypeCode_ptr itself is stored since that address is
+ * well-defined. We may not know the value of the @c
+ * CORBA::TypeCode_ptr when creating this @c Case statically at
+ * compile-time, hence the indirection.
+ *
+ * @note This @c TypeCode is released upon destruction of this
+ * @c Case.
+ */
+ CORBA::TypeCode_ptr * const type_;
};
@@ -110,17 +143,17 @@ namespace TAO
#ifdef __ACE_INLINE__
-# include "tao/TypeCode_Case.inl"
+# include "tao/TypeCode_Case_Base.inl"
#endif /* __ACE_INLINE__ */
#ifdef ACE_TEMPLATES_REQUIRE_SOURCE
-# include "tao/TypeCode_Case.cpp"
+# include "tao/TypeCode_Case_Base.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA
-# pragma implementation ("TypeCode_Case.cpp")
+# pragma implementation ("TypeCode_Case_Base.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
#include /**/ "ace/post.h"
-#endif /* TAO_TYPECODE_CASE_H */
+#endif /* TAO_TYPECODE_CASE_BASE_H */
diff --git a/TAO/tao/TypeCode/TypeCode_Case.inl b/TAO/tao/TypeCode/TypeCode_Case.inl
index 7a8f7e665bc..b5e23148d6b 100644
--- a/TAO/tao/TypeCode/TypeCode_Case.inl
+++ b/TAO/tao/TypeCode/TypeCode_Case.inl
@@ -2,14 +2,54 @@
//
// $Id$
-template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE>
+#include "tao/CDR.h"
+
+
+template <typename STRING_TYPE>
ACE_INLINE char const *
-TAO::TypeCode::Case<DISCRIMINATOR_TYPE, STRING_TYPE>::Case (
- DISCRIMINATOR_TYPE member_label,
+TAO::TypeCode::Case<STRING_TYPE>::Case (
char const * member_name,
CORBA::TypeCode_ptr * member_type)
- : Case_Base<STRING_TYPE> (member_name,
- member_type)
- , label_ (member_label)
+ : name_ (member_name)
+ , type_ (member_type)
+{
+}
+
+template <typename STRING_TYPE>
+ACE_INLINE char const *
+TAO::TypeCode::Case<STRING_TYPE>::name (void) const
+{
+ return this->name_;
+}
+
+template <typename STRING_TYPE>
+ACE_INLINE CORBA::TypeCode_ptr
+TAO::TypeCode::Case<STRING_TYPE>::type (void) const
+{
+ return *this->type_;
+}
+
+template <typename STRING_TYPE>
+ACE_INLINE bool
+TAO::TypeCode::Case<STRING_TYPE>::marshal (
+ TAO_OutputCDR & cdr) const
+{
+ return
+ this->marshal_label ()
+ && (cdr << this->name ())
+ && (cdr << this->type ());
+}
+
+
+// -----------------------------------------------------------------
+// Some compilers exhibit warnings about better conversion sequence
+// from a CORBA::String_var to a char const *. This member
+// specialization works around them by performing explicit
+// conversions.
+// -----------------------------------------------------------------
+
+ACE_INLINE char const *
+TAO::TypeCode::Case<CORBA::String_var>::name (void) const
{
+ return this->name_.in ();
}
diff --git a/TAO/tao/TypeCode/TypeCode_Default_Case.cpp b/TAO/tao/TypeCode/TypeCode_Default_Case.cpp
index 90fdb8732e9..8b5b3e450e4 100644
--- a/TAO/tao/TypeCode/TypeCode_Default_Case.cpp
+++ b/TAO/tao/TypeCode/TypeCode_Default_Case.cpp
@@ -35,6 +35,32 @@ TAO::TypeCode::Default_Case<STRING_TYPE>::marshal_label (
return (cdr << TAO::TypeCode::zero_octet);
}
+template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE>
+bool
+TAO::TypeCode::Default_Case<DISCRIMINATOR_TYPE,
+ STRING_TYPE>::equal_label (
+ CORBA::ULong index
+ CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const
+{
+ CORBA::Any_var const any = tc->member_label (index
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (false);
+
+
+ // Label for default case is always zero octet.
+ static CORBA::Octet const this_label = 0;
+
+ CORBA::Octet tc_label;
+ if (any.in () >>= CORBA::Any::to_octet (tc_label)
+ && this_label == tc_label)
+ {
+ return true;
+ }
+
+ return false;
+}
+
template <typename STRING_TYPE>
CORBA::Any *
TAO::TypeCode::Default_Case<STRING_TYPE>::label (
diff --git a/TAO/tao/TypeCode/TypeCode_Default_Case.h b/TAO/tao/TypeCode/TypeCode_Default_Case.h
index cc5a7b27340..362f1a7c6f9 100644
--- a/TAO/tao/TypeCode/TypeCode_Default_Case.h
+++ b/TAO/tao/TypeCode/TypeCode_Default_Case.h
@@ -47,13 +47,21 @@ namespace TAO
Default_Case (char const * member_name,
CORBA::TypeCode_ptr * member_type);
- /// Return the IDL @c union default_case label value embedded within a
- /// @c CORBA::Any.
+ /**
+ * @name @c TAO::TypeCode::Case Methods
+ *
+ * Methods required by the @c TAO::TypeCode::Case abstract base
+ * class.
+ *
+ * @see @c TAO::TypeCode::Case
+ */
+ //@{
virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const;
-
- /// Marshal this IDL @c union member into the given output CDR
- /// stream.
virtual bool marshal_label (TAO_OutputCDR & cdr) const;
+ virtual bool equal_label (CORBA::ULong index,
+ CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const;
+ //@}
};
diff --git a/TAO/tao/TypeCode/TypeCode_Default_Case.inl b/TAO/tao/TypeCode/TypeCode_Default_Case.inl
index 362655988d9..f9f6aaa4793 100644
--- a/TAO/tao/TypeCode/TypeCode_Default_Case.inl
+++ b/TAO/tao/TypeCode/TypeCode_Default_Case.inl
@@ -7,8 +7,7 @@ ACE_INLINE char const *
TAO::TypeCode::Default_Case<STRING_TYPE>::Default_Case (
char const * member_name,
CORBA::TypeCode_ptr * member_type)
- : Case_Base<STRING_TYPE> (member_name,
- member_type)
+ : Case<STRING_TYPE> (member_name, member_type)
{
}
diff --git a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp
index b6ef3d1d35b..ba451c3ad97 100644
--- a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp
+++ b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp
@@ -23,6 +23,11 @@ namespace TAO
{
return v;
}
+
+ inline static T any_to (T & v)
+ {
+ return v;
+ }
};
// Specializations for types that require wrapper for Any
@@ -36,6 +41,11 @@ namespace TAO
{
return CORBA::Any::from_boolean (v);
}
+
+ inline static CORBA::Any::to_boolean any_to (CORBA::Boolean & v)
+ {
+ return CORBA::Any::to_boolean (v);
+ }
};
template <>
@@ -45,6 +55,11 @@ namespace TAO
{
return CORBA::Any::from_char (v);
}
+
+ inline static CORBA::Any::to_char any_to (CORBA::Char & v)
+ {
+ return CORBA::Any::to_char (v);
+ }
};
template <>
@@ -54,6 +69,11 @@ namespace TAO
{
return CORBA::Any::from_wchar (v);
}
+
+ inline static CORBA::Any::to_wchar any_to (CORBA::WChar & v)
+ {
+ return CORBA::Any::to_wchar (v);
+ }
};
} // End TypeCode namespace
@@ -63,13 +83,42 @@ namespace TAO
template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE>
bool
-TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, STRING_TYPE>::marshal_label (
+TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE,
+ STRING_TYPE>::marshal_label (
TAO_OutputCDR & cdr) const
{
return (cdr << this->label_);
}
template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE>
+bool
+TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE,
+ STRING_TYPE>::equal_label (
+ CORBA::ULong index
+ CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const
+{
+ CORBA::Any_var const any = tc->member_label (index
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (false);
+
+ // The equality operator==() below is guaranteed to be defined for
+ // the discriminator type since an IDL union discriminator type must
+ // be any of the following: (1) an integer, (2) a character, (3) a
+ // boolean, or (4) an enumeration.
+
+ DISCRIMINATOR_TYPE tc_label;
+ if (any.in ()
+ >>= TAO::TypeCode::Case_Traits<DISCRIMINATOR_TYPE>::any_to (tc_label)
+ && this->label_ == tc_label)
+ {
+ return true;
+ }
+
+ return false;
+}
+
+template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE>
CORBA::Any *
TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, STRING_TYPE>::label (
ACE_ENV_SINGLE_ARG_DECL) const
diff --git a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.h b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.h
index efd6eb3a675..1a8ae547e77 100644
--- a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.h
+++ b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.h
@@ -92,13 +92,21 @@ namespace TAO
char const * member_name,
CORBA::TypeCode_ptr * member_type);
- /// Return the IDL @c union case label value embedded within a
- /// @c CORBA::Any.
+ /**
+ * @name @c TAO::TypeCode::Case Methods
+ *
+ * Methods required by the @c TAO::TypeCode::Case abstract base
+ * class.
+ *
+ * @see @c TAO::TypeCode::Case
+ */
+ //@{
virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const;
-
- /// Marshal this IDL @c union member into the given output CDR
- /// stream.
virtual bool marshal_label (TAO_OutputCDR & cdr) const;
+ virtual bool equal_label (CORBA::ULong index,
+ CORBA::TypeCode_ptr tc
+ ACE_ENV_ARG_DECL) const;
+ //@}
private:
diff --git a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl
index 1e4c69eff34..7a4dd0ab343 100644
--- a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl
+++ b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl
@@ -9,8 +9,7 @@ TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE,
DISCRIMINATOR_TYPE member_label,
char const * member_name,
CORBA::TypeCode_ptr * member_type)
- : Case_Base<STRING_TYPE> (member_name,
- member_type)
+ : Case<STRING_TYPE> (member_name, member_type)
, label_ (member_label)
{
}
diff --git a/TAO/tao/TypeCode/Union_TypeCode.cpp b/TAO/tao/TypeCode/Union_TypeCode.cpp
index ada6a299e25..9a343de8b15 100644
--- a/TAO/tao/TypeCode/Union_TypeCode.cpp
+++ b/TAO/tao/TypeCode/Union_TypeCode.cpp
@@ -23,6 +23,8 @@ TAO::TypeCode::Union<StringType,
// the CORBA specification), meaning that it must be marshaled into
// a CDR encapsulation.
+ CORBA::ULong const count = this->case_count ();
+
// Create a CDR encapsulation.
bool const success =
(cdr << TAO_ENCAP_BYTE_ORDER)
@@ -30,7 +32,7 @@ TAO::TypeCode::Union<StringType,
&& (cdr << this->base_attributes_.name ())
&& (cdr << *(this->discriminant_type_))
&& (cdr << this->default_index_)
- && (cdr << this->ncases_);
+ && (cdr << count);
if (!success)
return false;
@@ -39,11 +41,9 @@ TAO::TypeCode::Union<StringType,
// case handling is hidden behind the case_count() and case()
// methods.
- CORBA::ULong const len = this->case_count ();
-
- for (unsigned int i = 0; i < len; ++i)
+ for (unsigned int i = 0; i < count; ++i)
{
- Case const & c = this->case (i);
+ case_type const & c = this->case (i);
if (!c.marshal (cdr))
return false;
@@ -78,45 +78,48 @@ TAO::TypeCode::Union<StringType,
CORBA::TypeCode_ptr tc
ACE_ENV_ARG_DECL) const
{
- // This call shouldn't throw since CORBA::TypeCode::equal() verified
- // that the TCKind is the same as our's prior to invoking this
- // method, meaning that member_count() is supported.
+ // These calls shouldn't throw since CORBA::TypeCode::equal()
+ // verified that the TCKind is the same as our's prior to invoking
+ // this method, meaning that the CORBA::tk_union TypeCode methods
+ // are supported.
CORBA::ULong const tc_count =
tc->member_count (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
+ CORBA::Long tc_def = tc->default_index (ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (0);
+
CORBA::ULong const this_count = this->case_count ();
- if (tc_count != this_count)
+ if (tc_count != this_count
+ || tc_def != this->default_index_)
return 0;
- ............. ADD REMAINING ATTRIBUTE CHECKS ...........
-
- for (CORBA::ULong i = 0; i < this_count; ++i)
- {
- Case const & lhs_case = this->cases (i);
+ // Check the discriminator type.
+ CORBA::TypeCode_var tc_discriminator =
+ tc->discriminator_type (ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (0);
- char const * const lhs_name = lhs_case.name ();
- char const * const rhs_name = tc->member_name (i
- ACE_ENV_ARG_PARAMETER);
- ACE_CHECK_RETURN (0);
+ CORBA::Boolean const equal_discriminators =
+ (*this->discriminator_type_)->equal (tc_discriminator.in ()
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (0);
- if (ACE_OS::strcmp (lhs_name, rhs_name) != 0)
- return 0;
+ if (!equal_discriminators)
+ return 0;
- CORBA::TypeCode_ptr const lhs_tc = *(lhs_case.type);
- CORBA::TypeCode_var const rhs_tc =
- tc->member_type (i
- ACE_ENV_ARG_PARAMETER);
- ACE_CHECK_RETURN (0);
+ for (CORBA::ULong i = 0; i < this_count; ++i)
+ {
+ case_type const & lhs_case = this->case (i);
- CORBA::Boolean const equal_members =
- lhs_tc->equal (rhs_tc.in ()
- ACE_ENV_ARG_PARAMETER);
+ bool const equal_case =
+ lhs_case.equal (i,
+ tc
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
- if (!equal_members)
+ if (!equal_case)
return 0;
}
@@ -189,20 +192,15 @@ TAO::TypeCode::Union<StringType,
for (CORBA::ULong i = 0; i < this_count; ++i)
{
- .... CHECK EQUIVALENCE OF MEMBER LABELS ...
-
- CORBA::TypeCode_ptr const lhs = this->case (i).type ();
- CORBA::TypeCode_var const rhs =
- tc->member_type (i
- ACE_ENV_ARG_PARAMETER);
- ACE_CHECK_RETURN (0);
+ case_type const & lhs_case = this->case (i);
- CORBA::Boolean const equiv_members =
- lhs->equivalent (rhs.in ()
- ACE_ENV_ARG_PARAMETER);
+ bool const equivalent_case =
+ lhs_case.equivalent (i,
+ tc
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
- if (!equiv_members)
+ if (!equivalent_case)
return 0;
}
}
@@ -229,13 +227,13 @@ TAO::TypeCode::Union<StringType,
RefCountPolicy>::get_compact_typecode_i (
ACE_ENV_SINGLE_ARG_DECL) const
{
- Case * tc_cases = 0;
+ case_type * tc_cases = 0;
ACE_Auto_Array_Ptr<Case> safe_cases;
CORBA::ULong const len = this->case_count ();
-............. BUSTED ... NO DEFAULT CASE HANDLING ...
+............. BUSTED ... NO DEFAULT CASE HANDLING ... SORT OF ...
if (len > 0)
{
@@ -243,19 +241,21 @@ TAO::TypeCode::Union<StringType,
// member names.
ACE_NEW_THROW_EX (tc_cases,
- Case[len],
+ case_type[len],
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
safe_cases.reset (cases);
+ static char const * empty_name = "";
+
for (CORBA::ULong i = 0; i < len; ++i)
{
// Member names will be stripped, i.e. not embedded within
// the compact TypeCode.
-
+ tc_cases[i].name = empty_name;
tc_cases[i].type =
- &(this->cases (i).type ()->get_compact_typecode (
+ &(this->case (i).type ()->get_compact_typecode (
ACE_ENV_ARG_PARAMETER));
ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
}
@@ -275,8 +275,8 @@ TAO::TypeCode::Union<StringType,
this->kind_i (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
- tc = adapter->_tao_create_union_except_tc (........ FIX ME ....
- ACE_ENV_ARG_PARAMETER);
+ tc = adapter->_tao_create_union_tc (........ FIX ME ....
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (CORBA::TypeCode::_nil ());
(void) safe_cases.release ();
diff --git a/TAO/tao/TypeCode/Union_TypeCode.h b/TAO/tao/TypeCode/Union_TypeCode.h
index 4c0f79f7f0a..911f076c1c2 100644
--- a/TAO/tao/TypeCode/Union_TypeCode.h
+++ b/TAO/tao/TypeCode/Union_TypeCode.h
@@ -47,13 +47,13 @@ namespace TAO
{
public:
- typedef TAO::TypeCode::Case<StringType> Case;
+ typedef TAO::TypeCode::Case<StringType> case_type;
/// Constructor.
Union (char const * id,
char const * name,
CORBA::TypeCode_ptr * discriminant_type,
- Case const * cases,
+ case_type const * cases,
CORBA::ULong ncases,
CORBA::Long default_index,
char const * default_member_name,
@@ -107,14 +107,14 @@ namespace TAO
private:
/// Get pointer to the underlying @c Case array.
- Case const * cases (void) const;
+ case_type const * cases (void) const;
/// Return the number of cases in the IDL @c union, including
/// the @c default case.
CORBA::ULong case_count (void) const;
/// Return @c union case corresponding to given member (not
- /// @c Case array) index.
+ /// @c case_type array) index.
/**
* @param index The zero-based index of the @c union member,
* including the @c default case. For example, if
@@ -128,7 +128,7 @@ namespace TAO
* attempt to perform special handling for the @c default
* case by shifting the index value by one, for example.
*/
- Case const & case (CORBA::ULong index) const;
+ case_type const & case (CORBA::ULong index) const;
private:
diff --git a/TAO/tao/TypeCode/Union_TypeCode.inl b/TAO/tao/TypeCode/Union_TypeCode.inl
index 4a1915dbed4..f0dbe93daab 100644
--- a/TAO/tao/TypeCode/Union_TypeCode.inl
+++ b/TAO/tao/TypeCode/Union_TypeCode.inl
@@ -23,14 +23,6 @@ TAO::TypeCode::Union<StringType, CaseArrayType, RefCountPolicy>::Union (
}
template <typename StringType, typename CaseArrayType, class RefCountPolicy>
-ACE_INLINE TAO::TypeCode::Case<StringType> const *
-TAO::TypeCode::Union<StringType,
- CaseArrayType>::cases (void) const
-{
- return this->cases_;
-}
-
-template <typename StringType, typename CaseArrayType, class RefCountPolicy>
ACE_INLINE CORBA::ULong
TAO::TypeCode::Union<StringType,
CaseArrayType>::case_count (void) const
@@ -39,7 +31,7 @@ TAO::TypeCode::Union<StringType,
}
template <typename StringType, typename CaseArrayType, class RefCountPolicy>
-ACE_INLINE TAO::TypeCode::Union::Case const &
+ACE_INLINE TAO::TypeCode::Union::case_type const &
TAO::TypeCode::Union<StringType,
CaseArrayType>::case (CORBA::ULong index) const
{