![]() |
![]() |
|
|
Converting Strings
The following set of functions is provided to handle the case of conversion to and from a user type of FLD_STRING:
These functions call their non-string-function counterparts, providing a type of FLD_STRING, and a len of 0. Note that the duration of the validity of the pointer returned by Ffinds is the same as that described for CFfind.
For descriptions of these functions, see the BEA Tuxedo ATMI FML Function Reference.
Ftypcvt
The functions CFadd, CFchg, CFget, CFgetalloc, and CFfind use the function Ftypcvt to perform the appropriate data conversion. The Ftypcvt32 function fails for the FLD_PTR, FLD_FML32, and FLD_VIEW32 field types. The synopsis of Ftypcvt usage is as follows (it does not follow the parameter order conventions).
char *
Ftypcvt(FLDLEN *tolen, int totype, char *fromval, int fromtype, FLDLEN fromlen)
Here:
Ftypcvt converts from the value *fromval, which has type fromtype, and length fromlen if fromtype is type FLD_CARRAY (otherwise fromlen is inferred from fromtype), to a value of type totype. Ftypcvt returns a pointer to the converted value, and sets *tolen to the converted length, upon success. Upon failure, Ftypcvt returns NULL. Consider the following example, in which the CFchg function is used:
CFchg(fbfr,fieldid,oc,value,len,type)
FBFR *fbfr; /* fielded buffer */
FLDID fieldid; /* field to be changed */
FLDOCC oc; /* occurrence of field to be changed */
char *value; /* location of new value */
FLDLEN len; /* length of new value */
int type; /* type of new value */
{
char *convloc; /* location of post-conversion value */
FLDLEN convlen; /* length of post-conversion value */
extern char *Ftypcvt;
/* convert value to fielded buffer type */
if((convloc = Ftypcvt(&convlen,FLDTYPE(fieldid),value,type,len)) == NULL)
return(-1);
if(Fchg(fbfr,fieldid,oc,convloc,convlen) < 0)
return(-1);
return(1);
}
The user may call Ftypcvt directly to do field value conversion without adding or modifying a fielded buffer.
For more information, refer to Ftypcvt, Ftypcvt32(3fml) in the BEA Tuxedo ATMI FML Function Reference.
Conversion Rules
In the following list of conversion rules, oldval represents a pointer to the data item being converted, and newval, a pointer to the post-conversion value.
*((float *)newval) = *((short *) oldval)
sprintf(newval,"%d",*((short *)oldval))
*((float *)newval) = atof(oldval)
*((float *)newval) = *((char *)oldval)
To convert a short to a char, use the method shown in the next example:
*((char *)newval) = *((short *)oldval)
Note that a carray of length 1 and a char have the following differences:
The following table summarizes the conversion rules presented in this section.
The following table defines the entries listed in the previous table.
![]() |
![]() |
![]() |
|
Copyright © 2001 BEA Systems, Inc. All rights reserved.
|