Public Types | Public Member Functions

TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy > Class Template Reference

CORBA::TypeCode implementation for an OMG IDL union. More...

#include <Union_TypeCode.h>

Inheritance diagram for TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >:
Inheritance graph
[legend]
Collaboration diagram for TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef TAO::TypeCode::Case
< StringType, TypeCodeType > 
case_type

Public Member Functions

 Union (char const *id, char const *name, TypeCodeType const &discriminant_type, CaseArrayType const &cases, CORBA::ULong ncases, CORBA::Long default_index)
 Constructor.
 Union (CORBA::TCKind kind, char const *id)
 Constructor used for recursive TypeCodes.
TAO-specific @c CORBA::TypeCode Methods

Methods required by TAO's implementation of the CORBA::TypeCode class.

See also:
CORBA::TypeCode
virtual bool tao_marshal (TAO_OutputCDR &cdr, CORBA::ULong offset) const
 Marshal this TypeCode into a CDR output stream.
virtual void tao_duplicate (void)
 Increase the reference count on this TypeCode.
virtual void tao_release (void)
 Decrease the reference count on this object.

Protected Member Functions

@c TAO CORBA::TypeCode Template Methods

tk_union CORBA::TypeCode -specific template methods.

See also:
CORBA::TypeCode
virtual CORBA::Boolean equal_i (CORBA::TypeCode_ptr tc) const
virtual CORBA::Boolean equivalent_i (CORBA::TypeCode_ptr tc) const
virtual CORBA::TypeCode_ptr get_compact_typecode_i (void) const
virtual char const * id_i (void) const
virtual char const * name_i (void) const
virtual CORBA::ULong member_count_i (void) const
virtual char const * member_name_i (CORBA::ULong index) const
virtual CORBA::TypeCode_ptr member_type_i (CORBA::ULong index) const
virtual CORBA::Anymember_label_i (CORBA::ULong index) const
virtual CORBA::TypeCode_ptr discriminator_type_i (void) const
virtual CORBA::Long default_index_i (void) const

Protected Attributes

Base_Attributes< StringType > base_attributes_
TypeCodeType discriminant_type_
 Type of IDL union discriminant.
CORBA::Long default_index_
 Index of the default union case.
CORBA::ULong ncases_
CaseArrayType cases_

Detailed Description

template<typename StringType, typename TypeCodeType, class CaseArrayType, class RefCountPolicy>
class TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >

CORBA::TypeCode implementation for an OMG IDL union.

This class implements a CORBA::TypeCode for an OMG IDL union.

Definition at line 49 of file Union_TypeCode.h.


Member Typedef Documentation

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
typedef TAO::TypeCode::Case<StringType, TypeCodeType> TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::case_type

Definition at line 57 of file Union_TypeCode.h.


Constructor & Destructor Documentation

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::Union ( char const *  id,
char const *  name,
TypeCodeType const &  discriminant_type,
CaseArrayType const &  cases,
CORBA::ULong  ncases,
CORBA::Long  default_index 
)

Constructor.

