Enumerations
Enumeration maps a list of names to either a string or integer value. Within a module the enumeration has a similar form to other top level blocks. The following code defines an enumeration enum_name with three values identifier_1, identifier_2 and identifier_3.
*tpl* 1.4 *module* example;
*enumeration* enum_name 1.0
'Enum description'
identifier_0,
identifier_1,
identifier_2
*end enumeration*;
If no values are given to the names then the first value will be 0. Each subsequent value will be one larger than the previous value. So in this example identifier_0 is 0, identifier_1 is 1 and identifier_2 is 2. The default values can be overridden:
*tpl* 1.4 *module* example;
*enumeration* enum_name 1.0
'Enum description'
car -> 5,
boat,
plane -> 8,
tank
*end enumeration*;
Using the -> operator allows the value to be replaced. In this example, car is 5, boat is 6, plane is 8 and tank is 9. It is legal to have multiple names mapping to the same value though the names themselves must be unique. Alternatively an enumeration can map to string values. This is done by giving one of the values a mapping to a string. Any unmapped value will take the string representation of its name. Given
tpl 1.4 module example;
enumeration enum_name 1.0
'Enum description'
car,
boat -> "water",
plane
end enumeration;
car is "car", boat is "water" and plane is "plane". Strings and numbers cannot be mixed within a single enumeration.
Using enumerations
Enumeration values can be used in metadata or in an assignment within a pattern. Metadata has been extended so it now also supports numbers.
tpl 1.4 module example;
*enumeration* vehicle 1.0
'Enum description'
car,
boat -> "water",
plane
*end enumeration*;
*pattern* example 1.0
'Test pattern'
*overview*
tags example;
*end overview*;
*triggers*
on process := DiscoveredProcess;
*end triggers*;
*body*
a := vehicle.boat;
*end body*;
*end pattern*;
The pattern assigns the variable a the value "water". Enumeration values cannot be used within expressions.