const char*
; the derived classes are expected to provide current values of appropriate type. The constructor for class State sets the initial value to a null pointer, and sets the state's attributes to a value determined by the constant AB_DEFAULT, which is defined in "State.h" to be the bitwise or of AB_CONST and AB_SETTABLE. The destructor does nothing extra.
State& setState(const char* stateName, Block* parent,This function sets the name, parent, initial value, and optionally the descriptor for a state. The character strings representing the initial value and descriptor must outlive the State.
const char* initValue, const char* desc = NULL);
State& setState(const char* stateName, Block* parent,This function is the same as the other
const char* initValue, const char* desc,
Attribute attr);
setState
, but it also sets attributes for the state. The Attribute object represents a set of attribute bits to turn on or off.
void setInitValue(const char* valueString);This function sets the initial value to
valueString
.
This string must outlive the State.
const char* initValue () const;Return the initial value.
virtual const char* type() const = 0;Return the type name (for use in user interfaces, for example). When states are created dynamically (by the
KnownState
or InterpGalaxy
class), it is this name that is used to specify the type.
virtual int size() const;Return the size (number of distinct values) in the state. The default implementation returns 1. Array state types will return the number of elements.
virtual int isArray() const;Return TRUE if this state is an array, false otherwise. The default implementation returns false.
virtual void initialize() = 0;Initialize the state. The
initialize
function for a state is responsible for parsing the initial value string and setting the current value appropriately; errors are signaled using the Error::abortRun mechanism.
virtual StringList currentValue() const = 0;Return a string representation of the current value.
void setCurrentValue(const char* newval);Modify the current value, in a type-independent way. Notice that this function is not virtual. It exploits the semantics of
initialize
to set the current value using other functions; the initial value is not modified (it is saved and restored).
virtual State* clone() const = 0;Derived state classes override this method to create an identical object to the one the method is called on.
StringList print(int verbose) const;Output all info. This is NOT redefined for each type of state.
bitWord attributes() const;Return my attribute bits.
bitWord setAttributes(const Attribute& attr);Set or clear attributes.
bitWord clearAttributes(const Attribute& attr);
const State* lookup(const char* name, Block* b);This method searches for a state named
name
in Block b
or one of its ancestors, and either returns it or a null pointer if not found.
int isA(const char*) const;This function returns true when given the name of the class or the name of any baseclass
State
classes are expected to associate a Tokenizer
object with their initial value string. The functions provided here can then be used to parse expressions appearing in that string.
ParseToken getParseToken(Tokenizer& tok, int stateType = T_Float);This function obtains the next token from the input stream associated with the Tokenizer. If there is a pushback token, that token is returned instead. If it receives a '<' token, then it assumes that the next string delimited by white space is a file name. It substitutes references to other parameters in the filename and then uses the Tokenizer's include file capability to insert the contents of the file into the input stream. If it receives a '!' token, then it assumes that that the next string delimited by white space is a command to be evaluated by an external interpreter. It substitutes references to other parameters in the command, sends the resulting string to the interpreter defined by interp member described above for evaluation, and inserts the result into the input stream. The information both read from an external file and returned from an external interpreter is also parsed by this function. Therefore, the external interpreter can perform both numeric and symbolic computations. When the parser hits the end of the input stream, it returns T_EOF.
The characters in the set
[]+*-/()^
are considered to be special and the lexical value is equal to the character value. Integer and floating values are recognized and evaluated to produce either T_Int or T_Float tokens. However, the decision is based on the value of stateType
;
if it is T_Float, all numeric values are returned as T_Float; if it is T_Int, all numeric values are returned as T_Int. Names that take the form of a C or C++ identifier are assumed to be names of states defined at a higher level (states belonging to the parent galaxy or some ancestor galaxy). They are searched for using lookup
; if not found, an error is reported using parseError and an error token is returned. If a State is found, a token of type T_ID is returned if it is an array state or COMPLEX; otherwise the state's current value is substituted and reparsed as a token. This means, for example, that a name of an IntState will be replaced with a T_Int token with the correct value.
void parseError (const char* part1, const char* part2 = "");This method produces an appropriately formatted error message with the name of the state and the arguments and calls Error::abortRun.
static ParseToken pushback();These functions manipulate the pushback token, for use in parsing. The first function returns the current pushback token, the second sets it to be a copy of the argument, the third clears it. There is only one such token, so the state parser is not reentrant.
static void setPushback(const ParseToken&);
static void clearPushback();
ParseToken evalIntExpression(Tokenizer& lexer);These four functions implement a simple recursive-descent expression parser. An expression is either a term or a series of terms with intervening '+' or '-' signs. A term is either a factor or a series of factors with interventing '*' or '/' signs. A factor is either an atom or a series of atoms with intervening '^' signs for exponentiation. (Note, C fans! ^ means exponentiation, not exclusive-or!). An atom is any number of optional unary minus signs, followed either by a parenthesized expression or a T_Int token. If any of these methods reads too far, the pushback token is used. All getParseToken calls use
ParseToken evalIntTerm(Tokenizer& lexer);
ParseToken evalIntFactor(Tokenizer& lexer);
ParseToken evalIntAtom(Tokenizer& lexer);
stateType
T_Int, so any floating values in the expression are truncated to integer. The token types returned from each of these methods will be one of T_Int, T_EOF, or T_ERROR.
ParseToken evalFloatExpression(Tokenizer& lexer);These functions have the identical structure as the corresponding Int functions. The token types returned from each of these methods will be one of T_Float, T_EOF, or T_ERROR.
ParseToken evalFloatTerm(Tokenizer& lexer);
ParseToken evalFloatFactor(Tokenizer& lexer);
ParseToken evalFloatAtom(Tokenizer& lexer);
InvokeInterp interp;An external interpreter for evaluating commands in a parameter definition preceded by the ! character and surrounded in quotes. By default, no interpreter is defined. If the interpreter were defined as the Tcl interpreter, then ! "expr abs(cos(1.0))" would compute 0.540302. Other parameters can be referenced as usual by using curly braces, e.g. ! "expr abs(cos({gain}))".
StringList parseFileName(const char*);This method parses filenames that have been inherited from state values enclosed in curly braces.
StringList parseNestedExpression(const char* expression);This method parses nested sub-expressions appearing in the
expression
, e.g. {{{FilterTapFile}/{File}}}, that might be passed off to another interpreter for evaluation, e.g. Tcl.
Int mergeFileContents(Tokenizer& lexer, char* token);This method treats the next token on the
lexer
as a filename.
Int sendToInterpreter(Tokenizer& lexer, char* token);This method sends the next token on the
lexer
to be evaluated by an external interpreter.
Int getParameterName(Tokenizer& lexer, char* token);This method looks for parameters of the form {name}.