1 #include "tao/AnyTypeCode/TypeCode.h"
3 #if !defined (__ACE_INLINE__)
4 # include "tao/AnyTypeCode/TypeCode.inl"
5 #endif /* ! __ACE_INLINE__ */
8 #include "tao/ORB_Constants.h"
10 #include "tao/SystemException.h"
12 #include "ace/OS_NS_string.h"
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 CORBA::TypeCode::~TypeCode ()
22 CORBA::TypeCode::tao_marshal_kind (TAO_OutputCDR
& cdr
) const
24 return cdr
<< this->kind_
;
28 CORBA::TypeCode::equal (TypeCode_ptr tc
) const
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_
)
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)
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)
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
68 return this->equal_i (tc
);
72 CORBA::TypeCode::equivalent (TypeCode_ptr tc
) const
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
)
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 ());
117 CORBA::TypeCode::id_i () const
119 throw ::CORBA::TypeCode::BadKind ();
123 CORBA::TypeCode::name_i () const
125 throw ::CORBA::TypeCode::BadKind ();
129 CORBA::TypeCode::member_count_i () const
131 throw ::CORBA::TypeCode::BadKind ();
135 CORBA::TypeCode::member_name_i (CORBA::ULong
/* index */) const
137 throw ::CORBA::TypeCode::BadKind ();
141 CORBA::TypeCode::member_type_i (CORBA::ULong
/* index */) const
143 throw ::CORBA::TypeCode::BadKind ();
147 CORBA::TypeCode::member_label_i (CORBA::ULong
/* index */) const
149 throw ::CORBA::TypeCode::BadKind ();
153 CORBA::TypeCode::discriminator_type_i () const
155 throw ::CORBA::TypeCode::BadKind ();
159 CORBA::TypeCode::default_index_i () const
161 throw ::CORBA::TypeCode::BadKind ();
165 CORBA::TypeCode::length_i () const
167 throw ::CORBA::TypeCode::BadKind ();
171 CORBA::TypeCode::content_type_i () const
173 throw ::CORBA::TypeCode::BadKind ();
177 CORBA::TypeCode::fixed_digits_i () const
179 throw ::CORBA::TypeCode::BadKind ();
183 CORBA::TypeCode::fixed_scale_i () const
185 throw ::CORBA::TypeCode::BadKind ();
189 CORBA::TypeCode::member_visibility_i (CORBA::ULong
/* index */) const
191 throw ::CORBA::TypeCode::BadKind ();
195 CORBA::TypeCode::type_modifier_i () const
197 throw ::CORBA::TypeCode::BadKind ();
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",
214 CORBA::TypeCode::Bounds
*
215 CORBA::TypeCode::Bounds::_downcast (CORBA::Exception
*ex
)
217 return dynamic_cast <CORBA::TypeCode::Bounds
*> (ex
);
221 CORBA::TypeCode::Bounds::_alloc ()
223 CORBA::Exception
*retval
= 0;
224 ACE_NEW_RETURN (retval
, ::CORBA::TypeCode::Bounds
, 0);
229 CORBA::TypeCode::Bounds::_tao_duplicate () const
231 CORBA::Exception
*result
;
232 ACE_NEW_RETURN (result
,
233 CORBA::TypeCode::Bounds (*this),
239 CORBA::TypeCode::Bounds::_raise () const
245 CORBA::TypeCode::Bounds::_tao_encode (TAO_OutputCDR
&cdr
) const
247 if (cdr
<< this->_rep_id ())
252 throw ::CORBA::MARSHAL ();
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",
268 CORBA::TypeCode::BadKind
*
269 CORBA::TypeCode::BadKind::_downcast (CORBA::Exception
*ex
)
271 return dynamic_cast <CORBA::TypeCode::BadKind
*> (ex
);
275 CORBA::TypeCode::BadKind::_tao_duplicate () const
277 CORBA::Exception
*result
= 0;
278 ACE_NEW_RETURN (result
,
279 CORBA::TypeCode::BadKind (*this),
285 CORBA::TypeCode::BadKind::_raise () const
291 CORBA::TypeCode::BadKind::_tao_encode (TAO_OutputCDR
&cdr
) const
293 if (cdr
<< this->_rep_id ())
298 throw ::CORBA::MARSHAL ();
302 CORBA::TypeCode::BadKind::_tao_decode (TAO_InputCDR
&)
306 // ---------------------------------------------------------------
309 TAO::TypeCode::marshal (TAO_OutputCDR
& cdr
,
310 CORBA::TypeCode_ptr tc
,
313 // Marshal the TypeCode TCKind and TypeCode body.
315 // Update the offset value in case a recursive TypeCode is being
320 && tc
->tao_marshal_kind (cdr
)
321 && tc
->tao_marshal (cdr
, aligned_offset (offset
) + sizeof (CORBA::ULong
));
325 TAO::TypeCode::aligned_offset (CORBA::ULong offset
)
327 ptrdiff_t const unaligned_offset
=
328 static_cast<ptrdiff_t> (offset
);
331 static_cast<CORBA::ULong
> (ACE_align_binary (unaligned_offset
,
332 ACE_CDR::LONG_ALIGN
));
335 // ---------------------------------------------------------------
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)
349 operator<< (std::ostream
& strm
,
350 const CORBA::TypeCode_ptr
)
352 return strm
<< "CORBA::TypeCode";
355 #endif /* GEN_OSTREAM_OPS */
357 // ---------------------------------------------------------------
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.
394 Objref_Traits
<CORBA::TypeCode
>::duplicate (CORBA::TypeCode_ptr p
)
396 return CORBA::TypeCode::_duplicate (p
);
400 Objref_Traits
<CORBA::TypeCode
>::release (CORBA::TypeCode_ptr p
)
402 ::CORBA::release (p
);
406 Objref_Traits
<CORBA::TypeCode
>::nil ()
408 return CORBA::TypeCode::_nil ();
412 Objref_Traits
<CORBA::TypeCode
>::marshal (CORBA::TypeCode_ptr p
,
419 In_Object_Argument_Cloner_T
<CORBA::TypeCode_ptr
>::duplicate (
420 CORBA::TypeCode_ptr p
)
422 CORBA::TypeCode::_duplicate (p
);
426 In_Object_Argument_Cloner_T
<CORBA::TypeCode_ptr
>::release (
427 CORBA::TypeCode_ptr p
)
433 // =========================================================
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