Jump to content

TypeCode parameter

From EDM2
Revision as of 17:14, 8 November 2021 by Ak120 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function obtains a specified parameter from a given TypeCode.

Syntax

TypeCode         tc;
Environment     *env;
long             index;
any              rc;

rc = TypeCode_parameter(tc, env, index);

Parameters

tc (TypeCode)
The TypeCode whose parameter is desired.
env (Environment *)
A pointer to an Environment structure. The CORBA standard mandates the use of this structure as a standard way to return exception information when an error condition is detected.
index (long)
The number of the desired parameter. Parameters are numbered from 0 to N-1, where N is the value returned by the Typecode_param_count function.

Returns

rc (any)
Returns the requested parameter in the form of an any. This function raises the Bounds exception if the value of the index exceeds the number of parameters available in the given TypeCode. Because the values exist within the specified TypeCode, you should not free the results returned from this function.

A bounds exception is also raised if this function is called on any of the IDL basic data types (see note above).

An any is a basic IDL data type that is represented as the following structure in C or C++:

typedef struct any {
    TypeCode _type;
    void *   _value;
} any;

Since all TypeCode parameters have one of only three types (string, TypeCode, or long), the _type member will always be set to TC_string, TC_TypeCode, or TC_long, as appropriate. The _value member always points to the actual parameter datum. For example, the following code can be used to extract the name of a structure from a TypeCode of kind tk_struct in C:

#include <repostry.h>  /* Interface Repository class */
#include <typedef.h>   /* Interface Repository TypeDef class */
#include <somtcnst.h>  /* TypeCode constants */
TypeCode x;
Environment *ev = somGetGlobalEnvironment ();
TypeDef aTypeDefObj;
sequence(Contained) sc;
any parm;
string name;
Repository repo;

...

/* 1st, obtain a TypeCode from an Interface Repository object,
 * or use a TypeCode constant.
 */

repo = RepositoryNew ();
sc = _lookup_name (repo, ev,
     "AttributeDescription", -1, "TypeDef", TRUE);
if (sc._length) {
    aTypeDefObj = sc._buffer[0];
    x = __get_type (aTypeDefObj, ev);
    }
else
    x = TC_AttributeDescription;

if (TypeCode_kind (x, ev) == tk_struct) {
    parm = TypeCode_parameter (x, ev, 0); /* Get structure name */
    if (TypeCode_kind (parm._type, ev) != tk_string) {
        printf ("Error, unexpected TypeCode: ");
        TypeCode_print (parm._type, ev);
    } else {
        name = *((string *)parm._value);
        printf ("The struct name is %s\n", name);
    }
} else {
    printf ("TypeCode is not a tk_struct: ");
    TypeCode_print (x, ev);
}

Remarks

The TypeCode_parameter function can be used to obtain any of the parameters contained in a given TypeCode. Refer to Table 1 for a list of the number and type of parameters associated with each category of TypeCode.

Note: This function should not be used for any of the IDL basic data types (that is, any types in the TCKind enumeration that are not listed in table 1 under the TypeCode_Kind function).

Related Information

  • TypeCodeNew
  • TypeCode_alignment
  • TypeCode_equal
  • TypeCode_kind
  • TypeCode_param_count
  • TypeCode_copy
  • TypeCode_free
  • TypeCode_print
  • TypeCode_size
  • TypeCode_setAlignment