TypeCode parameter: Difference between revisions
Created page with "This function obtains a specified parameter from a given TypeCode. ==Syntax== TypeCode tc; Environment *env; long index; any rc; r..." |
mNo edit summary |
||
Line 1: | Line 1: | ||
This function obtains a specified parameter from a given TypeCode. | This function obtains a specified parameter from a given TypeCode. | ||
==Syntax== | ==Syntax== | ||
Line 6: | Line 6: | ||
long index; | long index; | ||
any rc; | any rc; | ||
rc = TypeCode_parameter(tc, env, index); | rc = TypeCode_parameter(tc, env, index); | ||
==Parameters== | ==Parameters== | ||
;tc (TypeCode) | ;tc (TypeCode):The TypeCode whose parameter is desired. | ||
: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. | |||
;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== | ==Returns== | ||
;rc (any) | ;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. | ||
: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). | 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++: | |||
<pre> | <pre> | ||
typedef struct any { | typedef struct any { | ||
Line 32: | Line 25: | ||
void * _value; | void * _value; | ||
} any; | } any; | ||
</pre> | </pre> | ||
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: | |||
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: | |||
<pre> | <pre> | ||
#include <repostry.h> /* Interface Repository class */ | #include <repostry.h> /* Interface Repository class */ | ||
Line 81: | Line 71: | ||
==Remarks== | ==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. | 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). | 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== | ==Related Information== | ||
*TypeCodeNew | *TypeCodeNew | ||
*TypeCode_alignment | *TypeCode_alignment | ||
*TypeCode_equal | *TypeCode_equal | ||
*TypeCode_kind | *TypeCode_kind | ||
*TypeCode_param_count | *TypeCode_param_count | ||
*TypeCode_copy | *TypeCode_copy | ||
*TypeCode_free | *TypeCode_free | ||
*TypeCode_print | *TypeCode_print | ||
*TypeCode_size | *TypeCode_size | ||
*TypeCode_setAlignment | *TypeCode_setAlignment | ||
[[Category:SOM IRF]] | [[Category:SOM IRF]] |
Latest revision as of 17:14, 8 November 2021
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