Definition at line 15 of file Union_TypeCode.inl.

  : ::CORBA::TypeCode (CORBA::tk_union)
  , RefCountPolicy ()
  , base_attributes_ (id, name)
  , discriminant_type_ (discriminant_type)
  , default_index_ (default_index)
  , ncases_ (ncases)
  , cases_ (cases)
{
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::Union ( CORBA::TCKind  kind,
char const *  id 
)

Constructor used for recursive TypeCodes.

Definition at line 40 of file Union_TypeCode.inl.

  : ::CORBA::TypeCode (CORBA::tk_union)
  , RefCountPolicy ()
  , base_attributes_ (id)
  , discriminant_type_ (0)
  , default_index_ (-1)
  , ncases_ (0)
  , cases_ ()
{
}


Member Function Documentation

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::Long TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::default_index_i ( void   )  const [protected, virtual]

Reimplemented from CORBA::TypeCode.

Definition at line 410 of file Union_TypeCode.cpp.

{
  return this->default_index_;
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::TypeCode_ptr TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::discriminator_type_i ( void   )  const [protected, virtual]

Reimplemented from CORBA::TypeCode.

Definition at line 395 of file Union_TypeCode.cpp.

{
  return
    CORBA::TypeCode::_duplicate (
      Traits<StringType>::get_typecode (this->discriminant_type_));
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::Boolean TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::equal_i ( CORBA::TypeCode_ptr  tc  )  const [protected, virtual]

Implements CORBA::TypeCode.

Definition at line 111 of file Union_TypeCode.cpp.

{
  // 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 ();

  CORBA::Long tc_def = tc->default_index ();

  if (tc_count != this->ncases_
      || tc_def != this->default_index_)
    return false;

  // Check the discriminator type.
  CORBA::TypeCode_var tc_discriminator =
    tc->discriminator_type ();

  CORBA::Boolean const equal_discriminators =
    Traits<StringType>::get_typecode (this->discriminant_type_)->equal (
      tc_discriminator.in ());

  if (!equal_discriminators)
    return false;

  for (CORBA::ULong i = 0; i < this->ncases_; ++i)
    {
      if (this->default_index_ > -1
          && static_cast<CORBA::ULong> (this->default_index_) == i)
        {
          // Don't bother checking equality of default case label.  It
          // will always be the zero octet (the CDR encoded value is
          // ignored).
          continue;
        }

      case_type const & lhs_case = *this->cases_[i];

      bool const equal_case = lhs_case.equal (i, tc);

      if (!equal_case)
        return false;
    }

  return true;
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::Boolean TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::equivalent_i ( CORBA::TypeCode_ptr  tc  )  const [protected, virtual]

Implements CORBA::TypeCode.

Definition at line 168 of file Union_TypeCode.cpp.

{
  // Perform a structural comparison, excluding the name() and
  // member_name() operations.

  CORBA::ULong const tc_count =
    tc->member_count ();

  CORBA::Long tc_def = tc->default_index ();

  if (tc_count != this->ncases_
      || tc_def != this->default_index_)
    return false;

  CORBA::TypeCode_var tc_discriminator =
    tc->discriminator_type ();

  CORBA::Boolean const equiv_discriminators =
    Traits<StringType>::get_typecode (this->discriminant_type_)->equivalent (
      tc_discriminator.in ());

  if (!equiv_discriminators)
    return false;

  for (CORBA::ULong i = 0; i < this->ncases_; ++i)
    {
      if (this->default_index_ > -1
          && static_cast<CORBA::ULong> (this->default_index_) == i)
        {
          // Don't bother checking equality/equivalence of default
          // case label.  It will always be the zero octet (the CDR
          // encoded value is ignored).
          continue;
        }

      case_type const & lhs_case = *this->cases_[i];

      bool const equivalent_case =
        lhs_case.equivalent (i, tc);

      if (!equivalent_case)
        return false;
    }

  return true;
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::TypeCode_ptr TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::get_compact_typecode_i ( void   )  const [protected, virtual]

Implements CORBA::TypeCode.

Definition at line 223 of file Union_TypeCode.cpp.

{
//   typedef ACE::Value_Ptr<TAO::TypeCode::Case<CORBA::String_var,
//                                              CORBA::TypeCode_var> > elem_type;

//   ACE_Array_Base<elem_type> tc_cases (this->ncases_);

//   if (this->ncases_ > 0)
//     {
//       // Dynamically construct a new array of cases stripped of
//       // member names.

//       static char const empty_name[] = "";

//       for (CORBA::ULong i = 0; i < this->ncases_; ++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 (
//              );
//         }
//     }

//   // Create the compact union TypeCode.
//   TAO_TypeCodeFactory_Adapter * adapter =
//     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
//       TAO_ORB_Core::typecodefactory_adapter_name ());

//   if (adapter == 0)
//     {
//       throw ::CORBA::INTERNAL ();
//     }

//   return
//     adapter->create_union_tc (
//       this->base_attributes_.id (),
//       "",  /* empty name */
//       Traits<StringType>::get_typecode (this->discriminant_type_),
//       tc_cases,
//       this->ncases_,
//       this->default_index_,
//       "",
//       Traits<StringType>::get_typecode (this->default_case_.type)
//      );

  throw ::CORBA::NO_IMPLEMENT ();
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
char const * TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::id_i ( void   )  const [protected, virtual]

Reimplemented from CORBA::TypeCode.

Definition at line 281 of file Union_TypeCode.cpp.

{
  // Ownership is retained by the TypeCode, as required by the C++
  // mapping.
  return this->base_attributes_.id ();
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::ULong TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::member_count_i ( void   )  const [protected, virtual]

Reimplemented from CORBA::TypeCode.

Definition at line 311 of file Union_TypeCode.cpp.

{
  return this->ncases_;
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::Any * TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::member_label_i ( CORBA::ULong  index  )  const [protected, virtual]

Reimplemented from CORBA::TypeCode.

Definition at line 358 of file Union_TypeCode.cpp.

{
  if (index >= this->ncases_)
    throw ::CORBA::TypeCode::Bounds ();

  // Default case.
  if (this->default_index_ > -1
      && static_cast<CORBA::ULong> (this->default_index_) == index)
    {
      CORBA::Any * any = 0;
      ACE_NEW_THROW_EX (any,
                        CORBA::Any,
                        CORBA::NO_MEMORY ());

      CORBA::Any_var safe_any (any);

      // Default case's label is a zero octet.
      CORBA::Any::from_octet const zero_octet (0);

      // Default case/member has a zero octet label value.
      (*any) <<= zero_octet;

      return safe_any._retn ();
    }

  // Non-default cases.
  return this->cases_[index]->label ();
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
char const * TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::member_name_i ( CORBA::ULong  index  )  const [protected, virtual]

Reimplemented from CORBA::TypeCode.

Definition at line 324 of file Union_TypeCode.cpp.

{
  // Ownership is retained by the TypeCode, as required by the C++
  // mapping.
  if (index >= this->ncases_)
    throw ::CORBA::TypeCode::Bounds ();

  return this->cases_[index]->name ();
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::TypeCode_ptr TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::member_type_i ( CORBA::ULong  index  )  const [protected, virtual]

Reimplemented from CORBA::TypeCode.

Definition at line 342 of file Union_TypeCode.cpp.

{
  if (index >= this->ncases_)
    throw ::CORBA::TypeCode::Bounds ();

  return CORBA::TypeCode::_duplicate (this->cases_[index]->type ());
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
char const * TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::name_i ( void   )  const [protected, virtual]

Reimplemented from CORBA::TypeCode.

Definition at line 296 of file Union_TypeCode.cpp.

{
  // Ownership is retained by the TypeCode, as required by the C++
  // mapping.
  return this->base_attributes_.name ();
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
void TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::tao_duplicate ( void   )  [virtual]

Increase the reference count on this TypeCode.

Implements CORBA::TypeCode.

Definition at line 85 of file Union_TypeCode.cpp.

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
bool TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::tao_marshal ( TAO_OutputCDR cdr,
CORBA::ULong  offset 
) const [virtual]

Marshal this TypeCode into a CDR output stream.

Marshal this TypeCode into the cdr output CDR stream, excluding the TypeCode kind. Existing cdr contents will not be altered. The marshaled TypeCode will be appended to the given cdr CDR output stream.

Parameters:
cdr Output CDR stream into which the TypeCode will be marshaled.
offset Number of bytes currently in the output CDR stream, including the top-level TypeCode TCKind. This argument is useful for recursive TypeCodes. TypeCodes that contain other TypeCodes should pass an updated offset value to the marshaling operation for those contained TypeCodes.
Returns:
true if marshaling was successful.
Note:
This is a TAO-specific method that is not part of the standard CORBA::TypeCode interface.
If this method returns false, the contents of the cdr output CDR stream are undefined.

Implements CORBA::TypeCode.

Definition at line 27 of file Union_TypeCode.cpp.

{
  // A tk_union TypeCode has a "complex" parameter list type (see
  // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of
  // the CORBA specification), meaning that it must be marshaled into
  // a CDR encapsulation.

  // Create a CDR encapsulation.
  TAO_OutputCDR enc;

  // Account for the encoded CDR encapsulation length and byte order.
  //
  // Aligning on an octet since the next value after the CDR
  // encapsulation length will always be the byte order octet/boolean
  // in this case.
  offset = ACE_align_binary (offset + 4,
                             ACE_CDR::OCTET_ALIGN);

  bool const success =
    (enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))
    && (enc << TAO_OutputCDR::from_string (this->base_attributes_.id (), 0))
    && (enc << TAO_OutputCDR::from_string (this->base_attributes_.name (), 0))
    && marshal (enc,
                Traits<StringType>::get_typecode (this->discriminant_type_),
                offset + enc.total_length ())
    && (enc << this->default_index_)
    && (enc << this->ncases_);

  if (!success)
    {
      return false;
    }

  for (CORBA::ULong i = 0; i < this->ncases_; ++i)
    {
      case_type const & c = *this->cases_[i];

      if (!c.marshal (enc, offset))
        {
          return false;
        }
    }

  return
    cdr << static_cast<CORBA::ULong> (enc.total_length ())
    && cdr.write_octet_array_mb (enc.begin ());
}

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
void TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::tao_release ( void   )  [virtual]

Decrease the reference count on this object.

Implements CORBA::TypeCode.

Definition at line 98 of file Union_TypeCode.cpp.


Member Data Documentation

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
Base_Attributes<StringType> TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::base_attributes_ [protected]

Union Attributes

Attributes representing the structure of an OMG IDL union.

Note:
These attributes are declared in the order in which they are marshaled into a CDR stream in order to increase cache hits by improving spatial locality. Base attributes containing repository ID and name of union type.

Definition at line 130 of file Union_TypeCode.h.

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CaseArrayType TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::cases_ [protected]

Array of TAO::TypeCode::Case representing structure of the OMG IDL defined union.

Definition at line 148 of file Union_TypeCode.h.

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::Long TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::default_index_ [protected]

Index of the default union case.

This value will be -1 if no default case is found in the union.

Definition at line 140 of file Union_TypeCode.h.

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
TypeCodeType TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::discriminant_type_ [protected]

Type of IDL union discriminant.

Definition at line 133 of file Union_TypeCode.h.

template<typename StringType , typename TypeCodeType , class CaseArrayType , class RefCountPolicy >
CORBA::ULong TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::ncases_ [protected]

The number of cases in the OMG IDL union, excluding the default case.

Definition at line 144 of file Union_TypeCode.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines