00001
00002
00003 #include "tao/AnyTypeCode/Union_TypeCode_Static.h"
00004 #include "tao/AnyTypeCode/TypeCode_Case_Base_T.h"
00005 #include "tao/AnyTypeCode/Any.h"
00006 #include "tao/SystemException.h"
00007
00008 #ifndef __ACE_INLINE__
00009 # include "tao/AnyTypeCode/Union_TypeCode_Static.inl"
00010 #endif
00011
00012 #include "ace/Value_Ptr.h"
00013 #include "ace/CORBA_macros.h"
00014
00015 ACE_RCSID (AnyTypeCode,
00016 Union_TypeCode_Static,
00017 "$Id: Union_TypeCode_Static.cpp 77452 2007-02-28 10:06:24Z johnnyw $")
00018
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 bool
00023 TAO::TypeCode::Union<char const *,
00024 CORBA::TypeCode_ptr const *,
00025 TAO::TypeCode::Case<char const *,
00026 CORBA::TypeCode_ptr const *> const * const *,
00027 TAO::Null_RefCount_Policy>::tao_marshal (
00028 TAO_OutputCDR & cdr,
00029 CORBA::ULong offset) const
00030 {
00031
00032
00033
00034
00035
00036
00037 TAO_OutputCDR enc;
00038
00039
00040
00041
00042
00043
00044 offset = ACE_align_binary (offset + 4,
00045 ACE_CDR::OCTET_ALIGN);
00046
00047 bool const success =
00048 (enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))
00049 && (enc << TAO_OutputCDR::from_string (this->base_attributes_.id (), 0))
00050 && (enc << TAO_OutputCDR::from_string (this->base_attributes_.name (), 0))
00051 && marshal (enc,
00052 Traits<char const *>::get_typecode (this->discriminant_type_),
00053 offset + enc.total_length ())
00054 && (enc << this->default_index_)
00055 && (enc << this->ncases_);
00056
00057 if (!success)
00058 {
00059 return false;
00060 }
00061
00062
00063
00064 for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00065 {
00066 case_type const & c = *this->cases_[i];
00067
00068 if (!c.marshal (enc, offset))
00069 {
00070 return false;
00071 }
00072 }
00073
00074 return
00075 cdr << static_cast<CORBA::ULong> (enc.total_length ())
00076 && cdr.write_octet_array_mb (enc.begin ());
00077 }
00078
00079 void
00080 TAO::TypeCode::Union<char const *,
00081 CORBA::TypeCode_ptr const *,
00082 TAO::TypeCode::Case<char const *,
00083 CORBA::TypeCode_ptr const *> const * const *,
00084 TAO::Null_RefCount_Policy>::tao_duplicate (void)
00085 {
00086 }
00087
00088 void
00089 TAO::TypeCode::Union<char const *,
00090 CORBA::TypeCode_ptr const *,
00091 TAO::TypeCode::Case<char const *,
00092 CORBA::TypeCode_ptr const *> const * const *,
00093 TAO::Null_RefCount_Policy>::tao_release (void)
00094 {
00095 }
00096
00097 CORBA::Boolean
00098 TAO::TypeCode::Union<char const *,
00099 CORBA::TypeCode_ptr const *,
00100 TAO::TypeCode::Case<char const *,
00101 CORBA::TypeCode_ptr const *> const * const *,
00102 TAO::Null_RefCount_Policy>::equal_i (
00103 CORBA::TypeCode_ptr tc
00104 ) const
00105 {
00106
00107
00108
00109
00110
00111 CORBA::ULong const tc_count = tc->member_count ();
00112
00113 CORBA::Long tc_def = tc->default_index ();
00114
00115 if (tc_count != this->ncases_ || tc_def != this->default_index_)
00116 return false;
00117
00118
00119 CORBA::TypeCode_var tc_discriminator = tc->discriminator_type ();
00120
00121 CORBA::Boolean const equal_discriminators =
00122 Traits<char const *>::get_typecode (this->discriminant_type_)->equal (
00123 tc_discriminator.in ());
00124
00125 if (!equal_discriminators)
00126 return false;
00127
00128 for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00129 {
00130 if (this->default_index_ > -1
00131 && static_cast<CORBA::ULong> (this->default_index_) == i)
00132 {
00133
00134
00135
00136 continue;
00137 }
00138
00139 case_type const & lhs_case = *this->cases_[i];
00140
00141 bool const equal_case = lhs_case.equal (i, tc);
00142
00143 if (!equal_case)
00144 return false;
00145 }
00146
00147 return true;
00148 }
00149
00150 CORBA::Boolean
00151 TAO::TypeCode::Union<char const *,
00152 CORBA::TypeCode_ptr const *,
00153 TAO::TypeCode::Case<char const *,
00154 CORBA::TypeCode_ptr const *> const * const *,
00155 TAO::Null_RefCount_Policy>::equivalent_i (
00156 CORBA::TypeCode_ptr tc) const
00157 {
00158
00159
00160 CORBA::ULong const tc_count = tc->member_count ();
00161
00162 CORBA::Long tc_def = tc->default_index ();
00163
00164 if (tc_count != this->ncases_ || tc_def != this->default_index_)
00165 return false;
00166
00167 CORBA::TypeCode_var tc_discriminator = tc->discriminator_type ();
00168
00169 CORBA::Boolean const equiv_discriminators =
00170 Traits<char const *>::get_typecode (this->discriminant_type_)->equivalent (
00171 tc_discriminator.in ());
00172
00173 if (!equiv_discriminators)
00174 return false;
00175
00176 for (CORBA::ULong i = 0; i < this->ncases_; ++i)
00177 {
00178 if (this->default_index_ > -1
00179 && static_cast<CORBA::ULong> (this->default_index_) == i)
00180 {
00181
00182
00183
00184 continue;
00185 }
00186
00187 case_type const & lhs_case = *this->cases_[i];
00188
00189 bool const equivalent_case = lhs_case.equivalent (i, tc);
00190
00191 if (!equivalent_case)
00192 return false;
00193 }
00194
00195 return true;
00196 }
00197
00198 CORBA::TypeCode_ptr
00199 TAO::TypeCode::Union<char const *,
00200 CORBA::TypeCode_ptr const *,
00201 TAO::TypeCode::Case<char const *,
00202 CORBA::TypeCode_ptr const *> const * const *,
00203 TAO::Null_RefCount_Policy>::get_compact_typecode_i (
00204 void) const
00205 {
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 throw ::CORBA::NO_IMPLEMENT ();
00252 }
00253
00254 char const *
00255 TAO::TypeCode::Union<char const *,
00256 CORBA::TypeCode_ptr const *,
00257 TAO::TypeCode::Case<char const *,
00258 CORBA::TypeCode_ptr const *> const * const *,
00259 TAO::Null_RefCount_Policy>::id_i (
00260 void) const
00261 {
00262
00263
00264 return this->base_attributes_.id ();
00265 }
00266
00267 char const *
00268 TAO::TypeCode::Union<char const *,
00269 CORBA::TypeCode_ptr const *,
00270 TAO::TypeCode::Case<char const *,
00271 CORBA::TypeCode_ptr const *> const * const *,
00272 TAO::Null_RefCount_Policy>::name_i (void) const
00273 {
00274
00275
00276 return this->base_attributes_.name ();
00277 }
00278
00279 CORBA::ULong
00280 TAO::TypeCode::Union<char const *,
00281 CORBA::TypeCode_ptr const *,
00282 TAO::TypeCode::Case<char const *,
00283 CORBA::TypeCode_ptr const *> const * const *,
00284 TAO::Null_RefCount_Policy>::member_count_i (void) const
00285 {
00286 return this->ncases_;
00287 }
00288
00289 char const *
00290 TAO::TypeCode::Union<char const *,
00291 CORBA::TypeCode_ptr const *,
00292 TAO::TypeCode::Case<char const *,
00293 CORBA::TypeCode_ptr const *> const * const *,
00294 TAO::Null_RefCount_Policy>::member_name_i (
00295 CORBA::ULong index) const
00296 {
00297
00298
00299 if (index >= this->ncases_)
00300 throw ::CORBA::TypeCode::Bounds ();
00301
00302 return this->cases_[index]->name ();
00303 }
00304
00305 CORBA::TypeCode_ptr
00306 TAO::TypeCode::Union<char const *,
00307 CORBA::TypeCode_ptr const *,
00308 TAO::TypeCode::Case<char const *,
00309 CORBA::TypeCode_ptr const *> const * const *,
00310 TAO::Null_RefCount_Policy>::member_type_i (
00311 CORBA::ULong index) const
00312 {
00313 if (index >= this->ncases_)
00314 throw ::CORBA::TypeCode::Bounds ();
00315
00316 return CORBA::TypeCode::_duplicate (this->cases_[index]->type ());
00317 }
00318
00319 CORBA::Any *
00320 TAO::TypeCode::Union<char const *,
00321 CORBA::TypeCode_ptr const *,
00322 TAO::TypeCode::Case<char const *,
00323 CORBA::TypeCode_ptr const *> const * const *,
00324 TAO::Null_RefCount_Policy>::member_label_i (
00325 CORBA::ULong index) const
00326 {
00327 if (index >= this->ncases_)
00328 throw ::CORBA::TypeCode::Bounds ();
00329
00330
00331 if (this->default_index_ > -1
00332 && static_cast<CORBA::ULong> (this->default_index_) == index)
00333 {
00334 CORBA::Any * any = 0;
00335 ACE_NEW_THROW_EX (any,
00336 CORBA::Any,
00337 CORBA::NO_MEMORY ());
00338
00339 CORBA::Any_var safe_any (any);
00340
00341
00342 CORBA::Any::from_octet const zero_octet (0);
00343
00344
00345 (*any) <<= zero_octet;
00346
00347 return safe_any._retn ();
00348 }
00349
00350
00351 return this->cases_[index]->label ();
00352 }
00353
00354 CORBA::TypeCode_ptr
00355 TAO::TypeCode::Union<char const *,
00356 CORBA::TypeCode_ptr const *,
00357 TAO::TypeCode::Case<char const *,
00358 CORBA::TypeCode_ptr const *> const * const *,
00359 TAO::Null_RefCount_Policy>::discriminator_type_i (void) const
00360 {
00361 return
00362 CORBA::TypeCode::_duplicate (
00363 Traits<char const *>::get_typecode (this->discriminant_type_));
00364 }
00365
00366 CORBA::Long
00367 TAO::TypeCode::Union<char const *,
00368 CORBA::TypeCode_ptr const *,
00369 TAO::TypeCode::Case<char const *,
00370 CORBA::TypeCode_ptr const *> const * const *,
00371 TAO::Null_RefCount_Policy>::default_index_i (void) const
00372 {
00373 return this->default_index_;
00374 }
00375
00376 TAO_END_VERSIONED_NAMESPACE_DECL