Full Library / Defining_Flow / Basic Processing / Case_Switch
Block Name: Case_Switch
Code File Location: VisualSim/actor/lib/DS_State_Switch
o It is used as a case switch.
This block is a four-stage Switch-Case operation that uses the value in a field or memory. The State_Name_Reference refers to a field or memory location. The value at this location must match one of the 4 items in the State_Switch_Values. If there is a match, then incoming data structure is sent to the Field_Description that matches the Index. If there is no matching line, the incoming Data Structure is sent on the default port.
This block reads a memory or Data Structure field specified in the State_Name_Reference parameter. The value in the field or memory is compared to the 4 possible values in the State_Switch_Values parameter. The sequence of the State_Switch_Values match the output port_number (0-3) and the Field_Description (1-4). If there is a match, then the Data Structure executes the matching expression (Field_Description_1 to Field_Description_4) and the DS is sent out on the matching port (0-3). If there is no match, then incoming Data Structure is sent on the 'output_default' port. Additional Case_Switch blocks can be attached to the output_default to create additional state options. The State_Switch_Values can be integer, long, double, boolean or string.
The Field_description (1 to 4) inserts values into the data structure fields or memory, based on user entered expression containing parameters, fields or memories and an operator for performing mathematical, logical and memory operations.
The State Switch can be used like a switch/case statement in C/C++ to decode an incoming string, integer or composite data strucutres. One can create simple state machines using the single DS expression for each output port. In addition, this provides a powerful integration of field selection, field calculations, direct field access to/from memory and field re-insertion, all based on field or numerical comparisons.
Expression Language Syntax: X Op Y, or X = Y Op Z
Where X can be a Memory or Field, OP is the Operator (See below), Y can be Memory, Field, Time, Parameter or Value and Z can be Memory, Parameter, Field, Time or Value.
int, long, double, string, binary, boolean and data structure.
For the format of X Op Y, Operators are: =, +=, -=, *=, /=, 1/=, %=, !, ^, sqrt, ~, &, |, xor.
For the format of Y Op Z, Operators are: +, -, *, /, 1/, %, &, |, xor.
Additional operators include binary functions for Y Op Z: & (AND), | (OR), ~ (NOT), ! and 'xor' (Exclusive OR).
Additional operators include binary functions for Y Op Z: '&=', '|=', '~=', 'xor='.
Other operators are for Y Op Z: <<', '<<=', '>>', '>>='.
Random: irand(lower, upper), rand(lower, upper), exp(mean), norm(mean, stdev).
This block can also be used to define a memory as: MyMemL local 0, MyMemG global 1.0.
TNow, TLast, TDelta, TReal, TRealLast and TRealDelta.
Binary and shift operators can be applied only on int, binary and binary strings.
The Use Model for the Data Structure Blocks is to modify user-defined data structures or memories to implement an architectural abstraction, or cycle accurate model. Data Structure Blocks provide for communication between model flows via memory elements (DS Blocks or Memory BLocks) and with composite Data Structures to quickly and efficiently implement a modeling abstraction. One can think of Data Structure Blocks as operating on Data Structures, similar to individual EXCEL spreadsheets with flow oriented operators (DS Blocks).
Refer CaseSwitch Demo Model.
Parameter |
Explanation |
Type |
Example |
State_Name_Reference |
This is the name of a field or memory location that contains the token that needs to be matched. |
String |
DS_Field_or_Memory_Name |
State_Switch_Values |
The field will contain four (4) possible values. |
The type can be integer, long, double, boolean, string. |
1, 2, 3, 4 |
Field_Description_1 |
The field description 1 (op_x, assign, op_y, op, op_z) is a string that utilizes the DS Expression language. op_x represents the result of the asssignment (assign) operator, typically '='. The expression formats, operators, types and Time values listed in the summary section can be used here. The assignment operator can also be '+=', '-=', '*=', '/=', etc. similar to C/C++. The assign can also be 'local' or 'global' for declaring memories. op_x can be a memory (local, global), composite data structure field, or combination 'memory:field'. op_x cannot be a constant or numerical value, like C/C++. op_y, op_z can be a memory, composite data structure field, 'memory.field', constant, or numerical value. |
String |
Name_X Assign Name_Y OP Name_Z |
Field_Description_2 |
The field description 2 (op_x, assign, op_y, op, op_z) is a string that utilizes the DS Expression language. op_x represents the result of the asssignment (assign) operator, typically '='. The expression formats, operators, types and Time values listed in the summary section can be used here. The assignment operator can also be '+=', '-=', '*=', '/=', etc. similar to C/C++. The assign can also be 'local' or 'global' for declaring memories. op_x can be a memory (local, global), composite data structure field, or combination 'memory:field'. op_x cannot be a constant or numerical value, like C/C++. op_y, op_z can be a memory, composite data structure field, 'memory.field', constant, or numerical value. |
String |
Name_X Assign Name_Y OP Name_Z |
Field_Description_3 |
The field description 3 (op_x, assign, op_y, op, op_z) is a string that utilizes the DS Expression language. op_x represents the result of the asssignment (assign) operator, typically '='. The expression formats, operators, types and Time values listed in the summary section can be used here. The assignment operator can also be '+=', '-=', '*=', '/=', etc. similar to C/C++. The assign can also be 'local' or 'global' for declaring memories. op_x can be a memory (local, global), composite data structure field, or combination 'memory:field'. op_x cannot be a constant or numerical value, like C/C++. op_y, op_z can be a memory, composite data structure field, 'memory.field', constant, or numerical value. |
String |
Name_X Assign Name_Y OP Name_Z |
Field_Description_4 |
The field description 4 (op_x, assign, op_y, op, op_z) is a string that utilizes the DS Expression language. op_x represents the result of the asssignment (assign) operator, typically '='. The expression formats, operators, types and Time values listed in the summary section can be used here. The assignment operator can also be '+=', '-=', '*=', '/=', etc. similar to C/C++. The assign can also be 'local' or 'global' for declaring memories. op_x can be a memory (local, global), composite data structure field, or combination 'memory:field'. op_x cannot be a constant or numerical value, like C/C++. op_y, op_z can be a memory, composite data structure field, 'memory.field', constant, or numerical value. |
String |
Name_X Assign Name_Y OP Name_Z |
Random_Seed |
Random Number Seed. |
String |
123457L |
Port |
Explanation |
Type |
input |
The data structure or token arrives on this port. The type depends on the incoming token. |
General |
output_1 |
If the field or memory matches the first item in the Switch_Values, the incoming token is sent out on this port. |
General |
output_2 |
If the field or memory matches the second item in the Switch_Values, the incoming token is sent out on this port. |
General |
output_3 |
The output_3 port. If the field or memory matches the third item in the Switch_Values, the incoming token is sent out on this port. |
General |
output_4 |
If the field or memory matches the fourth item in the Switch_Values, the incoming token is sent out on this port. |
General |
output_default |
If the field or memory does not match any item in the Switch_Values, the incoming token is sent out on this port. |
General |
Created with the Personal Edition of HelpNDoc: Full-featured Help generator