NAME

switch_op -- execute selected operand

PROTOTYPE

unitptr switch_op( int iNum, char *apcLabel[], unitptr uHost)

ARGUMENTS

int iNum
nr of case labels
char *apcLabel[]
the case labels themselves
unitptr uHost
host unit

RETURN VALUE:

A pointer to the created unit or NULL in the case of an error.

INTERFACE OF CREATED UNIT:

X_in[0]:
(input field 0) This is a field with a single scalar pin, if all case labels are numbers, otherwise, it is a text field. The input in this field is matched against the iNum specified case labels.

EXECUTION OF CREATED UNIT:

This unit mimicks the operation of the switch statement in C. It takes iNum+1 ( -iNum, if iNum is negative) successor units as its operands. Each execution call matches the input (text or number) at input field X_in against the iNum specified case labels. If a match occurs for the i - th label (i=0,1,2..), the i-th successor unit is executed. Then, execution skips the remaining operands and continues with the successor of the last operand. If no match occurs, execution skips abs(iNum) operands. Thus, if iNum was nonnegative, the last operand (at position iNum+1) is executed (the `default'' case). Otherwise, if iNum was negative, execution continues with the successor of the last operand (since in this case there is one operand less).

NOTE:

The behavior of the switch_unit corresponds to that of a C switch for which each case is followed by a break statement. Unlike in C, where the break must be specified, no such specification is necessary here.

ADAPTATION:

Again restricted to the operand corresponding to the chosen case.

DESCRIPTION:

CONTROL MODES:

EXAMPLES:

STATUS:

Preliminary.

SEE ALSO:

FILE

/local/homes/rhaschke/nst7/man/../o.linx86_64//../nstsrc/nst_stdr.c