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