TypeCode.cpp

Go to the documentation of this file.
00001 // $Id: TypeCode.cpp 78809 2007-07-06 10:24:12Z parsons $
00002 
00003 #include "tao/AnyTypeCode/TypeCode.h"
00004 
00005 ACE_RCSID (AnyTypeCode,
00006            TypeCode,
00007            "$Id: TypeCode.cpp 78809 2007-07-06 10:24:12Z parsons $")
00008 
00009 
00010 #if !defined (__ACE_INLINE__)
00011 # include "tao/AnyTypeCode/TypeCode.inl"
00012 #endif /* ! __ACE_INLINE__ */
00013 
00014 #include "tao/CDR.h"
00015 #include "tao/ORB_Constants.h"
00016 #include "tao/debug.h"
00017 #include "tao/SystemException.h"
00018 
00019 #include "ace/OS_NS_string.h"
00020 
00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00022 
00023 CORBA::TypeCode::~TypeCode (void)
00024 {
00025 }
00026 
00027 bool
00028 CORBA::TypeCode::tao_marshal_kind (TAO_OutputCDR & cdr) const
00029 {
00030   return cdr << this->kind_;
00031 }
00032 
00033 CORBA::Boolean
00034 CORBA::TypeCode::equal (TypeCode_ptr tc) const
00035 {
00036   if (this == tc)
00037     {
00038       return true;
00039     }
00040   else if (CORBA::is_nil (tc))
00041     {
00042       throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 13, CORBA::COMPLETED_NO);
00043     }
00044 
00045   CORBA::TCKind const tc_kind = tc->kind ();
00046 
00047   if (tc_kind != this->kind_)
00048     return false;
00049 
00050   try
00051     {
00052       char const * const tc_id = tc->id ();
00053 
00054       char const * const this_id = this->id ();
00055 
00056       if (ACE_OS::strcmp (this_id, tc_id) != 0)
00057         return false;
00058 
00059       char const * const tc_name = tc->name ();
00060 
00061       char const * const this_name = this->name ();
00062 
00063       if (ACE_OS::strcmp (this_name, tc_name) != 0)
00064         return false;
00065     }
00066   catch (const ::CORBA::TypeCode::BadKind&)
00067     {
00068       // Some TypeCodes do not support the id() and name()
00069       // operations.  Ignore the failure, and continue equality
00070       // verification using TypeCode subclass-specific techniques
00071       // below.
00072     }
00073 
00074   return this->equal_i (tc);
00075 }
00076 
00077 CORBA::Boolean
00078 CORBA::TypeCode::equivalent (TypeCode_ptr tc) const
00079 {
00080   if (this == tc)
00081     {
00082       return true;
00083     }
00084   else if (CORBA::is_nil (tc))
00085     {
00086       throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 13, CORBA::COMPLETED_NO);
00087     }
00088 
00089   CORBA::TypeCode_ptr const mutable_this =
00090     const_cast<CORBA::TypeCode_ptr> (this);
00091 
00092   CORBA::TypeCode_var unaliased_this = TAO::unaliased_typecode (mutable_this);
00093 
00094   CORBA::TypeCode_var unaliased_tc = TAO::unaliased_typecode (tc);
00095 
00096   CORBA::TCKind const this_kind = unaliased_this->kind ();
00097 
00098   CORBA::TCKind const tc_kind = unaliased_tc->kind ();
00099 
00100   if (tc_kind != this_kind)
00101     return false;
00102 
00103   try
00104     {
00105       char const * const this_id = unaliased_this->id ();
00106 
00107       char const * const tc_id = unaliased_tc->id ();
00108 
00109       if (ACE_OS::strlen (this_id) == 0
00110           || ACE_OS::strlen (tc_id) == 0)
00111         {
00112           return unaliased_this->equivalent_i (unaliased_tc.in ());
00113         }
00114       else if (ACE_OS::strcmp (this_id, tc_id) != 0)
00115         {
00116           return false;
00117         }
00118     }
00119   catch (const ::CORBA::TypeCode::BadKind&)
00120     {
00121       // Some TypeCodes do not support the id() operation.  Ignore the
00122       // failure, and continue equivalence verification using TypeCode
00123       // subclass-specific techniques.
00124       return unaliased_this->equivalent_i (unaliased_tc.in ());
00125     }
00126 
00127   return true;
00128 }
00129 
00130 char const *
00131 CORBA::TypeCode::id_i (void) const
00132 {
00133   throw ::CORBA::TypeCode::BadKind ();
00134 }
00135 
00136 char const *
00137 CORBA::TypeCode::name_i (void) const
00138 {
00139   throw ::CORBA::TypeCode::BadKind ();
00140 }
00141 
00142 CORBA::ULong
00143 CORBA::TypeCode::member_count_i (void) const
00144 {
00145   throw ::CORBA::TypeCode::BadKind ();
00146 }
00147 
00148 char const *
00149 CORBA::TypeCode::member_name_i (CORBA::ULong /* index */) const
00150 {
00151   throw ::CORBA::TypeCode::BadKind ();
00152 }
00153 
00154 CORBA::TypeCode_ptr
00155 CORBA::TypeCode::member_type_i (CORBA::ULong /* index */) const
00156 {
00157   throw ::CORBA::TypeCode::BadKind ();
00158 }
00159 
00160 CORBA::Any *
00161 CORBA::TypeCode::member_label_i (CORBA::ULong /* index */) const
00162 {
00163   throw ::CORBA::TypeCode::BadKind ();
00164 }
00165 
00166 CORBA::TypeCode_ptr
00167 CORBA::TypeCode::discriminator_type_i (void) const
00168 {
00169   throw ::CORBA::TypeCode::BadKind ();
00170 }
00171 
00172 CORBA::Long
00173 CORBA::TypeCode::default_index_i (void) const
00174 {
00175   throw ::CORBA::TypeCode::BadKind ();
00176 }
00177 
00178 CORBA::ULong
00179 CORBA::TypeCode::length_i (void) const
00180 {
00181   throw ::CORBA::TypeCode::BadKind ();
00182 }
00183 
00184 CORBA::TypeCode_ptr
00185 CORBA::TypeCode::content_type_i (void) const
00186 {
00187   throw ::CORBA::TypeCode::BadKind ();
00188 }
00189 
00190 CORBA::UShort
00191 CORBA::TypeCode::fixed_digits_i (void) const
00192 {
00193   throw ::CORBA::TypeCode::BadKind ();
00194 }
00195 
00196 CORBA::UShort
00197 CORBA::TypeCode::fixed_scale_i (void) const
00198 {
00199   throw ::CORBA::TypeCode::BadKind ();
00200 }
00201 
00202 CORBA::Visibility
00203 CORBA::TypeCode::member_visibility_i (CORBA::ULong /* index */) const
00204 {
00205   throw ::CORBA::TypeCode::BadKind ();
00206 }
00207 
00208 CORBA::ValueModifier
00209 CORBA::TypeCode::type_modifier_i (void) const
00210 {
00211   throw ::CORBA::TypeCode::BadKind ();
00212 }
00213 
00214 CORBA::TypeCode_ptr
00215 CORBA::TypeCode::concrete_base_type_i (void) const
00216 {
00217   throw ::CORBA::TypeCode::BadKind ();
00218 }
00219 
00220 // ---------------------------------------------------------------
00221 
00222 CORBA::TypeCode::Bounds::Bounds (void)
00223   : CORBA::UserException ("IDL:omg.org/CORBA/TypeCode/Bounds:1.0",
00224                           "Bounds")
00225 {
00226 }
00227 
00228 CORBA::TypeCode::Bounds*
00229 CORBA::TypeCode::Bounds::_downcast (CORBA::Exception *ex)
00230 {
00231    return dynamic_cast <CORBA::TypeCode::Bounds*> (ex);
00232 }
00233 
00234 CORBA::Exception *
00235 CORBA::TypeCode::Bounds::_alloc (void)
00236 {
00237   CORBA::Exception *retval = 0;
00238   ACE_NEW_RETURN (retval, ::CORBA::TypeCode::Bounds, 0);
00239   return retval;
00240 }
00241 
00242 CORBA::Exception *
00243 CORBA::TypeCode::Bounds::_tao_duplicate (void) const
00244 {
00245   CORBA::Exception *result;
00246   ACE_NEW_RETURN (result,
00247                   CORBA::TypeCode::Bounds (*this),
00248                   0);
00249   return result;
00250 }
00251 
00252 void
00253 CORBA::TypeCode::Bounds::_raise (void) const
00254 {
00255   throw *this;
00256 }
00257 
00258 void
00259 CORBA::TypeCode::Bounds::_tao_encode (TAO_OutputCDR &cdr) const
00260 {
00261   if (cdr << this->_rep_id ())
00262     {
00263       return;
00264     }
00265 
00266   throw ::CORBA::MARSHAL ();
00267 }
00268 
00269 void
00270 CORBA::TypeCode::Bounds::_tao_decode (TAO_InputCDR &)
00271 {
00272 }
00273 
00274 // ****************************************************************
00275 
00276 CORBA::TypeCode::BadKind::BadKind (void)
00277   : CORBA::UserException ("IDL:omg.org/CORBA/TypeCode/BadKind:1.0",
00278                           "BadKind")
00279 {
00280 }
00281 
00282 CORBA::TypeCode::BadKind*
00283 CORBA::TypeCode::BadKind::_downcast (CORBA::Exception *ex)
00284 {
00285   return dynamic_cast <CORBA::TypeCode::BadKind*> (ex);
00286 }
00287 
00288 CORBA::Exception *
00289 CORBA::TypeCode::BadKind::_tao_duplicate (void) const
00290 {
00291   CORBA::Exception *result = 0;
00292   ACE_NEW_RETURN (result,
00293                   CORBA::TypeCode::BadKind (*this),
00294                   0);
00295   return result;
00296 }
00297 
00298 void
00299 CORBA::TypeCode::BadKind::_raise (void) const
00300 {
00301   throw *this;
00302 }
00303 
00304 void
00305 CORBA::TypeCode::BadKind::_tao_encode (TAO_OutputCDR &cdr) const
00306 {
00307   if (cdr << this->_rep_id ())
00308     {
00309       return;
00310     }
00311 
00312   throw ::CORBA::MARSHAL ();
00313 }
00314 
00315 void
00316 CORBA::TypeCode::BadKind::_tao_decode (TAO_InputCDR &)
00317 {
00318 }
00319 
00320 // ---------------------------------------------------------------
00321 
00322 bool
00323 TAO::TypeCode::marshal (TAO_OutputCDR & cdr,
00324                         CORBA::TypeCode_ptr tc,
00325                         CORBA::ULong offset)
00326 {
00327   // Marshal the TypeCode TCKind and TypeCode body.
00328   //
00329   // Update the offset value in case a recursive TypeCode is being
00330   // marshaled.
00331 
00332   return
00333     tc != 0
00334     && tc->tao_marshal_kind (cdr)
00335     && tc->tao_marshal (cdr, aligned_offset (offset) + sizeof (CORBA::ULong));
00336 }
00337 
00338 CORBA::ULong
00339 TAO::TypeCode::aligned_offset (CORBA::ULong offset)
00340 {
00341   ptrdiff_t const unaligned_offset =
00342     static_cast<ptrdiff_t> (offset);
00343 
00344   return
00345     static_cast<CORBA::ULong> (ACE_align_binary (unaligned_offset,
00346                                                  ACE_CDR::LONG_ALIGN));
00347 }
00348 
00349 // ---------------------------------------------------------------
00350 
00351 CORBA::Boolean
00352 operator<< (TAO_OutputCDR & cdr,
00353             const CORBA::TypeCode_ptr tc)
00354 {
00355   return TAO::TypeCode::marshal (cdr, tc, 0);
00356 }
00357 
00358 // ---------------------------------------------------------------
00359 
00360 #if defined (GEN_OSTREAM_OPS)
00361 
00362 std::ostream &
00363 operator<< (std::ostream & strm,
00364             const CORBA::TypeCode_ptr)
00365 {
00366   return strm << "CORBA::TypeCode";
00367 }
00368 
00369 #endif /* GEN_OSTREAM_OPS */
00370 
00371 // ---------------------------------------------------------------
00372 
00373 CORBA::TypeCode_ptr
00374 TAO::unaliased_typecode (CORBA::TypeCode_ptr tc)
00375 {
00376   if (CORBA::is_nil (tc))
00377     {
00378       throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 13, CORBA::COMPLETED_NO);
00379     }
00380 
00381   CORBA::TCKind tc_kind = tc->kind ();
00382 
00383   if (tc_kind == CORBA::tk_alias)
00384     {
00385       CORBA::TypeCode_var tc_content = CORBA::TypeCode::_duplicate (tc);
00386 
00387       // Iterate until we get to the actual unaliased type.
00388       do
00389         {
00390           tc_content = tc_content->content_type ();
00391 
00392           tc_kind = tc_content->kind ();
00393         }
00394       while (tc_kind == CORBA::tk_alias);
00395 
00396       return tc_content._retn ();
00397     }
00398 
00399   return CORBA::TypeCode::_duplicate (tc);
00400 }
00401 
00402 // =========================================================
00403 
00404 // Traits specializations for CORBA::TypeCode.
00405 namespace TAO
00406 {
00407   CORBA::TypeCode_ptr
00408   Objref_Traits<CORBA::TypeCode>::duplicate (CORBA::TypeCode_ptr p)
00409   {
00410     return CORBA::TypeCode::_duplicate (p);
00411   }
00412 
00413   void
00414   Objref_Traits<CORBA::TypeCode>::release (CORBA::TypeCode_ptr p)
00415   {
00416     ::CORBA::release (p);
00417   }
00418 
00419   CORBA::TypeCode_ptr
00420   Objref_Traits<CORBA::TypeCode>::nil (void)
00421   {
00422     return CORBA::TypeCode::_nil ();
00423   }
00424 
00425   CORBA::Boolean
00426   Objref_Traits<CORBA::TypeCode>::marshal (CORBA::TypeCode_ptr p,
00427                                            TAO_OutputCDR & cdr)
00428   {
00429     return cdr << p;
00430   }
00431 
00432   void
00433   In_Object_Argument_Cloner_T<CORBA::TypeCode_ptr>::duplicate (
00434                                                 CORBA::TypeCode_ptr p)
00435   {
00436     CORBA::TypeCode::_duplicate (p);
00437   }
00438 
00439   void
00440   In_Object_Argument_Cloner_T<CORBA::TypeCode_ptr>::release (
00441                                                 CORBA::TypeCode_ptr p)
00442   {
00443     CORBA::release (p);
00444   }
00445 }
00446 
00447 // =========================================================
00448 
00449 CORBA::TCKind
00450 TAO::unaliased_kind (CORBA::TypeCode_ptr tc)
00451 {
00452   CORBA::TypeCode_var unaliased_tc = TAO::unaliased_typecode (tc);
00453 
00454   return unaliased_tc->kind ();
00455 }
00456 
00457 TAO_END_VERSIONED_NAMESPACE_DECL

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