00001
00002
00003 #include "tao/AnyTypeCode/Struct_TypeCode_Static.h"
00004 #include "tao/AnyTypeCode/TypeCode_Struct_Field.h"
00005 #include "tao/AnyTypeCode/TypeCode_Traits.h"
00006 #include "tao/ORB_Core.h"
00007 #include "tao/TypeCodeFactory_Adapter.h"
00008 #include "tao/CDR.h"
00009 #include "tao/SystemException.h"
00010
00011 #ifndef __ACE_INLINE__
00012 # include "tao/AnyTypeCode/Struct_TypeCode_Static.inl"
00013 #endif
00014
00015 #include "ace/Dynamic_Service.h"
00016
00017
00018 ACE_RCSID (AnyTypeCode,
00019 Struct_TypeCode_Static,
00020 "$Id: Struct_TypeCode_Static.cpp 77528 2007-03-05 11:11:05Z johnnyw $")
00021
00022
00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00024
00025 bool
00026 TAO::TypeCode::Struct<char const *,
00027 CORBA::TypeCode_ptr const *,
00028 TAO::TypeCode::Struct_Field<char const *,
00029 CORBA::TypeCode_ptr const *> const *,
00030 TAO::Null_RefCount_Policy>::tao_marshal (
00031 TAO_OutputCDR & cdr,
00032 CORBA::ULong offset) const
00033 {
00034
00035
00036
00037
00038
00039
00040 TAO_OutputCDR enc;
00041
00042
00043
00044
00045
00046
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->nfields_);
00055
00056 if (!success)
00057 return false;
00058
00059 Struct_Field<char const *, CORBA::TypeCode_ptr const *> const * const begin =
00060 &this->fields_[0];
00061 Struct_Field<char const *, CORBA::TypeCode_ptr const *> const * const end =
00062 begin + this->nfields_;
00063
00064 for (Struct_Field<char const *, CORBA::TypeCode_ptr const *> const * i =
00065 begin;
00066 i != end;
00067 ++i)
00068 {
00069 Struct_Field<char const *, CORBA::TypeCode_ptr const *> const & field =
00070 *i;
00071
00072 if (!(enc << TAO_OutputCDR::from_string (
00073 Traits<char const *>::get_string (field.name), 0))
00074 || !marshal (enc,
00075 Traits<char const *>::get_typecode (field.type),
00076 offset + enc.total_length ()))
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 void
00086 TAO::TypeCode::Struct<char const *,
00087 CORBA::TypeCode_ptr const *,
00088 TAO::TypeCode::Struct_Field<char const *,
00089 CORBA::TypeCode_ptr const *> const *,
00090 TAO::Null_RefCount_Policy>::tao_duplicate (void)
00091 {
00092 }
00093
00094 void
00095 TAO::TypeCode::Struct<char const *,
00096 CORBA::TypeCode_ptr const *,
00097 TAO::TypeCode::Struct_Field<char const *,
00098 CORBA::TypeCode_ptr const *> const *,
00099 TAO::Null_RefCount_Policy>::tao_release (void)
00100 {
00101 }
00102
00103 CORBA::Boolean
00104 TAO::TypeCode::Struct<char const *,
00105 CORBA::TypeCode_ptr const *,
00106 TAO::TypeCode::Struct_Field<char const *,
00107 CORBA::TypeCode_ptr const *> const *,
00108 TAO::Null_RefCount_Policy>::equal_i (
00109 CORBA::TypeCode_ptr tc) const
00110 {
00111
00112
00113
00114
00115 CORBA::ULong const tc_nfields =
00116 tc->member_count ();
00117
00118 if (tc_nfields != this->nfields_)
00119 return false;
00120
00121 for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00122 {
00123 Struct_Field<char const *, CORBA::TypeCode_ptr const *> const &
00124 lhs_field = this->fields_[i];
00125
00126 char const * const lhs_name =
00127 Traits<char const *>::get_string (lhs_field.name);
00128 char const * const rhs_name = tc->member_name (i
00129 );
00130
00131 if (ACE_OS::strcmp (lhs_name, rhs_name) != 0)
00132 return false;
00133
00134 CORBA::TypeCode_ptr const lhs_tc =
00135 Traits<char const *>::get_typecode (lhs_field.type);
00136 CORBA::TypeCode_var const rhs_tc =
00137 tc->member_type (i);
00138
00139 CORBA::Boolean const equal_members =
00140 lhs_tc->equal (rhs_tc.in ());
00141
00142 if (!equal_members)
00143 return false;
00144 }
00145
00146 return true;
00147 }
00148
00149 CORBA::Boolean
00150 TAO::TypeCode::Struct<char const *,
00151 CORBA::TypeCode_ptr const *,
00152 TAO::TypeCode::Struct_Field<char const *,
00153 CORBA::TypeCode_ptr const *> const *,
00154 TAO::Null_RefCount_Policy>::equivalent_i (
00155 CORBA::TypeCode_ptr tc) const
00156 {
00157
00158
00159
00160 CORBA::ULong const tc_nfields =
00161 tc->member_count ();
00162
00163 if (tc_nfields != this->nfields_)
00164 return false;
00165
00166 for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00167 {
00168 CORBA::TypeCode_ptr const lhs =
00169 Traits<char const *>::get_typecode (this->fields_[i].type);
00170 CORBA::TypeCode_var const rhs =
00171 tc->member_type (i);
00172
00173 CORBA::Boolean const equiv_members =
00174 lhs->equivalent (rhs.in ());
00175
00176 if (!equiv_members)
00177 return false;
00178 }
00179
00180 return true;
00181 }
00182
00183 CORBA::TypeCode_ptr
00184 TAO::TypeCode::Struct<char const *,
00185 CORBA::TypeCode_ptr const *,
00186 TAO::TypeCode::Struct_Field<char const *,
00187 CORBA::TypeCode_ptr const *> const *,
00188 TAO::Null_RefCount_Policy>::get_compact_typecode_i (
00189 void) const
00190 {
00191 ACE_Array_Base<Struct_Field<CORBA::String_var,
00192 CORBA::TypeCode_var> >
00193 tc_fields (this->nfields_);
00194
00195 if (this->nfields_ > 0)
00196 {
00197
00198
00199
00200 static char const empty_name[] = "";
00201
00202 for (CORBA::ULong i = 0; i < this->nfields_; ++i)
00203 {
00204
00205
00206
00207 tc_fields[i].name = empty_name;
00208 tc_fields[i].type =
00209 Traits<char const *>::get_typecode (
00210 this->fields_[i].type)->get_compact_typecode ();
00211 }
00212 }
00213
00214 TAO_TypeCodeFactory_Adapter * const adapter =
00215 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00216 TAO_ORB_Core::typecodefactory_adapter_name ());
00217
00218 if (adapter == 0)
00219 {
00220 throw ::CORBA::INTERNAL ();
00221 }
00222
00223 return
00224 adapter->create_struct_except_tc (this->kind_,
00225 this->base_attributes_.id (),
00226 "" ,
00227 tc_fields,
00228 this->nfields_);
00229 }
00230
00231 char const *
00232 TAO::TypeCode::Struct<char const *,
00233 CORBA::TypeCode_ptr const *,
00234 TAO::TypeCode::Struct_Field<char const *,
00235 CORBA::TypeCode_ptr const *> const *,
00236 TAO::Null_RefCount_Policy>::id_i (
00237 void) const
00238 {
00239
00240
00241 return this->base_attributes_.id ();
00242 }
00243
00244 char const *
00245 TAO::TypeCode::Struct<char const *,
00246 CORBA::TypeCode_ptr const *,
00247 TAO::TypeCode::Struct_Field<char const *,
00248 CORBA::TypeCode_ptr const *> const *,
00249 TAO::Null_RefCount_Policy>::name_i (void) const
00250 {
00251
00252
00253 return this->base_attributes_.name ();
00254 }
00255
00256 CORBA::ULong
00257 TAO::TypeCode::Struct<char const *,
00258 CORBA::TypeCode_ptr const *,
00259 TAO::TypeCode::Struct_Field<char const *,
00260 CORBA::TypeCode_ptr const *> const *,
00261 TAO::Null_RefCount_Policy>::member_count_i (void) const
00262 {
00263 return this->nfields_;
00264 }
00265
00266 char const *
00267 TAO::TypeCode::Struct<char const *,
00268 CORBA::TypeCode_ptr const *,
00269 TAO::TypeCode::Struct_Field<char const *,
00270 CORBA::TypeCode_ptr const *> const *,
00271 TAO::Null_RefCount_Policy>::member_name_i (
00272 CORBA::ULong index) const
00273 {
00274
00275
00276 if (index >= this->nfields_)
00277 throw ::CORBA::TypeCode::Bounds ();
00278
00279 return Traits<char const *>::get_string (this->fields_[index].name);
00280 }
00281
00282 CORBA::TypeCode_ptr
00283 TAO::TypeCode::Struct<char const *,
00284 CORBA::TypeCode_ptr const *,
00285 TAO::TypeCode::Struct_Field<char const *,
00286 CORBA::TypeCode_ptr const *> const *,
00287 TAO::Null_RefCount_Policy>::member_type_i (
00288 CORBA::ULong index) const
00289 {
00290 if (index >= this->nfields_)
00291 throw ::CORBA::TypeCode::Bounds ();
00292
00293 return
00294 CORBA::TypeCode::_duplicate (
00295 Traits<char const *>::get_typecode (this->fields_[index].type));
00296 }
00297
00298 TAO_END_VERSIONED_NAMESPACE_DECL