previous next top complete contents complete index framed top this page unframed
Figure 35–3. $fieldInfo
| BOOLEAN PROCEDURE $fieldInfo (POINTER p; STRING fieldName; PRODUCES OPTIONAL INTEGER type,dspl); |
p is a POINTER to a record, CLASS descriptor, or data section. fieldName is the name of a data field. If p is invalid (e.g., NULLPOINTER), FALSE is returned. Otherwise, the field names in the associated CLASS descriptor are searched, and if fieldName is found (comparison is caseless), type is set to the data type code for the field (e.g., integerCode), dspl is set to the displacement in storage units from the start of the record (first field) to the start of the named field, and TRUE is returned. If there is no field by the name fieldName, FALSE is returned.
If fieldName designates a data field of an explicitly sized type, type is an extended type code, not a base type code (see Appendix A).
$fieldInfo can be used to examine or change the value of a field given a POINTER and a STRING with the name of the field, as follows (assuming that no field of p is explicitly sized):
write(logFile,s," = ");
IF $fieldInfo(p,s,type,dspl) THEN
CASE type OFB
[booleanCode]
write(logFile,boLoad(cva(p),dspl));
[integerCode]
write(logFile,iLoad(cva(p),dspl));
[longIntegerCode]
write(logFile,liload(cva(p),dspl));
...
[pointerCode]
write(logFile,"'",lbload(cva(p),dspl));
END
EL write(logFile,"<invalid pointer or field name>");
write(logFile,eol);
$fieldInfo makes a linear search of the STRING that contains the field names to look for the argument fieldName. If there are many fields, and only type (not displacement) information is needed, and the lookup is done often, it is more efficient to call $classInfo once to get all the required information, and store this information in a more rapidly accessible data structure (e.g., a hash table based on field name).
Section 50.1 describes a version of $fieldInfo, $fieldInfoExtended, that provides additional information about a field. However, $fieldInfoExtended is a temporary feature.
MAINSAIL Language Manual, Section 35.3