NonStop Software

CORBA::TypeCode

Previous Topic | Next Topic | Contents | Index
Getting Started Guide | Administration Guide | Programmer's Guide

Subtopics

TypeCode Syntax
TypeCode Description
TypeCode Parameters
TypeCode Methods
CORBA::TypeCode::TypeCode( ) Constructor
CORBA::TypeCode::TypeCode( ) Copy Constructor
CORBA::TypeCode::_duplicate( )
CORBA::TypeCode::_nil( )
CORBA::TypeCode::equal( )
CORBA::TypeCode::kind( )
TypeCode Example

TypeCode Syntax

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);
};

TypeCode Description

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.

TypeCode Parameters

Following are the legal TypeCode kinds and parameters:

Table 1. 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

TypeCode Methods

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.

equal

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)

Parameters

tc
The TypeCode object to compare against.

Returns

True if the typecodes are equal; false otherwise.

kind

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( )

Returns

The TCKind instance indicating the value of the kind field of this TypeCode object.

id

Retrieves the RepositoryId globally identifying the type of this TypeCode object.

public abstract String id( ) throws BadKind

Description

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.

Returns

The RepositoryId for this TypeCode object or an empty string if there is no RepositoryId.

Throws

BadKind, if the method is invoked on an inappropriate kind of TypeCode object.

name

Retrieves the simple name identifying this object within its enclosing scope.

public abstract String name( ) throws BadKind

Description

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.

Returns

the name identifying this TypeCode object or an empty string

Throws

BadKind, if the method is invoked on an inappropriate kind of TypeCode object.

member_count

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

Returns

The number of members constituting the type described by this TypeCode object.

Throws

BadKind, if the method is invoked on an inappropriate kind of TypeCode object.

member_name

Retrieves the simple name of the member identified by the given index.

public abstract String member_name(int index) throws BadKind, Bounds

Description

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.

Parameters

index - index of the member for which a name is being reqested

Returns

The simple name of the member identified by the index or an empty string.

Throws

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.

member_type

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

Parameters

index
The index of the member for which type information is begin requested.

Returns

The TypeCode object describing the member at the given index.

Throws

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.

member_label

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

Parameters

index
The index of the union member for which the label is being requested.

Returns

An Any object describing the label of the requested union member or the zero octet for the default member.

Throws

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.

discriminator_type

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

Returns

The TypeCode object describing the non-default member labels.

Throws

BadKind, if the method is invoked on a non-union TypeCode object.

default_index

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

Returns

The index of the default member, or -1 if there is no default member.

Throws

BadKind, if the method is invoked on a non-union TypeCode object.

length

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

Returns

The bound for strings and sequences, or the number of elements for arrays.

Throws

BadKind, if the method is invoked on an inappropriate kind of TypeCode object.

content_type

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

Returns

A TypeCode object representing the element type for sequences and arrays, or the original type for aliases.

Throws

BadKind, if the method is invoked on an inappropriate kind of TypeCode object.

CORBA::TypeCode::TypeCode( ) Constructor


Syntax

TypeCode( );

Description

Default constructor. Created with the default tk_null.

CORBA::TypeCode::TypeCode( ) Copy Constructor


Syntax

TypeCode(const TypeCode&);

Description

Copy constructor. All parameters, if any, are copied.

CORBA::TypeCode::_duplicate( )

Syntax

static TypeCode_ptr _duplicate(TypeCode_ptr <obj>);

Description

Increments the reference count of <obj>.

Returns the object whose reference count was incremented.

CORBA::TypeCode::_nil( )

Syntax

static TypeCode_ptr _nil( );

Description

Returns a nil object reference for a TypeCode.

CORBA::TypeCode::equal( )

Syntax

Boolean equal(TypeCode_ptr <tc>) const;

Description

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::TypeCode::kind( )

Syntax

CORBA::TCKind kind(id( ); name( ); member-count; member-name;
   member-type; member-label, discriminator-type, default-index( );
   length; content-type) const;

Description

Determines the kind of the TypeCode (an enumerated value of the TCKind).

TypeCode Example

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 );

Previous Topic | Next Topic | Contents | Top
Getting Started Guide | Administration Guide | Programmer's Guide
Bibliography | Glossary | Index
© Tandem, a division of Compaq. All rights reserved. Legal notices.