Data Dictionary: Types and functions

AF3 allows you to define your own datatypes and functions by using a socalled "Data Dictionary".
To create such a Data Dictionary, right-click at the root of your project and select "Data Dictionary", as shown below:



You can then add the following elements to your Data Dictionary: These can be added by drag-and-drop from the model elements palette or by the context menu (right-click)
of the data dictionary itself in the model navigator. We describe below every of these elements in more details: what they consist of, how to define them,
as well as the syntax to use to refer to the data items they define. The latter is particularly
useful, e.g., in Guards and Actions of State Automata, in Code Specifications, or in Temporal Logic Specifications.

Enumeration

An enumeration is a data type defined as a finite list of values. Variables of this type can only contain a value which belong to this list.
This is similar to "unions" in C, or to "sum types" in functional languages.
After having created an enumeration, you can add elements to it by drag and dropping "enumeration members" from the
palette or by right-clicking the enumeration in the data dictionary editor.

Syntax: an enumeration member can be accessed by writing its name followed by "()" (this allows to distinguish enumeration members from ports).
For instance, referring to the elements of the enumeration defined below is done by writing "Green()", "Red()", "RedYellow()", "Yellow()".


Structure

A structure is a data type which allows to gather various values in one variable, each value being uniquely identified by a structure member name.
One can for instance state a value shall always have a member called "x" of type integer and a member called "y" of type boolean.
This is similar to "records" in C, or to "product types" in functional languages.
After having created a structure, you can add elements to it by drag and dropping "structure members" from the
palette or by right-clicking the structure in the data dictionary editor.

Syntax: a structure member of a variable "v" can be accessed by writing "v.MEMBER_NAME".
For instance, for the example structure mentioned in the previous paragraph, one would access the integer by "v.x" and the boolean by "v.y".
Creating a structure is done with the syntax "{member_name_1: value_1, member_name_2: value_2, ...}". With the same example above: "{ x: 1, y: true }".

Array

Arrays are like usual C arrays, but their size is defined in the datatype itself.

Syntax: Given a variable "v" whose type is an array, the i-th element can be accessed by the expression
"v[i]". The index starts from 0. Assigning a value x to the i-th element is done with the syntax "v[i] = x".

Function

Functions denote small functions which can be used in various places in an AF3 project.
Note:Functions are not a type but are still defined in the data dictionary.

Functions have:

(see next figure for an example).



Evaluator

If you want to check your defined functions, AutoFOCUS provides an Evaluator for the Data Dictionary.
Simply click onto the Evaluator-Tab and insert commands into the lower field. The upper field shows the results of your inputs.
As you can see in the following Example, the Function "tRed()" returns 5 as defined.