3-48
SOMobjects Base Toolkit Programmer’s Reference Manual
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);
}
Related Information
Functions: TypeCodeNew, TypeCode_alignment, TypeCode_copy, TypeCode_equal,
TypeCode_free, TypeCode_kind, TypeCode_param_count, TypeCode_print,
TypeCode_setAlignment, TypeCode_size
Commenti su questo manuale