Skip to content

Enums

Besides specifying structured types, it is also possible to declare enumeration types in a C header. Here’s the header file color.h, which defines the Color enumeration type:

#ifndef COLOR_H_
#define COLOR_H_

typedef enum {
    RED, GREEN, BLUE, YELLOW, BLACK, WHITE
} Color;

#endif /* COLOR_H_ */

Now let’s extend the Triangle defined above by a fill color:

#ifndef TRIANGLE_H_
#define TRIANGLE_H_

#include "./point.h"
#include "./color.h"

typedef struct {
    Point a, b, c;
    Color fillColor;

} Triangle;

#endif /* TRIANGLE_H_ */

Similar to the Triangle type or any other C type, the Color enumeration type can be used in the statechart, e.g., by declaring an additional interface variable:

import: "color.h"
import: "triangle.h"

interface:
    var t: Triangle
    var c: Color = Color.BLUE

Please note that unlike structured types, enumeration variables can be initialized directly in their definitions within the statechart’s definition section.

In order to see which enumeration values are available, the content assist, triggered by [Ctrl+Space], is helpful again.

Using content assist to select an enumeration value [1]

Using content assist to select an enumeration value [1]

Once initialized, the c variable can now be used, e.g., in an assignment to the triangle t's fill color:

t.fillColor = c;

Accordingly, during simulation, the values of enum variables are displayed in the simulation view. It is also possible to modify them manually.

Using content assist to select an enumeration value [2]

Using content assist to select an enumeration value [2]