Value_TypeCode_Static.cpp

Go to the documentation of this file.
00001 // $Id: Value_TypeCode_Static.cpp 76995 2007-02-11 12:51:42Z johnnyw $
00002 
00003 #include "tao/AnyTypeCode/Value_TypeCode_Static.h"
00004 #include "tao/AnyTypeCode/TypeCode_Value_Field.h"
00005 #include "tao/CDR.h"
00006 
00007 #include "tao/ORB_Core.h"
00008 #include "tao/TypeCodeFactory_Adapter.h"
00009 #include "tao/SystemException.h"
00010 
00011 #include "ace/Dynamic_Service.h"
00012 
00013 #ifndef __ACE_INLINE__
00014 # include "tao/AnyTypeCode/Value_TypeCode_Static.inl"
00015 #endif  /* !__ACE_INLINE__ */
00016 
00017 
00018 ACE_RCSID (AnyTypeCode,
00019            Value_TypeCode_Static,
00020            "$Id: Value_TypeCode_Static.cpp 76995 2007-02-11 12:51:42Z johnnyw $")
00021 
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 bool
00025 TAO::TypeCode::Value<char const *,
00026                      CORBA::TypeCode_ptr const *,
00027                      TAO::TypeCode::Value_Field<char const *,
00028                                                 CORBA::TypeCode_ptr const *> const *,
00029                      TAO::Null_RefCount_Policy>::tao_marshal (
00030   TAO_OutputCDR & cdr,
00031   CORBA::ULong offset) const
00032 {
00033   // A tk_value 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->type_modifier_)
00054     && marshal (enc,
00055                 Traits<char const *>::get_typecode (this->concrete_base_),
00056                 offset + enc.total_length ())
00057     && (enc << this->nfields_);
00058 
00059   if (!success)
00060     return false;
00061 
00062   Value_Field<char const *, CORBA::TypeCode_ptr const *> const * const begin =
00063     &this->fields_[0];
00064   Value_Field<char const *, CORBA::TypeCode_ptr const *> const * const end =
00065     begin + this->nfields_;
00066 
00067   for (Value_Field<char const *, CORBA::TypeCode_ptr const *> const * i =
00068          begin;
00069        i != end;
00070        ++i)
00071     {
00072       Value_Field<char const *, CORBA::TypeCode_ptr const *> const & field = *i;
00073 
00074       if (!(enc << Traits<char const *>::get_string (field.name))
00075           || !marshal (enc,
00076                        Traits<char const *>::get_typecode (field.type),
00077                        offset + enc.total_length ())
00078           || !(enc << field.visibility))
00079         return false;
00080     }
00081 
00082   return
00083     cdr << static_cast<CORBA::ULong> (enc.total_length ())
00084     && cdr.write_octet_array_mb (enc.begin ());
00085 }
00086 
00087 void
00088 TAO::TypeCode::Value<char const *,
00089                      CORBA::TypeCode_ptr const *,
00090                      TAO::TypeCode::Value_Field<char const *,
00091                                                 CORBA::TypeCode_ptr const *> const *,
00092                      TAO::Null_RefCount_Policy>::tao_duplicate (void)
00093 {
00094 }
00095 
00096 void
00097 TAO::TypeCode::Value<char const *,
00098                      CORBA::TypeCode_ptr const *,
00099                      TAO::TypeCode::Value_Field<char const *,
00100                                                 CORBA::TypeCode_ptr const *> const *,
00101                      TAO::Null_RefCount_Policy>::tao_release (void)
00102 {
00103 }
00104 
00105 CORBA::Boolean
00106 TAO::TypeCode::Value<char const *,
00107                      CORBA::TypeCode_ptr const *,
00108                      TAO::TypeCode::Value_Field<char const *,
00109                                                 CORBA::TypeCode_ptr const *> const *,
00110                      TAO::Null_RefCount_Policy>::equal_i (
00111   CORBA::TypeCode_ptr tc) const
00112 {
00113   // None of these calls should throw since CORBA::TypeCode::equal()
00114   // verified that the TCKind is the same as our's prior to invoking
00115   // this method.
00116 
00117   CORBA::ValueModifier const tc_type_modifier =
00118     tc->type_modifier ();
00119 
00120   if (tc_type_modifier != this->type_modifier_)
00121     return false;
00122 
00123   CORBA::TypeCode_var rhs_concrete_base_type = tc->concrete_base_type ();
00124 
00125   CORBA::Boolean const equal_concrete_base_types =
00126     this->equal (rhs_concrete_base_type.in ());
00127 
00128   if (!equal_concrete_base_types)
00129     return false;
00130 
00131   CORBA::ULong const tc_nfields = tc->member_count ();
00132 
00133   if (tc_nfields != this->nfields_)
00134     return false;
00135 
00136   for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00137     {
00138       Value_Field<char const *, CORBA::TypeCode_ptr const *> const & lhs_field =
00139         this->fields_[i];
00140 
00141       CORBA::Visibility const lhs_visibility = lhs_field.visibility;
00142       CORBA::Visibility const rhs_visibility = tc->member_visibility (i);
00143 
00144       if (lhs_visibility != rhs_visibility)
00145         return false;
00146 
00147       char const * const lhs_name =
00148         Traits<char const *>::get_string (lhs_field.name);;
00149       char const * const rhs_name = tc->member_name (i);
00150 
00151       if (ACE_OS::strcmp (lhs_name, rhs_name) != 0)
00152         return false;
00153 
00154       CORBA::TypeCode_ptr const lhs_tc =
00155         Traits<char const *>::get_typecode (lhs_field.type);
00156       CORBA::TypeCode_var const rhs_tc =
00157         tc->member_type (i);
00158 
00159       CORBA::Boolean const equal_members =
00160         lhs_tc->equal (rhs_tc.in ());
00161 
00162       if (!equal_members)
00163         return false;
00164     }
00165 
00166   return true;
00167 }
00168 
00169 CORBA::Boolean
00170 TAO::TypeCode::Value<char const *,
00171                      CORBA::TypeCode_ptr const *,
00172                      TAO::TypeCode::Value_Field<char const *,
00173                                                 CORBA::TypeCode_ptr const *> const *,
00174                      TAO::Null_RefCount_Policy>::equivalent_i (
00175   CORBA::TypeCode_ptr tc) const
00176 {
00177   CORBA::ValueModifier const tc_type_modifier = tc->type_modifier ();
00178 
00179   if (tc_type_modifier != this->type_modifier_)
00180     return false;
00181 
00182   CORBA::TypeCode_var rhs_concrete_base_type = tc->concrete_base_type ();
00183 
00184   CORBA::Boolean const equivalent_concrete_base_types =
00185     this->equivalent (rhs_concrete_base_type.in ());
00186 
00187   if (!equivalent_concrete_base_types)
00188     return false;
00189 
00190   // Perform a structural comparison, excluding the name() and
00191   // member_name() operations.
00192 
00193   CORBA::ULong const tc_nfields = tc->member_count ();
00194 
00195   if (tc_nfields != this->nfields_)
00196     return false;
00197 
00198   for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00199     {
00200       Value_Field<char const *,
00201                   CORBA::TypeCode_ptr const *> const & lhs_field =
00202         this->fields_[i];
00203 
00204       CORBA::Visibility const lhs_visibility = lhs_field.visibility;
00205       CORBA::Visibility const rhs_visibility = tc->member_visibility (i);
00206 
00207       if (lhs_visibility != rhs_visibility)
00208         return false;
00209 
00210       CORBA::TypeCode_ptr const lhs_tc =
00211         Traits<char const *>::get_typecode (lhs_field.type);
00212       CORBA::TypeCode_var const rhs_tc = tc->member_type (i);
00213 
00214       CORBA::Boolean const equiv_types = lhs_tc->equivalent (rhs_tc.in ());
00215 
00216       if (!equiv_types)
00217         return false;
00218     }
00219 
00220   return true;
00221 }
00222 
00223 CORBA::TypeCode_ptr
00224 TAO::TypeCode::Value<char const *,
00225                      CORBA::TypeCode_ptr const *,
00226                      TAO::TypeCode::Value_Field<char const *,
00227                                                 CORBA::TypeCode_ptr const *> const *,
00228                      TAO::Null_RefCount_Policy>::get_compact_typecode_i (
00229   void) const
00230 {
00231   ACE_Array_Base<Value_Field<CORBA::String_var, CORBA::TypeCode_var> >
00232     tc_fields (this->nfields_);
00233 
00234   if (this->nfields_ > 0)
00235     {
00236       // Dynamically construct a new array of fields stripped of
00237       // member names.
00238 
00239       static char const empty_name[] = "";
00240 
00241       for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00242         {
00243           // Member names will be stripped, i.e. not embedded within
00244           // the compact TypeCode.
00245 
00246           tc_fields[i].name = empty_name;
00247           tc_fields[i].type =
00248             Traits<char const *>::get_typecode (
00249               this->fields_[i].type)->get_compact_typecode (
00250                 );
00251           tc_fields[i].visibility = this->fields_[i].visibility;
00252         }
00253     }
00254 
00255   TAO_TypeCodeFactory_Adapter * const adapter =
00256     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00257       TAO_ORB_Core::typecodefactory_adapter_name ());
00258 
00259   if (adapter == 0)
00260     {
00261       throw ::CORBA::INTERNAL ();
00262     }
00263 
00264   return
00265     adapter->create_value_event_tc (
00266       this->kind_,
00267       this->base_attributes_.id (),
00268       "", // empty name
00269       this->type_modifier_,
00270       Traits<char const *>::get_typecode (this->concrete_base_),
00271       tc_fields,
00272       this->nfields_
00273      );
00274 }
00275 
00276 char const *
00277 TAO::TypeCode::Value<char const *,
00278                      CORBA::TypeCode_ptr const *,
00279                      TAO::TypeCode::Value_Field<char const *,
00280                                                 CORBA::TypeCode_ptr const *> const *,
00281                      TAO::Null_RefCount_Policy>::id_i (void) const
00282 {
00283   // Ownership is retained by the TypeCode, as required by the C++
00284   // mapping.
00285   return this->base_attributes_.id ();
00286 }
00287 
00288 char const *
00289 TAO::TypeCode::Value<char const *,
00290                      CORBA::TypeCode_ptr const *,
00291                      TAO::TypeCode::Value_Field<char const *,
00292                                                 CORBA::TypeCode_ptr const *> const *,
00293                      TAO::Null_RefCount_Policy>::name_i (void) const
00294 {
00295   // Ownership is retained by the TypeCode, as required by the C++
00296   // mapping.
00297   return this->base_attributes_.name ();
00298 }
00299 
00300 CORBA::ULong
00301 TAO::TypeCode::Value<char const *,
00302                      CORBA::TypeCode_ptr const *,
00303                      TAO::TypeCode::Value_Field<char const *,
00304                                                 CORBA::TypeCode_ptr const *> const *,
00305                      TAO::Null_RefCount_Policy>::member_count_i (void) const
00306 {
00307   return this->nfields_;
00308 }
00309 
00310 char const *
00311 TAO::TypeCode::Value<char const *,
00312                      CORBA::TypeCode_ptr const *,
00313                      TAO::TypeCode::Value_Field<char const *,
00314                                                 CORBA::TypeCode_ptr const *> const *,
00315                      TAO::Null_RefCount_Policy>::member_name_i (
00316   CORBA::ULong index) const
00317 {
00318   // Ownership is retained by the TypeCode, as required by the C++
00319   // mapping.
00320   if (index >= this->nfields_)
00321     throw ::CORBA::TypeCode::Bounds ();
00322 
00323   return Traits<char const *>::get_string (this->fields_[index].name);
00324 }
00325 
00326 CORBA::TypeCode_ptr
00327 TAO::TypeCode::Value<char const *,
00328                      CORBA::TypeCode_ptr const *,
00329                      TAO::TypeCode::Value_Field<char const *,
00330                                                 CORBA::TypeCode_ptr const *> const *,
00331                      TAO::Null_RefCount_Policy>::member_type_i (
00332   CORBA::ULong index) const
00333 {
00334   if (index >= this->nfields_)
00335     throw ::CORBA::TypeCode::Bounds ();
00336 
00337   return
00338     CORBA::TypeCode::_duplicate (
00339       Traits<char const *>::get_typecode (this->fields_[index].type));
00340 }
00341 
00342 CORBA::Visibility
00343 TAO::TypeCode::Value<char const *,
00344                      CORBA::TypeCode_ptr const *,
00345                      TAO::TypeCode::Value_Field<char const *,
00346                                                 CORBA::TypeCode_ptr const *> const *,
00347                      TAO::Null_RefCount_Policy>::member_visibility_i (
00348   CORBA::ULong index) const
00349 {
00350   if (index >= this->nfields_)
00351     throw ::CORBA::TypeCode::Bounds ();
00352 
00353   return this->fields_[index].visibility;
00354 }
00355 
00356 CORBA::ValueModifier
00357 TAO::TypeCode::Value<char const *,
00358                      CORBA::TypeCode_ptr const *,
00359                      TAO::TypeCode::Value_Field<char const *,
00360                                                 CORBA::TypeCode_ptr const *> const *,
00361                      TAO::Null_RefCount_Policy>::type_modifier_i (void) const
00362 {
00363   return this->type_modifier_;
00364 }
00365 
00366 CORBA::TypeCode_ptr
00367 TAO::TypeCode::Value<char const *,
00368                      CORBA::TypeCode_ptr const *,
00369                      TAO::TypeCode::Value_Field<char const *,
00370                                                 CORBA::TypeCode_ptr const *> const *,
00371                      TAO::Null_RefCount_Policy>::concrete_base_type_i (
00372   void) const
00373 {
00374   return
00375     CORBA::TypeCode::_duplicate (
00376       Traits<char const *>::get_typecode (this->concrete_base_));
00377 }
00378 
00379 TAO_END_VERSIONED_NAMESPACE_DECL

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