3 //=============================================================================
7 * Header file the @c CORBA::TypeCode class.
9 * @author Ossama Othman <ossama@dre.vanderbilt.edu>
10 * @author DOC group at Vanderbilt University, Washington University
11 * and the University of California at Irvine.
13 //=============================================================================
15 #ifndef TAO_TYPECODE_H
16 #define TAO_TYPECODE_H
18 #include /**/ "ace/pre.h"
20 #include "tao/AnyTypeCode/TAO_AnyTypeCode_Export.h"
22 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
27 #include "tao/AnyTypeCode/ValueModifierC.h"
28 #include "tao/AnyTypeCode/VisibilityC.h"
29 #include "tao/UserException.h"
30 #include "tao/Basic_Types.h"
31 #include "tao/Typecode_typesC.h"
32 #include "tao/Any_Insert_Policy_T.h"
33 #include "tao/CORBA_methods.h"
34 #include "tao/Pseudo_VarOut_T.h"
35 #include "tao/Object_Argument_T.h"
36 #include "tao/Arg_Traits_T.h"
37 #include "tao/Objref_VarOut_T.h"
39 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
43 typedef TAO_Pseudo_Var_T
<TypeCode
> TypeCode_var
;
44 typedef TAO_Pseudo_Out_T
<TypeCode
> TypeCode_out
;
49 * @brief A representation of the structure of a given OMG
52 * @c TypeCodes are primarily used by @c CORBA::Anys, the CORBA
53 * Interface Repository and the CORBA Dynamic Invocation Interface.
55 class TAO_AnyTypeCode_Export TypeCode
61 * @brief Out-of-bounds member index exception.
63 * Exception thrown when attempting to pass an out-of-bounds index
64 * value to a @c TypeCode operation that accepts a member index
67 class TAO_AnyTypeCode_Export Bounds
: public UserException
73 static Bounds
* _downcast (CORBA::Exception
* ex
);
74 static CORBA::Exception
* _alloc ();
76 virtual CORBA::Exception
* _tao_duplicate () const;
78 virtual void _raise () const;
80 virtual void _tao_encode (TAO_OutputCDR
& cdr
) const;
81 virtual void _tao_decode (TAO_InputCDR
& cdr
);
87 * @brief Invalid @c TypeCode operation exception.
89 * Exception thrown when attempting to invoke a @c TypeCode
90 * operation that is not valid for the type represented by the
93 class TAO_AnyTypeCode_Export BadKind
: public CORBA::UserException
98 static BadKind
* _downcast (CORBA::Exception
* ex
);
99 static CORBA::Exception
* _alloc ();
101 virtual CORBA::Exception
* _tao_duplicate () const;
103 virtual void _raise () const;
105 virtual void _tao_encode (TAO_OutputCDR
& cdr
) const;
106 virtual void _tao_decode (TAO_InputCDR
& cdr
);
109 static CORBA::TypeCode_ptr
const _tc_Bounds
;
110 static CORBA::TypeCode_ptr
const _tc_BadKind
;
112 /// Duplicate this @c TypeCode.
114 * Statically instantiated @c TypeCodes incur no reference count
115 * manipulation, i.e. reference counting is a no-op.
117 * Dynamically instantiated @c TypeCodes will have their reference
118 * count incremented by one each time this function is called.
120 static CORBA::TypeCode_ptr
_duplicate (CORBA::TypeCode_ptr tc
);
122 /// Returns a NULL typecode.
123 static CORBA::TypeCode_ptr
_nil ();
126 * @name @c CORBA::TypeCode Methods
128 * These methods are part of the public interface of @c
129 * CORBA::TypeCode class, as defined by the OMG CORBA
130 * specification and C++ mapping.
132 * The C++ mapping does not declare the methods in the public
133 * @c CORBA::TypeCode API as @c virtual, so work around that by
134 * making these methods inlined to forward all calls to the
135 * corresponding protected template method (i.e. the design
136 * pattern, not the C++ feature) listed below in the @c protected
140 /// Equality of two @c TypeCodes.
142 * @return @c true if and only if the set of legal operations is
143 * the same and invoking any operation on the this
144 * @c TypeCode and @a tc returns identical results.
146 Boolean
equal (TypeCode_ptr tc
) const;
148 /// Equivalence of two @c TypeCodes.
150 * Equivalence of two @c TypeCodes satisfies a subset of the
151 * requirements necessary for equality.
155 Boolean
equivalent (TypeCode_ptr tc
) const;
157 /// The kind of @c TypeCode.
158 TCKind
kind () const;
160 /// Return @c TypeCode stripped of optional @c name and
161 /// @c member_name fields.
163 * @note Calling this method will incur additional run-time memory
164 * consumption since TAO's implementation relies on the
165 * TypeCodeFactory to dynamically create a compact @c
166 * TypeCode; the exception being @c TypeCodes with empty
167 * parameter lists. Those @c TypeCodes are already compact,
168 * meaning that call this method on such @c TypeCodes incurs
169 * no additional run-time memory requirements.
171 * Unless you need to send compact @c TypeCodes
172 * "over-the-wire" or your @c TypeCode corresponds to a
173 * type with a large number of members, try to stick with
174 * the existing potentially non-compact @c TypeCode.
176 * @note Compact @c TypeCodes may also be generated statically by
177 * the TAO_IDL compiler by invoking it with its "-Gt"
178 * (i.e. enable optimized TypeCodes) command line option.
180 TypeCode_ptr
get_compact_typecode () const;
182 /// The @c RepositoryId globally identifying the type.
184 * This method is valid for the following kinds of @c TypeCodes:
192 * @li @c tk_value_box
194 * @li @c tk_abstract_interface
195 * @li @c tk_local_interface
197 * @li @c tk_component
201 * @note CORBA::TypeCode::id() does not follow the usual parameter
202 * passing rules defined by the C++ mapping. This behavior
203 * is required by the C++ mapping. In particular, ownership
204 * is maintained by the @c TypeCode.
206 char const * id () const;
208 /// The simple name identifying the type within its enclosing
211 * This method is valid for the following kinds of @c TypeCodes:
219 * @li @c tk_value_box
221 * @li @c tk_abstract_interface
222 * @li @c tk_local_interface
224 * @li @c tk_component
228 * @note CORBA::TypeCode::name() does not follow the usual
229 * parameter passing rules defined by the C++ mapping. This
230 * behavior is required by the C++ mapping. In particular,
231 * ownership is maintained by the @c TypeCode.
233 char const * name () const;
235 /// The type member count.
237 * This method is valid for the following kinds of @c TypeCodes:
246 ULong
member_count () const;
248 /// The type member name.
250 * This method is valid for the following kinds of @c TypeCodes:
259 * @note CORBA::TypeCode::member_name() does not follow the usual
260 * parameter passing rules defined by the C++ mapping. This
261 * behavior is required by the C++ mapping. In particular,
262 * ownership is maintained by the @c TypeCode.
264 char const * member_name (ULong index
) const;
266 /// The type member @c TypeCode.
268 * This method is valid for the following kinds of @c TypeCodes:
276 TypeCode_ptr
member_type (ULong index
) const;
278 /// The union member label.
280 * This method is valid for the following kinds of @c TypeCodes:
284 Any
* member_label (ULong index
) const;
286 /// The type of all non-default union member labels.
288 * This method is valid for the following kinds of @c TypeCodes:
292 TypeCode_ptr
discriminator_type () const;
294 /// The index of the default union member.
296 * This method is valid for the following kinds of @c TypeCodes:
300 Long
default_index () const;
302 /// The length of the type.
304 * This method is valid for the following kinds of @c TypeCodes:
311 ULong
length () const;
313 /// The underlying content type.
315 * This method is valid for the following kinds of @c TypeCodes:
319 * @li @c tk_value_box
322 TypeCode_ptr
content_type () const;
324 /// The number of significant digits.
326 * This method is valid for the following kinds of @c TypeCodes:
330 UShort
fixed_digits () const;
332 /// The scale factor.
334 * This method is valid for the following kinds of @c TypeCodes:
338 UShort
fixed_scale () const;
340 /// The @c Visibility of the @c valuetype or @c eventtype member
341 /// corresponding to index @a index.
343 * This method is valid for the following kinds of @c TypeCodes:
348 Visibility
member_visibility (ULong index
) const;
350 /// The @c ValueModifier of the @c valuetype of @c eventtype
351 /// represented by this @c TypeCode.
353 * This method is valid for the following kinds of @c TypeCodes:
358 ValueModifier
type_modifier () const;
360 /// The @c TypeCode corresponding to the concrete base
361 /// @c valuetype or @c eventtype.
363 * This method is valid for the following kinds of @c TypeCodes:
368 * @return @c TypeCode corresponding to the concrete base
369 * @c valuetype or @c eventtype.
370 * @c CORBA::TypeCode::_nil() if no concrete base exists.
372 TypeCode_ptr
concrete_base_type () const;
375 /// Marshal the @c TypeCode @c TCKind.
379 virtual bool tao_marshal_kind (TAO_OutputCDR
& cdr
) const;
381 /// Marshal this @c TypeCode into a CDR output stream.
383 * Marshal this @c TypeCode into the @a cdr output CDR stream,
384 * excluding the @c TypeCode kind. Existing @a cdr contents will
385 * not be altered. The marshaled @c TypeCode will be appended to
386 * the given @a cdr CDR output stream.
388 * @param cdr Output CDR stream into which the @c TypeCode will be
391 * @param offset Number of bytes currently in the output CDR
392 * stream, including the top-level TypeCode @c
393 * TCKind. This argument is useful for recursive
394 * @c TypeCodes. @c TypeCodes that contain other
395 * @c TypeCodes should pass an updated @a offset
396 * value to the marshaling operation for those
397 * contained @c TypeCodes.
399 * @return @c true if marshaling was successful.
401 * @note This is a TAO-specific method that is not part of the
402 * standard @c CORBA::TypeCode interface.
404 * @note If this method returns false, the contents of the @a cdr
405 * output CDR stream are undefined.
407 virtual bool tao_marshal (TAO_OutputCDR
& cdr
,
408 CORBA::ULong offset
) const = 0;
410 /// Increase the reference count on this @c TypeCode.
411 virtual void tao_duplicate () = 0;
413 /// Decrease the reference count on this object.
414 virtual void tao_release () = 0;
416 /// Destruction callback for Anys.
417 static void _tao_any_destructor (void * x
);
419 typedef CORBA::TypeCode_ptr _ptr_type
;
420 typedef CORBA::TypeCode_var _var_type
;
421 typedef CORBA::TypeCode_out _out_type
;
425 TypeCode (CORBA::TCKind kind
);
429 * Protected destructor to enforce proper memory management
430 * through the reference counting mechanism.
432 virtual ~TypeCode ();
435 * @name @c TypeCode Template Methods
437 * Methods that must be implemented by @c CORBA::TypeCode
438 * subclasses if valid for those subclasses.
440 * The default implementations of the non-pure virtual methods
441 * throw the @c CORBA::TypeCode::BadKind exception since many of
442 * these methods are @c TypeCode type-specific. This reduces code
443 * duplication and bloat.
445 * The @c TypeCode @c equal(), @c equivalent(), @c kind() and
446 * @c get_compact_typecode() methods are valid for all
447 * @c TypeCodes which is why their template method "@c _i"
448 * counterparts are pure virtual.
451 virtual Boolean
equal_i (TypeCode_ptr tc
) const = 0;
452 virtual Boolean
equivalent_i (TypeCode_ptr tc
) const = 0;
453 virtual TypeCode_ptr
get_compact_typecode_i () const = 0;
455 virtual char const * id_i () const;
456 virtual char const * name_i () const;
457 virtual ULong
member_count_i () const;
458 virtual char const * member_name_i (ULong index
) const;
459 virtual TypeCode_ptr
member_type_i (ULong index
) const;
460 virtual Any
* member_label_i (ULong index
) const;
461 virtual TypeCode_ptr
discriminator_type_i () const;
462 virtual Long
default_index_i () const;
463 virtual ULong
length_i () const;
464 virtual TypeCode_ptr
content_type_i () const;
465 virtual UShort
fixed_digits_i () const;
466 virtual UShort
fixed_scale_i () const;
467 virtual Visibility
member_visibility_i (ULong index
) const;
468 virtual ValueModifier
type_modifier_i () const;
469 virtual TypeCode_ptr
concrete_base_type_i () const;
473 // Prevent copying and assignment.
474 TypeCode (TypeCode
const &);
475 void operator= (TypeCode
const &);
478 /// The kind of TypeCode.
481 } // End namespace CORBA
484 TAO_AnyTypeCode_Export
CORBA::Boolean
485 operator<< (TAO_OutputCDR
& cdr
, const CORBA::TypeCode_ptr tc
);
487 TAO_AnyTypeCode_Export
CORBA::Boolean
488 operator>> (TAO_InputCDR
& cdr
, CORBA::TypeCode_ptr
& tc
);
490 #if defined (GEN_OSTREAM_OPS)
492 // Used in optionally generated ostream operators (for debugging).
493 TAO_AnyTypeCode_Export
std::ostream
&
494 operator<< (std::ostream
&, const CORBA::TypeCode_ptr tc
);
496 #endif /* GEN_OSTREAM_OPS */
502 /// Marshal the @c TypeCode @a tc in to the output CDR stream @a
505 * @see @CORBA::TypeCode::tao_marshal() description for details.
508 TAO_AnyTypeCode_Export
bool marshal (TAO_OutputCDR
& cdr
,
509 CORBA::TypeCode_ptr tc
,
510 CORBA::ULong offset
);
512 /// Return @a offset aligned on the appropriate CDR boundary.
513 TAO_AnyTypeCode_Export
CORBA::ULong
aligned_offset (CORBA::ULong offset
);
516 /// Return the unaliased content @c TypeCode of the given
518 TAO_AnyTypeCode_Export
519 CORBA::TypeCode_ptr
unaliased_typecode (CORBA::TypeCode_ptr tc
);
521 /// Return the unaliased @c TCKind of the given @c TypeCode.
523 * @note This is a convenience function that simply calls @c kind()
524 * on the unaliased @c TypeCode returned from
525 * @c unaliased_typecode().
527 TAO_AnyTypeCode_Export
528 CORBA::TCKind
unaliased_kind (CORBA::TypeCode_ptr tc
);
530 // ---------------------------------------------------------------
532 // Used in generated code if CORBA::TypeCode is an argument or
535 class TAO_AnyTypeCode_Export Arg_Traits
<CORBA::TypeCode
>
536 : public Object_Arg_Traits_T
<CORBA::TypeCode_ptr
,
539 TAO::Objref_Traits
<CORBA::TypeCode
>,
540 TAO::Any_Insert_Policy_Stream
>
545 struct TAO_AnyTypeCode_Export Objref_Traits
< ::CORBA::TypeCode
>
547 static ::CORBA::TypeCode_ptr
duplicate (::CORBA::TypeCode_ptr
);
548 static void release (::CORBA::TypeCode_ptr
);
549 static ::CORBA::TypeCode_ptr
nil ();
550 static CORBA::Boolean
marshal (::CORBA::TypeCode_ptr p
,
551 TAO_OutputCDR
& cdr
);
555 struct TAO_AnyTypeCode_Export In_Object_Argument_Cloner_T
<CORBA::TypeCode_ptr
>
557 static void duplicate(CORBA::TypeCode_ptr objref
);
558 static void release(CORBA::TypeCode_ptr objref
);
562 TAO_END_VERSIONED_NAMESPACE_DECL
564 #if defined (__ACE_INLINE__)
565 # include "tao/AnyTypeCode/TypeCode.inl"
566 #endif /* __ACE_INLINE__ */
568 #include /**/ "ace/post.h"
570 #endif /* TAO_TYPECODE_H */