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 48 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 56 of file Union_TypeCode.h.

Referenced by TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::equal_i(), TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::equivalent_i(), and TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::tao_marshal().


Constructor & Destructor Documentation

template<typename StringType, typename TypeCodeType, class CaseArrayType, class RefCountPolicy>
TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE 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.

00028   : ::CORBA::TypeCode (CORBA::tk_union)
00029   , RefCountPolicy ()
00030   , base_attributes_ (id, name)
00031   , discriminant_type_ (discriminant_type)
00032   , default_index_ (default_index)
00033   , ncases_ (ncases)
00034   , cases_ (cases)
00035 {
00036 }

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

Constructor used for recursive TypeCodes.

Definition at line 46 of file Union_TypeCode.inl.

00049   : ::CORBA::TypeCode (CORBA::tk_union)
00050   , RefCountPolicy ()
00051   , base_attributes_ (id)
00052   , discriminant_type_ (0)
00053   , default_index_ (-1)
00054   , ncases_ (0)
00055   , cases_ ()
00056 {
00057 }


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.

00411 {
00412   return this->default_index_;
00413 }

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.

References CORBA::TypeCode::_duplicate().

00396 {
00397   return
00398     CORBA::TypeCode::_duplicate (
00399       Traits<StringType>::get_typecode (this->discriminant_type_));
00400 }

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.

References TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::case_type, and TAO::TypeCode::Case< StringType, TypeCodeType >::equal().

00112 {
00113   // These calls shouldn't throw since CORBA::TypeCode::equal()
00114   // verified that the TCKind is the same as our's prior to invoking
00115   // this method, meaning that the CORBA::tk_union TypeCode methods
00116   // are supported.
00117 
00118   CORBA::ULong const tc_count =
00119     tc->member_count ();
00120 
00121   CORBA::Long tc_def = tc->default_index ();
00122 
00123   if (tc_count != this->ncases_
00124       || tc_def != this->default_index_)
00125     return false;
00126 
00127   // Check the discriminator type.
00128   CORBA::TypeCode_var tc_discriminator =
00129     tc->discriminator_type ();
00130 
00131   CORBA::Boolean const equal_discriminators =
00132     Traits<StringType>::get_typecode (this->discriminant_type_)->equal (
00133       tc_discriminator.in ());
00134 
00135   if (!equal_discriminators)
00136     return false;
00137 
00138   for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00139     {
00140       if (this->default_index_ > -1
00141           && static_cast<CORBA::ULong> (this->default_index_) == i)
00142         {
00143           // Don't bother checking equality of default case label.  It
00144           // will always be the zero octet (the CDR encoded value is
00145           // ignored).
00146           continue;
00147         }
00148 
00149       case_type const & lhs_case = *this->cases_[i];
00150 
00151       bool const equal_case = lhs_case.equal (i, tc);
00152 
00153       if (!equal_case)
00154         return false;
00155     }
00156 
00157   return true;
00158 }

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.

References TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::case_type, and TAO::TypeCode::Case< StringType, TypeCodeType >::equivalent().

00169 {
00170   // Perform a structural comparison, excluding the name() and
00171   // member_name() operations.
00172 
00173   CORBA::ULong const tc_count =
00174     tc->member_count ();
00175 
00176   CORBA::Long tc_def = tc->default_index ();
00177 
00178   if (tc_count != this->ncases_
00179       || tc_def != this->default_index_)
00180     return false;
00181 
00182   CORBA::TypeCode_var tc_discriminator =
00183     tc->discriminator_type ();
00184 
00185   CORBA::Boolean const equiv_discriminators =
00186     Traits<StringType>::get_typecode (this->discriminant_type_)->equivalent (
00187       tc_discriminator.in ());
00188 
00189   if (!equiv_discriminators)
00190     return false;
00191 
00192   for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00193     {
00194       if (this->default_index_ > -1
00195           && static_cast<CORBA::ULong> (this->default_index_) == i)
00196         {
00197           // Don't bother checking equality/equivalence of default
00198           // case label.  It will always be the zero octet (the CDR
00199           // encoded value is ignored).
00200           continue;
00201         }
00202 
00203       case_type const & lhs_case = *this->cases_[i];
00204 
00205       bool const equivalent_case =
00206         lhs_case.equivalent (i, tc);
00207 
00208       if (!equivalent_case)
00209         return false;
00210     }
00211 
00212   return true;
00213 }

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.

