TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, RefCountPolicy > Class Template Reference

CORBA::TypeCode implementation for an OMG IDL struct or exception. More...

#include <Struct_TypeCode.h>

Inheritance diagram for TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, RefCountPolicy >:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Struct (CORBA::TCKind kind, char const *id, char const *name, FieldArrayType const &fields, CORBA::ULong nfields)
 Constructor.

 Struct (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_struct or tk_except 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

Protected Attributes

Base_Attributes< StringType > base_attributes_
CORBA::ULong nfields_
 The number of fields in the OMG IDL structure.

FieldArrayType fields_

Detailed Description

template<typename StringType, typename TypeCodeType, class FieldArrayType, class RefCountPolicy>
class TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, RefCountPolicy >

CORBA::TypeCode implementation for an OMG IDL struct or exception.

This class implements a CORBA::TypeCode for an OMG IDL struct or exception.

Definition at line 51 of file Struct_TypeCode.h.


Constructor & Destructor Documentation

template<typename StringType, typename TypeCodeType, class FieldArrayType, class RefCountPolicy>
TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, RefCountPolicy >::Struct CORBA::TCKind  kind,
char const *  id,
char const *  name,
FieldArrayType const &  fields,
CORBA::ULong  nfields
 

Constructor.

Definition at line 15 of file Struct_TypeCode.inl.

00021   : ::CORBA::TypeCode (kind)
00022   , RefCountPolicy ()
00023   , base_attributes_ (id, name)
00024   , nfields_ (nfields)
00025   , fields_ (fields)
00026 {
00027 }

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

Constructor used for recursive TypeCodes.

Definition at line 37 of file Struct_TypeCode.inl.

00040   : ::CORBA::TypeCode (kind)
00041   , RefCountPolicy ()
00042   , base_attributes_ (id)
00043   , nfields_ (0)
00044   , fields_ ()
00045 {
00046   // CORBA::tk_except is not allowed in the recursive TypeCode case.
00047   // ACE_ASSERT (kind == CORBA::tk_struct);
00048 }


Member Function Documentation

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

Implements CORBA::TypeCode.

Definition at line 114 of file Struct_TypeCode.cpp.

References TAO::TypeCode::Struct_Field< StringType, TypeCodeType >::name, ACE_OS::strcmp(), and TAO::TypeCode::Struct_Field< StringType, TypeCodeType >::type.

00115 {
00116   // This call shouldn't throw since CORBA::TypeCode::equal() verified
00117   // that the TCKind is the same as our's prior to invoking this
00118   // method, meaning that member_count() is supported.
00119 
00120   CORBA::ULong const tc_nfields =
00121     tc->member_count ();
00122 
00123   if (tc_nfields != this->nfields_)
00124     return false;
00125 
00126   for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00127     {
00128       Struct_Field<StringType, TypeCodeType> const & lhs_field =
00129         this->fields_[i];
00130 
00131       char const * const lhs_name =
00132         Traits<StringType>::get_string (lhs_field.name);
00133       char const * const rhs_name = tc->member_name (i);
00134 
00135       if (ACE_OS::strcmp (lhs_name, rhs_name) != 0)
00136         return false;
00137 
00138       CORBA::TypeCode_ptr const lhs_tc =
00139         Traits<StringType>::get_typecode (lhs_field.type);
00140       CORBA::TypeCode_var const rhs_tc =
00141         tc->member_type (i);
00142 
00143       CORBA::Boolean const equal_members =
00144         lhs_tc->equal (rhs_tc.in ());
00145 
00146       if (!equal_members)
00147         return false;
00148     }
00149 
00150   return true;
00151 }

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

Implements CORBA::TypeCode.

Definition at line 161 of file Struct_TypeCode.cpp.

00163 {
00164   // Perform a structural comparison, excluding the name() and
00165   // member_name() operations.
00166 
00167   CORBA::ULong const tc_nfields =
00168     tc->member_count ();
00169 
00170   if (tc_nfields != this->nfields_)
00171     return false;
00172 
00173   for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00174     {
00175       CORBA::TypeCode_ptr const lhs =
00176         Traits<StringType>::get_typecode (this->fields_[i].type);
00177       CORBA::TypeCode_var const rhs =
00178         tc->member_type (i);
00179 
00180       CORBA::Boolean const equiv_members =
00181         lhs->equivalent (rhs.in ());
00182 
00183       if (!equiv_members)
00184         return false;
00185     }
00186 
00187   return true;
00188 }

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

Implements CORBA::TypeCode.

Definition at line 198 of file Struct_TypeCode.cpp.

References TAO_TypeCodeFactory_Adapter::create_struct_except_tc(), and ACE_Dynamic_Service< TYPE >::instance().

00199 {
00200   ACE_Array_Base<Struct_Field<CORBA::String_var,
00201                               CORBA::TypeCode_var> >
00202     tc_fields (this->nfields_);
00203 
00204   if (this->nfields_ > 0)
00205     {
00206       // Dynamically construct a new array of fields stripped of
00207       // member names.
00208 
00209       static char const empty_name[] = "";
00210 
00211       for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00212         {
00213           // Member names will be stripped, i.e. not embedded within
00214           // the compact TypeCode.
00215 
00216           tc_fields[i].name = empty_name;
00217           tc_fields[i].type =
00218             Traits<StringType>::get_typecode (
00219               this->fields_[i].type)->get_compact_typecode ();
00220         }
00221     }
00222 
00223   TAO_TypeCodeFactory_Adapter * const adapter =
00224     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00225       TAO_ORB_Core::typecodefactory_adapter_name ());
00226 
00227   if (adapter == 0)
00228     {
00229       throw ::CORBA::INTERNAL ();
00230     }
00231 
00232   return
00233     adapter->create_struct_except_tc (this->kind_,
00234                                       this->base_attributes_.id (),
00235                                       ""  /* empty name */,
00236                                       tc_fields,
00237                                       this->nfields_);
00238 }

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

