Top Up Prev Next Bottom Contents Index Search

9.2 Types of states

9.2.1 Class IntState and class FloatState

Class IntState, derived from State, has an integer current value. Its initialize() function uses the evalIntExpression function to read an integer expression from the initial value string. If successful, it attempts to read another token from the string; if there is another token, it reports the error "extra text after valid expression". An assignment operator is provided that accepts an integer value and loads it into the current value. A cast to integer is also defined for accessing the current value. The virtual function currentValue is overloaded to return a printed version of the current value. In addition to the setInitValue from class State, a second form is provided that takes an integer argument. Standard overrides for isA, className, and clone are provided. Class FloatState is almost identical to class IntState except that its data field is a double precision value; where IntState functions have an argument or return value of int, FloatState has a corresponding argument or return value of double. Both are generated from the same pseudo-template files. The type() function for IntState returns "INT". For FloatState, "FLOAT" is returned. For both implementations, a prototype object is added to the KnownState list.

9.2.2 Class ComplexState

ComplexState is much like FloatState and IntState, except in the expressions it accepts for initial values. Its data member is Complex and it accordingly defines an assignment operator that takes a complex value and a conversion operator that returns one. The initial value string for a ComplexState takes one of three forms: it may be the name of a galaxy ComplexState, a floating expression (of the form accepted by State::evalFloatExpression), or a string of the form (floatexp1 , floatexp2) where both floatexp1 and floatexp2 are floating expressions. For the second form, the imaginary part will always be zero. For the third form, the first expression gives the real part and the second gives the imaginary part.

9.2.3 Class StringState

A StringState's current value is a string (more correctly, of type const char*). The current value is created by the initialize() function by scanning the initial value string. This string is copied literally, except that curly braces are special. If a pair of curly braces surrounds the name of a galaxy state, the printed representation of that state's current value (returned by the currentValue function) is substituted. To get a literal curly brace in the current value, prefix it with a backslash. Class StringState defines assignment operators so that different string values can be copied to the current value; the value is copied with saveString and deleted by the destructor.

9.2.4 Numeric array states

Classes IntArrayState and FloatArrayState are produced from the same pseudo-template. Class ComplexArrayState has a very similar design. All return TRUE to isArray, provide an array element selection operator (operator[](int)), and an operator that converts the state into a pointer to the first element of its data (much like arrays in C). The expression parser for FloatArrayState accepts a series of "subarray expressions", which are concatenated together to get the current value when initialize() is called. Subarray expressions may specify a single element, some number of copies of a single element, or a galaxy array state of the same type (another FloatArrayState). A single element specifier may either be a floating point value, a scalar (integer or floating) galaxy state name, or a general floating expression enclosed in parentheses. A number of copies of this single element can be specified by appending an integer expression enclosed in square brackets. The expression parsers for IntArrayState and ComplexArrayState differ only that where FloatArrayState wants a floating expression, IntArrayState wants an integer expression and ComplexArrayState wants a complex expression (an expression suitable for initializing a ComplexState).

9.2.5 Class StringArrayState

As its name suggests, the current value for a StringArrayState is an array of strings. White space in the initial value string separates "words", and Each word is assigned by initialize() into a separate array element. Quotes can be use to permit "words" to have white space. Current values of galaxy states can be converted into single elements of the StringArrayState value by surrounding their names with curly braces in the initial value. Galaxy StringArrayState names will be translated into a series of values. There is currently no provision for modifying the current value of a StringArrayState other than calling of initialize to parse the current value string.

Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.