Value_TypeCode.cpp

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

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