5. Basics: String and Number ObjectsBack to Table of Contents As a convenience, the Daylight Toolkits provide object to hold "ordinary" data -- strings, integers, and floating-point numbers. There is nothing fancy about these objects -- they simply hold a string or numeric value. However, the ability to represent strings and numbers as Toolkit objects makes it possible to attach all kinds of information (e.g. atomic properties, labels, etc.) to other objects, such as atoms, bonds, and molecules. The functions dt_adjunct() and dt_setadjunct() are particularly useful with these simple objects.
5.1 String ObjectsA string object is a simple Toolkit object that holds the characters in a string, and the string's length. The Toolkit's concept of a "string" is a series of arbitrary 8-bit values and a length. Note, in particular, that the string is not assumed to be null-terminated, padded with blanks, or other application-language-dependent standards. For example, it is permissible to store arbitrary, or "binary" data in a string object as long as it can be represented as a series of bytes with no machine-dependent word-alignment assumptions. (Note: Many Toolkit functions return strings. Don't confuse this with functions that return string objects. If a function returns a string object, then the function's return type will be a Handle.) There is only one function specific to string objects:
A string-object's contents can also be modified via the function dt_setstringvalue(), and retrieved with the function dt_stringvalue(); both are discussed in the previous section.
5.2 Integer and Real Number ObjectsInteger- and Real-number objects are similar in concept to the string objects described above. Each object type holds a simple number. The following functions operate on these objects:
5.3 Binary-Data FunctionsIt is often convenient to use string objects to store "binary" data -- data that are not intended to be printed, and that may contain "NULL" characters and so forth. However, it is also convenient to be able to represent these binary data as printable ASCII characters. For example, Daylight's THOR database system can store arbitrary binary data, but needs to be able to represent it lexically with a restricted set of printable characters. Three "convenience" functions are provided to convert binary data to printable ASCII and back again. The conversion used maps each 3 bytes of binary data into 4 bytes of ASCII data (i.e. 4 groups of 6 bits are converted to 4 ASCII characters). The ASCII representation has a trailing byte indicating how many of the last 3 binary bytes are part of the original binary data. Note that these functions take strings, not string objects, as their inputs, and return string objects, not strings.
Go to previous chapter: Introduction. Go to next chapter: Basics: Streams and Sequences |