Getting Attribute Values

We saw above (ยง4.4) how to display the internal values of an ObjectObject, but what about accessing these values from a program? Not all internal Object values are accessible in this way, but many are. Those that are, are called attributes. A description of all the attributes used by the AST library can be found in Appendix C.

Attributes come in several data types (character string, integer, boolean and floating point) and there is a standard way of obtaining their values. As an example, consider obtaining the value of the NinNin attribute for the ZoomMapZoomMap created earlier. This could be done as follows:


\begin{terminalv}
int nin;
\par
...
\par
nin = astGetI( zoommap, ''Nin'' );
\end{terminalv}

Here, the function astGetI is used to extract the attribute value by giving it the ZoomMap pointer and the attribute name (attribute names are not case sensitive, but we have used consistent capitalisation in this document in order to identify them). Remember to use the “ast.h” header file to include the function prototype.

If we had wanted the value of the ZoomZoom attribute, we would probably have used astGetD instead, this being a double version of the same function, for example:


\begin{terminalv}
double zoom;
\par
...
\par
zoom = astGetD( zoommap, ''Zoom'' );
\end{terminalv}

However, we could equally well have read the Nin value as double, or the Zoom value as an integer, or whatever we wanted.

The data type you want returned is specified simply by replacing the final character of the astGetX function name with C (character string), D (double), F (float), I (int) or L (long). If possible, the value is converted to the type you want. If not, an error message will result. Note that all floating point values are stored internally as double, and all integer values as int. Boolean values are also stored as integers, but only take the values 1 and 0 (for true/false).