00224 {
00225 //   typedef ACE::Value_Ptr<TAO::TypeCode::Case<CORBA::String_var,
00226 //                                              CORBA::TypeCode_var> > elem_type;
00227 
00228 //   ACE_Array_Base<elem_type> tc_cases (this->ncases_);
00229 
00230 //   if (this->ncases_ > 0)
00231 //     {
00232 //       // Dynamically construct a new array of cases stripped of
00233 //       // member names.
00234 
00235 //       static char const empty_name[] = "";
00236 
00237 //       for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00238 //         {
00239 //           // Member names will be stripped, i.e. not embedded within
00240 //           // the compact TypeCode.
00241 //           tc_cases[i].name = empty_name;
00242 //           tc_cases[i].type =
00243 //             this->cases_[i]->type ()->get_compact_typecode (
00244 //              );
00245 //         }
00246 //     }
00247 
00248 //   // Create the compact union TypeCode.
00249 //   TAO_TypeCodeFactory_Adapter * adapter =
00250 //     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00251 //       TAO_ORB_Core::typecodefactory_adapter_name ());
00252 
00253 //   if (adapter == 0)
00254 //     {
00255 //       throw ::CORBA::INTERNAL ();
00256 //     }
00257 
00258 //   return
00259 //     adapter->create_union_tc (
00260 //       this->base_attributes_.id (),
00261 //       "",  /* empty name */
00262 //       Traits<StringType>::get_typecode (this->discriminant_type_),
00263 //       tc_cases,
00264 //       this->ncases_,
00265 //       this->default_index_,
00266 //       "",
00267 //       Traits<StringType>::get_typecode (this->default_case_.type)
00268 //      );
00269 
00270   throw ::CORBA::NO_IMPLEMENT ();
00271 }

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.

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

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.

00312 {
00313   return this->ncases_;
00314 }

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.

References CORBA::Any_var::_retn(), ACE_NEW_THROW_EX, and CORBA::Any::from_octet.

00359 {
00360   if (index >= this->ncases_)
00361     throw ::CORBA::TypeCode::Bounds ();
00362 
00363   // Default case.
00364   if (this->default_index_ > -1
00365       && static_cast<CORBA::ULong> (this->default_index_) == index)
00366     {
00367       CORBA::Any * any = 0;
00368       ACE_NEW_THROW_EX (any,
00369                         CORBA::Any,
00370                         CORBA::NO_MEMORY ());
00371 
00372       CORBA::Any_var safe_any (any);
00373 
00374       // Default case's label is a zero octet.
00375       CORBA::Any::from_octet const zero_octet (0);
00376 
00377       // Default case/member has a zero octet label value.
00378       (*any) <<= zero_octet;
00379 
00380       return safe_any._retn ();
00381     }
00382 
00383   // Non-default cases.
00384   return this->cases_[index]->label ();
00385 }

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.

00325 {
00326   // Ownership is retained by the TypeCode, as required by the C++
00327   // mapping.
00328   if (index >= this->ncases_)
00329     throw ::CORBA::TypeCode::Bounds ();
00330 
00331   return this->cases_[index]->name ();
00332 }

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.

References CORBA::TypeCode::_duplicate().

00343 {
00344   if (index >= this->ncases_)
00345     throw ::CORBA::TypeCode::Bounds ();
00346 
00347   return CORBA::TypeCode::_duplicate (this->cases_[index]->type ());
00348 }

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.

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

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.

00086 {
00087   this->RefCountPolicy::add_ref ();
00088 }

template<typename StringType, typename TypeCodeType, class CaseArrayType, class RefCountPolicy>
TAO_BEGIN_VERSIONED_NAMESPACE_DECL 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.

References ACE_align_binary(), ACE_OutputCDR::begin(), TAO::TypeCode::Union< StringType, TypeCodeType, CaseArrayType, RefCountPolicy >::case_type, TAO::TypeCode::Case< StringType, TypeCodeType >::marshal(), TAO_ENCAP_BYTE_ORDER, and ACE_OutputCDR::total_length().

00030 {
00031   // A tk_union TypeCode has a "complex" parameter list type (see
00032   // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of
00033   // the CORBA specification), meaning that it must be marshaled into
00034   // a CDR encapsulation.
00035 
00036   // Create a CDR encapsulation.
00037   TAO_OutputCDR enc;
00038 
00039   // Account for the encoded CDR encapsulation length and byte order.
00040   //
00041   // Aligning on an octet since the next value after the CDR
00042   // encapsulation length will always be the byte order octet/boolean
00043   // in this case.
00044   offset = ACE_align_binary (offset + 4,
00045                              ACE_CDR::OCTET_ALIGN);
00046 
00047   bool const success =
00048     (enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))
00049     && (enc << TAO_OutputCDR::from_string (this->base_attributes_.id (), 0))
00050     && (enc << TAO_OutputCDR::from_string (this->base_attributes_.name (), 0))
00051     && marshal (enc,
00052                 Traits<StringType>::get_typecode (this->discriminant_type_),
00053                 offset + enc.total_length ())
00054     && (enc << this->default_index_)
00055     && (enc << this->ncases_);
00056 
00057   if (!success)
00058     {
00059       return false;
00060     }
00061 
00062   for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00063     {
00064       case_type const & c = *this->cases_[i];
00065 
00066       if (!c.marshal (enc, offset))
00067         {
00068           return false;
00069         }
00070     }
00071 
00072   return
00073     cdr << static_cast<CORBA::ULong> (enc.total_length ())
00074     && cdr.write_octet_array_mb (enc.begin ());
00075 }

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.

00099 {
00100   this->RefCountPolicy::remove_ref ();
00101 }


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]
 

Base attributes containing repository ID and name of union type.

Definition at line 135 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 153 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 145 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 138 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 149 of file Union_TypeCode.h.


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 13:22:15 2008 for TAO_AnyTypeCode by doxygen 1.3.6