interface TypeCode {
exception Bounds {};
exception BadKind {};
//For all TypeCode kinds
boolean equal(in TypeCode tc);
TCKind kind( );
//For tk_objref, tk_struct, tk_union, tk_enum, tk_alias, & tk_except
RepositoryId id( ) raises (BadKind);
//For tk_objref, tk_struct, tk_union, tk_enum, tk_alias, & tk_except
Identifier( ) name raises (BadKind);
//For tk_struct, tk_union, tk_enum, & tk_except
unsigned long member_count( ) raises (BadKind);
Identifier member_name (in unsigned long index)
raises (BadKind, Bounds);
//For tk_struct, tk_union, & tk_except
TypeCode member_type(in unsigned long index)
raises (BadKind, Bounds);
//For tk_union
any member_label(in unsigned long index)
raises (BadKind, Bounds);
TypeCode discriminator_type( ) raises (BadKind);
long default_index( ) raises (BadKind);
//For tk_string, tk_sequence, & tk_array
unsigned long length( ) raises (BadKind);
//For tk_sequence, tk_array, & tk_alias
TypeCode content_type( ) raises (BadKind);
};
The CORBA::TypeCode class implements the IDL pseudointerface called TypeCode. It describes complex IDL type structures at runtime. TypeCode consists of a kind and a list of parameters. The kind describes the TypeCode and the parameters provide the type definition.
You can only use CORBA::TypeCode* and CORBA::TypeCode_var types. You cannot use instances of CORBA::TypeCode in the code. Also, You must use CORBA::release( ) to release a TypeCode, not the delete operator. If you attempt to use a TypeCode instance or delete, you will receive a compile time error.
Following are the legal TypeCode kinds and parameters:
| Kind | Parameter List | Comments |
tk_null |
None | |
tk_void |
None | |
tk_short |
None | |
tk_long |
None | |
tk_ushort |
None | |
tk_ulong |
None | |
tk_float |
None | |
tk_double |
None | |
tk_boolean |
None | |
tk_char |
None | |
tk_octet |
None | |
tk_any |
None | |
tk_TypeCode |
None | |
tk_Principal |
None | |
tk_objref |
{<interface-ID>} |
Interface name |
tk_struct |
{<struct-name>, <member-name,> TypeCode, ...}
|
RepositoryId |
tk_union |
{<union-name>, <switch-TypeCode>, <label-value>, <member-name>, TypeCode,...} |
RepositoryId |
tk_enum |
{<enum-name>, <enum-ID>,... } |
RepositoryId |
tk_string |
{<maxlen-integer> } |
|
tk_sequence |
{TypeCode, <maxlen-integer>} |
|
tk_array |
{TypeCode, <length-integer> } |
|
tk_alias |
{<alias-name>, TypeCode} |
RepositoryId |
tk_except |
{<except-name>, <member-name>, TypeCode, ...} |
RepositoryId |
Most of the methods in the TypeCode class are accessors. The information contained in a TypeCode object is specific to a particular type. Therefore, methods must be invoked only on the kind of typecodes to which they apply. If an accessor method tries to access information from an inappropriate kind of typecode, it will throw the exception TypeCodePackage.BadKind. For example, if the method discriminator_type is called on anything other than a union, it will throw BadKind because only unions have a discriminator.
Compares this TypeCode object with the given one, testing for equality. TypeCode objects are equal if they are interchangeable and give identical results when TypeCode operations are applied to them.
public abstract boolean equal(TypeCode tc)
tcTypeCode object to compare against.True if the typecodes are equal; false otherwise.
Retrieves the kind of this TypeCode object. The kind of a typecode determines which TypeCode methods may legally be invoked on it.
The method kind may be invoked on any TypeCode object.
public abstract TCKind kind( )
TypeCode object.
Retrieves the RepositoryId globally identifying the type of this TypeCode object.
public abstract String id( ) throws BadKind
The id method can be invoked on object reference, structure, union, enumeration, alias, and exception typecodes. Object reference and exception TypeCode objects always have a RepositoryId. Structure, union, enumeration, and alias TypeCode objects obtained from the Interface Repository or the method ORB.create_operation_list also always have a RepositoryId. If there is no RepositoryId, the method can return an empty string.
The RepositoryId for this TypeCode object or an empty string if there is no RepositoryId.
BadKind, if the method is invoked on an inappropriate kind of TypeCode object.
Retrieves the simple name identifying this object within its enclosing scope.
public abstract String name( ) throws BadKind
Since names are local to a Repository, the name returned from a TypeCode object may not match the name of the type in any particular Repository, and may even be an empty string.
The method name can be invoked on object reference, structure, union, enumeration, alias, and exception TypeCode objects.
TypeCode object or an empty string
BadKind, if the method is invoked on an inappropriate kind of TypeCode object.
Retrieves the number of members in the type described by this TypeCode object.
The method member_count can be invoked on structure, union, and enumeration TypeCode objects.
public abstract int member_count( ) throws BadKind
The number of members constituting the type described by this TypeCode object.
BadKind, if the method is invoked on an inappropriate kind of TypeCode object.
Retrieves the simple name of the member identified by the given index.
public abstract String member_name(int index) throws BadKind, Bounds
Since names are local to a Repository, the name returned from a TypeCode object may not match the name of the member in any repository, and may be an empty string.
The method member_name can be invoked on structure, union, and enumeration TypeCode objects.
The simple name of the member identified by the index or an empty string.
Bounds, if the index is equal to or greater than the number of members constituting the type.
BadKind, if the method is invoked on an inappropriate kind of TypeCode object.
Retrieves the object describing the type of the member identified by the given index.
The method member_type can be invoked on structure and union TypeCode objects.
public abstract TypeCode member_type(int index) throws BadKind, Bounds
indexTypeCode object describing the member at the given index.
Bounds, if the index is equal to or greater than the number of members constituting the type.
BadKind, if the method is invoked on an inappropriate kind of TypeCode object.
Retrieves the label of the union member identified by the given index. For the default member, the label is the zero octet.
The member_label method can only be invoked on union TypeCode objects.
public abstract Any member_label(int index) throws BadKind, Bounds
indexAn Any object describing the label of the requested union member or the zero octet for the default member.
Bounds, if the index is equal to or greater than the number of members constituting the union.
BadKind, if the method is invoked on a non-union TypeCode object.
Returns a TypeCode object describing all non-default member labels. The method discriminator_type can be invoked only on union TypeCode objects.
public abstract TypeCode discriminator_type( ) throws BadKind
The TypeCode object describing the non-default member labels.
BadKind, if the method is invoked on a non-union TypeCode object.
Returns the index of the default member, or -1 if there is no default member.
The method default_index can be invoked only on union TypeCode objects.
public abstract int default_index( ) throws BadKind
The index of the default member, or -1 if there is no default member.
BadKind, if the method is invoked on a non-union TypeCode object.
Returns the number of elements in the type described by this TypeCode object. For strings and sequences, it returns the bound, with zero indicating an unbounded string or sequence. For arrays, it returns the number of elements in the array.
The method length can be invoked on string, sequence, and array TypeCode objects.
public abstract int length( ) throws BadKind
The bound for strings and sequences, or the number of elements for arrays.
BadKind, if the method is invoked on an inappropriate kind of TypeCode object.
Returns the TypeCode object representing the IDL type for the members of the object described by this TypeCode object. For sequences and arrays, it returns the element type. For aliases, it returns the original type. Note that multidimensional arrays are represented by nesting TypeCode objects, one per dimension.
The content_type method can be invoked on sequence, array, and alias TypeCode objects.
public abstract TypeCode content_type( ) throws BadKind
A TypeCode object representing the element type for sequences and arrays, or the original type for aliases.
BadKind, if the method is invoked on an inappropriate kind of TypeCode object.
TypeCode( );
Default constructor. Created with the default tk_null.
TypeCode(const TypeCode&);
Copy constructor. All parameters, if any, are copied.
static TypeCode_ptr _duplicate(TypeCode_ptr <obj>);
Increments the reference count of <obj>.
Returns the object whose reference count was incremented.
static TypeCode_ptr _nil( );
Returns a nil object reference for a TypeCode.
Boolean equal(TypeCode_ptr <tc>) const;
Compares itself with <tc>. They are considered equal if the IDL definitions have equal types.
Returns true if the TypeCodes are equal; false, otherwise.
CORBA::TCKind kind(id( ); name( ); member-count; member-name; member-type; member-label, discriminator-type, default-index( ); length; content-type) const;
Determines the kind of the TypeCode (an enumerated value of the TCKind).
Consider the following IDL definition:
struct my_struct_type
{
char member1;
long member2;
string member3;
};
If the IDL definition is compiled using the -typecodes option, the compiler generates a TypeCode constant called _tc_my_struct_type. Also, the TypeCode for the struct can be constructed by using the following code:
CORBA::TypeCode_var lv_tc;
CORBA::StructMemberSeq lv_seq(3);
CORBA::Any lv_any;
my_struct_type lv_struct;
lv_seq.length( 3 );
lv_seq[0].name = CORBA::string_dup( "member1" );
lv_seq[0].type = CORBA::TypeCode::_duplicate(CORBA::_tc_char );
lv_seq[1].name = CORBA::string_dup( "member2" );
lv_seq[1].type = CORBA::TypeCode::_duplicate(CORBA::_tc_long );
lv_seq[2].name = CORBA::string_dup( "member3" );
lv_seq[2].type = CORBA::TypeCode::_duplicate(CORBA::_tc_string );
lv_tc = pp_orb->create_struct_tc("IDL:my_struct_type:1.0",
"my_struct_type", lv_seq );
lv_struct.member1 = 'A';
lv_struct.member2 = 100000;
lv_struct.member3 = (const char *)"Test Struct string";
lv_any.replace( lv_tc, &lv_struct );
|