Reimplemented from CORBA::TypeCode.

Definition at line 248 of file Struct_TypeCode.cpp.

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

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

Reimplemented from CORBA::TypeCode.

Definition at line 278 of file Struct_TypeCode.cpp.

00279 {
00280   return this->nfields_;
00281 }

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

Reimplemented from CORBA::TypeCode.

Definition at line 291 of file Struct_TypeCode.cpp.

00293 {
00294   // Ownership is retained by the TypeCode, as required by the C++
00295   // mapping.
00296   if (index >= this->nfields_)
00297     throw ::CORBA::TypeCode::Bounds ();
00298 
00299   return Traits<StringType>::get_string (this->fields_[index].name);
00300 }

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

Reimplemented from CORBA::TypeCode.

Definition at line 310 of file Struct_TypeCode.cpp.

References CORBA::TypeCode::_duplicate().

00312 {
00313   if (index >= this->nfields_)
00314     throw ::CORBA::TypeCode::Bounds ();
00315 
00316   return
00317     CORBA::TypeCode::_duplicate (
00318       Traits<StringType>::get_typecode (this->fields_[index].type));
00319 }

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

Reimplemented from CORBA::TypeCode.

Definition at line 263 of file Struct_TypeCode.cpp.

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

template<typename StringType, typename TypeCodeType, class FieldArrayType, class RefCountPolicy>
void TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, RefCountPolicy >::tao_duplicate void   )  [virtual]
 

Increase the reference count on this TypeCode.

Implements CORBA::TypeCode.

Definition at line 88 of file Struct_TypeCode.cpp.

00089 {
00090   this->RefCountPolicy::add_ref ();
00091 }

template<typename StringType, typename TypeCodeType, class FieldArrayType, class RefCountPolicy>
TAO_BEGIN_VERSIONED_NAMESPACE_DECL bool TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, 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 30 of file Struct_TypeCode.cpp.

References ACE_align_binary(), ACE_OutputCDR::begin(), TAO::TypeCode::Struct_Field< StringType, TypeCodeType >::name, TAO_ENCAP_BYTE_ORDER, ACE_OutputCDR::total_length(), and TAO::TypeCode::Struct_Field< StringType, TypeCodeType >::type.

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

template<typename StringType, typename TypeCodeType, class FieldArrayType, class RefCountPolicy>
void TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, RefCountPolicy >::tao_release void   )  [virtual]
 

Decrease the reference count on this object.

Implements CORBA::TypeCode.

Definition at line 101 of file Struct_TypeCode.cpp.

00102 {
00103   this->RefCountPolicy::remove_ref ();
00104 }


Member Data Documentation

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

Base attributes containing repository ID and name of structure type.

Definition at line 118 of file Struct_TypeCode.h.

template<typename StringType, typename TypeCodeType, class FieldArrayType, class RefCountPolicy>
FieldArrayType TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, RefCountPolicy >::fields_ [protected]
 

Array of TAO::TypeCode fields representing structure of the OMG IDL defined struct.

Definition at line 125 of file Struct_TypeCode.h.

template<typename StringType, typename TypeCodeType, class FieldArrayType, class RefCountPolicy>
CORBA::ULong TAO::TypeCode::Struct< StringType, TypeCodeType, FieldArrayType, RefCountPolicy >::nfields_ [protected]
 

The number of fields in the OMG IDL structure.

Definition at line 121 of file Struct_TypeCode.h.


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