Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / AnyTypeCode / TypeCode.cpp
blob15de05e890b682640f6bc0cd2243c11f3945a740
1 #include "tao/AnyTypeCode/TypeCode.h"
3 #if !defined (__ACE_INLINE__)
4 # include "tao/AnyTypeCode/TypeCode.inl"
5 #endif /* ! __ACE_INLINE__ */
7 #include "tao/CDR.h"
8 #include "tao/ORB_Constants.h"
9 #include "tao/debug.h"
10 #include "tao/SystemException.h"
12 #include "ace/OS_NS_string.h"
13 #include <cstring>
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 CORBA::TypeCode::~TypeCode ()
21 bool
22 CORBA::TypeCode::tao_marshal_kind (TAO_OutputCDR & cdr) const
24 return cdr << this->kind_;
27 CORBA::Boolean
28 CORBA::TypeCode::equal (TypeCode_ptr tc) const
30 if (this == tc)
32 return true;
34 else if (CORBA::is_nil (tc))
36 throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 13, CORBA::COMPLETED_NO);
39 CORBA::TCKind const tc_kind = tc->kind ();
41 if (tc_kind != this->kind_)
42 return false;
44 try
46 char const * const tc_id = tc->id ();
48 char const * const this_id = this->id ();
50 if (std::strcmp (this_id, tc_id) != 0)
51 return false;
53 char const * const tc_name = tc->name ();
55 char const * const this_name = this->name ();
57 if (std::strcmp (this_name, tc_name) != 0)
58 return false;
60 catch (const ::CORBA::TypeCode::BadKind&)
62 // Some TypeCodes do not support the id() and name()
63 // operations. Ignore the failure, and continue equality
64 // verification using TypeCode subclass-specific techniques
65 // below.
68 return this->equal_i (tc);
71 CORBA::Boolean
72 CORBA::TypeCode::equivalent (TypeCode_ptr tc) const
74 if (this == tc)
76 return true;
78 else if (CORBA::is_nil (tc))
80 throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 13, CORBA::COMPLETED_NO);
83 CORBA::TypeCode_ptr const mutable_this =
84 const_cast<CORBA::TypeCode_ptr> (this);
86 CORBA::TypeCode_var unaliased_this = TAO::unaliased_typecode (mutable_this);
87 CORBA::TypeCode_var unaliased_tc = TAO::unaliased_typecode (tc);
89 CORBA::TCKind const this_kind = unaliased_this->kind ();
90 CORBA::TCKind const tc_kind = unaliased_tc->kind ();
92 if (tc_kind != this_kind)
93 return false;
95 try
97 char const * const this_id = unaliased_this->id ();
98 char const * const tc_id = unaliased_tc->id ();
100 if (std::strlen (this_id) != 0
101 && std::strlen (tc_id) != 0)
103 return std::strcmp (this_id, tc_id) == 0;
106 catch (const ::CORBA::TypeCode::BadKind&)
108 // Some TypeCodes do not support the id() operation. Ignore the
109 // failure, and continue equivalence verification using TypeCode
110 // subclass-specific techniques.
113 return unaliased_this->equivalent_i (unaliased_tc.in ());
116 char const *
117 CORBA::TypeCode::id_i () const
119 throw ::CORBA::TypeCode::BadKind ();
122 char const *
123 CORBA::TypeCode::name_i () const
125 throw ::CORBA::TypeCode::BadKind ();
128 CORBA::ULong
129 CORBA::TypeCode::member_count_i () const
131 throw ::CORBA::TypeCode::BadKind ();
134 char const *
135 CORBA::TypeCode::member_name_i (CORBA::ULong /* index */) const
137 throw ::CORBA::TypeCode::BadKind ();
140 CORBA::TypeCode_ptr
141 CORBA::TypeCode::member_type_i (CORBA::ULong /* index */) const
143 throw ::CORBA::TypeCode::BadKind ();
146 CORBA::Any *
147 CORBA::TypeCode::member_label_i (CORBA::ULong /* index */) const
149 throw ::CORBA::TypeCode::BadKind ();
152 CORBA::TypeCode_ptr
153 CORBA::TypeCode::discriminator_type_i () const
155 throw ::CORBA::TypeCode::BadKind ();
158 CORBA::Long
159 CORBA::TypeCode::default_index_i () const
161 throw ::CORBA::TypeCode::BadKind ();
164 CORBA::ULong
165 CORBA::TypeCode::length_i () const
167 throw ::CORBA::TypeCode::BadKind ();
170 CORBA::TypeCode_ptr
171 CORBA::TypeCode::content_type_i () const
173 throw ::CORBA::TypeCode::BadKind ();
176 CORBA::UShort
177 CORBA::TypeCode::fixed_digits_i () const
179 throw ::CORBA::TypeCode::BadKind ();
182 CORBA::UShort
183 CORBA::TypeCode::fixed_scale_i () const
185 throw ::CORBA::TypeCode::BadKind ();
188 CORBA::Visibility
189 CORBA::TypeCode::member_visibility_i (CORBA::ULong /* index */) const
191 throw ::CORBA::TypeCode::BadKind ();
194 CORBA::ValueModifier
195 CORBA::TypeCode::type_modifier_i () const
197 throw ::CORBA::TypeCode::BadKind ();
200 CORBA::TypeCode_ptr
201 CORBA::TypeCode::concrete_base_type_i () const
203 throw ::CORBA::TypeCode::BadKind ();
206 // ---------------------------------------------------------------
208 CORBA::TypeCode::Bounds::Bounds ()
209 : CORBA::UserException ("IDL:omg.org/CORBA/TypeCode/Bounds:1.0",
210 "Bounds")
214 CORBA::TypeCode::Bounds*
215 CORBA::TypeCode::Bounds::_downcast (CORBA::Exception *ex)
217 return dynamic_cast <CORBA::TypeCode::Bounds*> (ex);
220 CORBA::Exception *
221 CORBA::TypeCode::Bounds::_alloc ()
223 CORBA::Exception *retval = 0;
224 ACE_NEW_RETURN (retval, ::CORBA::TypeCode::Bounds, 0);
225 return retval;
228 CORBA::Exception *
229 CORBA::TypeCode::Bounds::_tao_duplicate () const
231 CORBA::Exception *result;
232 ACE_NEW_RETURN (result,
233 CORBA::TypeCode::Bounds (*this),
235 return result;
238 void
239 CORBA::TypeCode::Bounds::_raise () const
241 throw *this;
244 void
245 CORBA::TypeCode::Bounds::_tao_encode (TAO_OutputCDR &cdr) const
247 if (cdr << this->_rep_id ())
249 return;
252 throw ::CORBA::MARSHAL ();
255 void
256 CORBA::TypeCode::Bounds::_tao_decode (TAO_InputCDR &)
260 // ****************************************************************
262 CORBA::TypeCode::BadKind::BadKind ()
263 : CORBA::UserException ("IDL:omg.org/CORBA/TypeCode/BadKind:1.0",
264 "BadKind")
268 CORBA::TypeCode::BadKind*
269 CORBA::TypeCode::BadKind::_downcast (CORBA::Exception *ex)
271 return dynamic_cast <CORBA::TypeCode::BadKind*> (ex);
274 CORBA::Exception *
275 CORBA::TypeCode::BadKind::_tao_duplicate () const
277 CORBA::Exception *result = 0;
278 ACE_NEW_RETURN (result,
279 CORBA::TypeCode::BadKind (*this),
281 return result;
284 void
285 CORBA::TypeCode::BadKind::_raise () const
287 throw *this;
290 void
291 CORBA::TypeCode::BadKind::_tao_encode (TAO_OutputCDR &cdr) const
293 if (cdr << this->_rep_id ())
295 return;
298 throw ::CORBA::MARSHAL ();
301 void
302 CORBA::TypeCode::BadKind::_tao_decode (TAO_InputCDR &)
306 // ---------------------------------------------------------------
308 bool
309 TAO::TypeCode::marshal (TAO_OutputCDR & cdr,
310 CORBA::TypeCode_ptr tc,
311 CORBA::ULong offset)
313 // Marshal the TypeCode TCKind and TypeCode body.
315 // Update the offset value in case a recursive TypeCode is being
316 // marshaled.
318 return
319 tc != 0
320 && tc->tao_marshal_kind (cdr)
321 && tc->tao_marshal (cdr, aligned_offset (offset) + sizeof (CORBA::ULong));
324 CORBA::ULong
325 TAO::TypeCode::aligned_offset (CORBA::ULong offset)
327 ptrdiff_t const unaligned_offset =
328 static_cast<ptrdiff_t> (offset);
330 return
331 static_cast<CORBA::ULong> (ACE_align_binary (unaligned_offset,
332 ACE_CDR::LONG_ALIGN));
335 // ---------------------------------------------------------------
337 CORBA::Boolean
338 operator<< (TAO_OutputCDR & cdr,
339 const CORBA::TypeCode_ptr tc)
341 return TAO::TypeCode::marshal (cdr, tc, 0);
344 // ---------------------------------------------------------------
346 #if defined (GEN_OSTREAM_OPS)
348 std::ostream &
349 operator<< (std::ostream & strm,
350 const CORBA::TypeCode_ptr)
352 return strm << "CORBA::TypeCode";
355 #endif /* GEN_OSTREAM_OPS */
357 // ---------------------------------------------------------------
359 CORBA::TypeCode_ptr
360 TAO::unaliased_typecode (CORBA::TypeCode_ptr tc)
362 if (CORBA::is_nil (tc))
364 throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 13, CORBA::COMPLETED_NO);
367 CORBA::TCKind tc_kind = tc->kind ();
369 if (tc_kind == CORBA::tk_alias)
371 CORBA::TypeCode_var tc_content = CORBA::TypeCode::_duplicate (tc);
373 // Iterate until we get to the actual unaliased type.
376 tc_content = tc_content->content_type ();
378 tc_kind = tc_content->kind ();
380 while (tc_kind == CORBA::tk_alias);
382 return tc_content._retn ();
385 return CORBA::TypeCode::_duplicate (tc);
388 // =========================================================
390 // Traits specializations for CORBA::TypeCode.
391 namespace TAO
393 CORBA::TypeCode_ptr
394 Objref_Traits<CORBA::TypeCode>::duplicate (CORBA::TypeCode_ptr p)
396 return CORBA::TypeCode::_duplicate (p);
399 void
400 Objref_Traits<CORBA::TypeCode>::release (CORBA::TypeCode_ptr p)
402 ::CORBA::release (p);
405 CORBA::TypeCode_ptr
406 Objref_Traits<CORBA::TypeCode>::nil ()
408 return CORBA::TypeCode::_nil ();
411 CORBA::Boolean
412 Objref_Traits<CORBA::TypeCode>::marshal (CORBA::TypeCode_ptr p,
413 TAO_OutputCDR & cdr)
415 return cdr << p;
418 void
419 In_Object_Argument_Cloner_T<CORBA::TypeCode_ptr>::duplicate (
420 CORBA::TypeCode_ptr p)
422 CORBA::TypeCode::_duplicate (p);
425 void
426 In_Object_Argument_Cloner_T<CORBA::TypeCode_ptr>::release (
427 CORBA::TypeCode_ptr p)
429 CORBA::release (p);
433 // =========================================================
435 CORBA::TCKind
436 TAO::unaliased_kind (CORBA::TypeCode_ptr tc)
438 CORBA::TypeCode_var unaliased_tc = TAO::unaliased_typecode (tc);
440 return unaliased_tc->kind ();
443 TAO_END_VERSIONED_NAMESPACE_DECL