Union_TypeCode_Static.cpp

Go to the documentation of this file.
00001 // $Id: Union_TypeCode_Static.cpp 77452 2007-02-28 10:06:24Z johnnyw $
00002 
00003 #include "tao/AnyTypeCode/Union_TypeCode_Static.h"
00004 #include "tao/AnyTypeCode/TypeCode_Case_Base_T.h"
00005 #include "tao/AnyTypeCode/Any.h"
00006 #include "tao/SystemException.h"
00007 
00008 #ifndef __ACE_INLINE__
00009 # include "tao/AnyTypeCode/Union_TypeCode_Static.inl"
00010 #endif  /* !__ACE_INLINE__ */
00011 
00012 #include "ace/Value_Ptr.h"
00013 #include "ace/CORBA_macros.h"
00014 
00015 ACE_RCSID (AnyTypeCode,
00016            Union_TypeCode_Static,
00017            "$Id: Union_TypeCode_Static.cpp 77452 2007-02-28 10:06:24Z johnnyw $")
00018 
00019 
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021 
00022 bool
00023 TAO::TypeCode::Union<char const *,
00024                      CORBA::TypeCode_ptr const *,
00025                      TAO::TypeCode::Case<char const *,
00026                                          CORBA::TypeCode_ptr const *> const * const *,
00027                      TAO::Null_RefCount_Policy>::tao_marshal (
00028   TAO_OutputCDR & cdr,
00029   CORBA::ULong offset) const
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<char const *>::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   // Note that we handle the default case below, too.
00063 
00064   for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00065     {
00066       case_type const & c = *this->cases_[i];
00067 
00068       if (!c.marshal (enc, offset))
00069         {
00070           return false;
00071         }
00072     }
00073 
00074   return
00075     cdr << static_cast<CORBA::ULong> (enc.total_length ())
00076     && cdr.write_octet_array_mb (enc.begin ());
00077 }
00078 
00079 void
00080 TAO::TypeCode::Union<char const *,
00081                      CORBA::TypeCode_ptr const *,
00082                      TAO::TypeCode::Case<char const *,
00083                                          CORBA::TypeCode_ptr const *> const * const *,
00084                      TAO::Null_RefCount_Policy>::tao_duplicate (void)
00085 {
00086 }
00087 
00088 void
00089 TAO::TypeCode::Union<char const *,
00090                      CORBA::TypeCode_ptr const *,
00091                      TAO::TypeCode::Case<char const *,
00092                                          CORBA::TypeCode_ptr const *> const * const *,
00093                      TAO::Null_RefCount_Policy>::tao_release (void)
00094 {
00095 }
00096 
00097 CORBA::Boolean
00098 TAO::TypeCode::Union<char const *,
00099                      CORBA::TypeCode_ptr const *,
00100                      TAO::TypeCode::Case<char const *,
00101                                          CORBA::TypeCode_ptr const *> const * const *,
00102                      TAO::Null_RefCount_Policy>::equal_i (
00103   CORBA::TypeCode_ptr tc
00104   ) const
00105 {
00106   // These calls shouldn't throw since CORBA::TypeCode::equal()
00107   // verified that the TCKind is the same as our's prior to invoking
00108   // this method, meaning that the CORBA::tk_union TypeCode methods
00109   // are supported.
00110 
00111   CORBA::ULong const tc_count = tc->member_count ();
00112 
00113   CORBA::Long tc_def = tc->default_index ();
00114 
00115   if (tc_count != this->ncases_ || tc_def != this->default_index_)
00116     return false;
00117 
00118   // Check the discriminator type.
00119   CORBA::TypeCode_var tc_discriminator = tc->discriminator_type ();
00120 
00121   CORBA::Boolean const equal_discriminators =
00122     Traits<char const *>::get_typecode (this->discriminant_type_)->equal (
00123       tc_discriminator.in ());
00124 
00125   if (!equal_discriminators)
00126     return false;
00127 
00128   for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00129     {
00130       if (this->default_index_ > -1
00131           && static_cast<CORBA::ULong> (this->default_index_) == i)
00132         {
00133           // Don't bother checking equality of default case label.  It
00134           // will always be the zero octet (the CDR encoded value is
00135           // ignored).
00136           continue;
00137         }
00138 
00139       case_type const & lhs_case = *this->cases_[i];
00140 
00141       bool const equal_case = lhs_case.equal (i, tc);
00142 
00143       if (!equal_case)
00144         return false;
00145     }
00146 
00147   return true;
00148 }
00149 
00150 CORBA::Boolean
00151 TAO::TypeCode::Union<char const *,
00152                      CORBA::TypeCode_ptr const *,
00153                      TAO::TypeCode::Case<char const *,
00154                                          CORBA::TypeCode_ptr const *> const * const *,
00155                      TAO::Null_RefCount_Policy>::equivalent_i (
00156   CORBA::TypeCode_ptr tc) const
00157 {
00158   // Perform a structural comparison, excluding the name() and
00159   // member_name() operations.
00160   CORBA::ULong const tc_count = tc->member_count ();
00161 
00162   CORBA::Long tc_def = tc->default_index ();
00163 
00164   if (tc_count != this->ncases_ || tc_def != this->default_index_)
00165     return false;
00166 
00167   CORBA::TypeCode_var tc_discriminator = tc->discriminator_type ();
00168 
00169   CORBA::Boolean const equiv_discriminators =
00170     Traits<char const *>::get_typecode (this->discriminant_type_)->equivalent (
00171       tc_discriminator.in ());
00172 
00173   if (!equiv_discriminators)
00174     return false;
00175 
00176   for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00177     {
00178       if (this->default_index_ > -1
00179           && static_cast<CORBA::ULong> (this->default_index_) == i)
00180         {
00181           // Don't bother checking equality/equivalence of default
00182           // case label.  It will always be the zero octet (the CDR
00183           // encoded value is ignored).
00184           continue;
00185         }
00186 
00187       case_type const & lhs_case = *this->cases_[i];
00188 
00189       bool const equivalent_case = lhs_case.equivalent (i, tc);
00190 
00191       if (!equivalent_case)
00192         return false;
00193     }
00194 
00195   return true;
00196 }
00197 
00198 CORBA::TypeCode_ptr
00199 TAO::TypeCode::Union<char const *,
00200                      CORBA::TypeCode_ptr const *,
00201                      TAO::TypeCode::Case<char const *,
00202                                          CORBA::TypeCode_ptr const *> const * const *,
00203                      TAO::Null_RefCount_Policy>::get_compact_typecode_i (
00204   void) const
00205 {
00206 //   typedef ACE::Value_Ptr<TAO::TypeCode::Case<CORBA::String_var,
00207 //                                              CORBA::TypeCode_var> > elem_type;
00208 
00209 //   ACE_Array_Base<elem_type> tc_cases (this->ncases_);
00210 
00211 //   if (this->ncases_ > 0)
00212 //     {
00213 //       // Dynamically construct a new array of cases stripped of
00214 //       // member names.
00215 
00216 //       static char const empty_name[] = "";
00217 
00218 //       for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00219 //         {
00220 //           // Member names will be stripped, i.e. not embedded within
00221 //           // the compact TypeCode.
00222 //           tc_cases[i].name = empty_name;
00223 //           tc_cases[i].type =
00224 //             this->cases_[i]->type ()->get_compact_typecode (
00225 //              );
00226 //         }
00227 //     }
00228 
00229 //   // Create the compact union TypeCode.
00230 //   TAO_TypeCodeFactory_Adapter * adapter =
00231 //     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00232 //       TAO_ORB_Core::typecodefactory_adapter_name ());
00233 
00234 //   if (adapter == 0)
00235 //     {
00236 //       throw ::CORBA::INTERNAL ();
00237 //     }
00238 
00239 //   return
00240 //     adapter->create_union_tc (
00241 //       this->base_attributes_.id (),
00242 //       "",  /* empty name */
00243 //       Traits<char const *>::get_typecode (this->discriminant_type_),
00244 //       tc_cases,
00245 //       this->ncases_,
00246 //       this->default_index_,
00247 //       "",
00248 //       Traits<char const *>::get_typecode (this->default_case_.type)
00249 //      );
00250 
00251   throw ::CORBA::NO_IMPLEMENT ();
00252 }
00253 
00254 char const *
00255 TAO::TypeCode::Union<char const *,
00256                      CORBA::TypeCode_ptr const *,
00257                      TAO::TypeCode::Case<char const *,
00258                                          CORBA::TypeCode_ptr const *> const * const *,
00259                      TAO::Null_RefCount_Policy>::id_i (
00260   void) const
00261 {
00262   // Ownership is retained by the TypeCode, as required by the C++
00263   // mapping.
00264   return this->base_attributes_.id ();
00265 }
00266 
00267 char const *
00268 TAO::TypeCode::Union<char const *,
00269                      CORBA::TypeCode_ptr const *,
00270                      TAO::TypeCode::Case<char const *,
00271                                          CORBA::TypeCode_ptr const *> const * const *,
00272                      TAO::Null_RefCount_Policy>::name_i (void) const
00273 {
00274   // Ownership is retained by the TypeCode, as required by the C++
00275   // mapping.
00276   return this->base_attributes_.name ();
00277 }
00278 
00279 CORBA::ULong
00280 TAO::TypeCode::Union<char const *,
00281                      CORBA::TypeCode_ptr const *,
00282                      TAO::TypeCode::Case<char const *,
00283                                          CORBA::TypeCode_ptr const *> const * const *,
00284                      TAO::Null_RefCount_Policy>::member_count_i (void) const
00285 {
00286   return this->ncases_;
00287 }
00288 
00289 char const *
00290 TAO::TypeCode::Union<char const *,
00291                      CORBA::TypeCode_ptr const *,
00292                      TAO::TypeCode::Case<char const *,
00293                                          CORBA::TypeCode_ptr const *> const * const *,
00294                      TAO::Null_RefCount_Policy>::member_name_i (
00295   CORBA::ULong index) const
00296 {
00297   // Ownership is retained by the TypeCode, as required by the C++
00298   // mapping.
00299   if (index >= this->ncases_)
00300     throw ::CORBA::TypeCode::Bounds ();
00301 
00302   return this->cases_[index]->name ();
00303 }
00304 
00305 CORBA::TypeCode_ptr
00306 TAO::TypeCode::Union<char const *,
00307                      CORBA::TypeCode_ptr const *,
00308                      TAO::TypeCode::Case<char const *,
00309                                          CORBA::TypeCode_ptr const *> const * const *,
00310                      TAO::Null_RefCount_Policy>::member_type_i (
00311   CORBA::ULong index) const
00312 {
00313   if (index >= this->ncases_)
00314     throw ::CORBA::TypeCode::Bounds ();
00315 
00316   return CORBA::TypeCode::_duplicate (this->cases_[index]->type ());
00317 }
00318 
00319 CORBA::Any *
00320 TAO::TypeCode::Union<char const *,
00321                      CORBA::TypeCode_ptr const *,
00322                      TAO::TypeCode::Case<char const *,
00323                                          CORBA::TypeCode_ptr const *> const * const *,
00324                      TAO::Null_RefCount_Policy>::member_label_i (
00325   CORBA::ULong index) const
00326 {
00327   if (index >= this->ncases_)
00328     throw ::CORBA::TypeCode::Bounds ();
00329 
00330   // Default case.
00331   if (this->default_index_ > -1
00332       && static_cast<CORBA::ULong> (this->default_index_) == index)
00333     {
00334       CORBA::Any * any = 0;
00335       ACE_NEW_THROW_EX (any,
00336                         CORBA::Any,
00337                         CORBA::NO_MEMORY ());
00338 
00339       CORBA::Any_var safe_any (any);
00340 
00341       // Default case's label is a zero octet.
00342       CORBA::Any::from_octet const zero_octet (0);
00343 
00344       // Default case/member has a zero octet label value.
00345       (*any) <<= zero_octet;
00346 
00347       return safe_any._retn ();
00348     }
00349 
00350   // Non-default cases.
00351   return this->cases_[index]->label ();
00352 }
00353 
00354 CORBA::TypeCode_ptr
00355 TAO::TypeCode::Union<char const *,
00356                      CORBA::TypeCode_ptr const *,
00357                      TAO::TypeCode::Case<char const *,
00358                                          CORBA::TypeCode_ptr const *> const * const *,
00359                      TAO::Null_RefCount_Policy>::discriminator_type_i (void) const
00360 {
00361   return
00362     CORBA::TypeCode::_duplicate (
00363       Traits<char const *>::get_typecode (this->discriminant_type_));
00364 }
00365 
00366 CORBA::Long
00367 TAO::TypeCode::Union<char const *,
00368                      CORBA::TypeCode_ptr const *,
00369                      TAO::TypeCode::Case<char const *,
00370                                          CORBA::TypeCode_ptr const *> const * const *,
00371                      TAO::Null_RefCount_Policy>::default_index_i (void) const
00372 {
00373   return this->default_index_;
00374 }
00375 
00376 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:21:07 2008 for TAO_AnyTypeCode by doxygen 1.3.6