3.10.5 Methods for Iterating over Enumerated Types
VeraLite includes a set of specialized methods to enable iterating over the values of enumerated types.
3.10.5.1 first()
The syntax for the first() method is:
function enum first();
The first() method returns
the value of the first member of the enumeration enum.
3.10.5.2 last()
The syntax for the last() method is:
function enum last();
The last() function return the value of the last
member of the enumeration enum.
3.10.5.3 next()
The syntax for the next() method is:
function enum next( unsigned
int N =
1 );
The next() function returns the Nth next enumeration value (default is the next one) starting from the current value of the given variable. A wrap to the start of the enumeration occurs when the end of the enumeration is reached. If the given value is not a member of the enumeration, the next() function returns the first member.
3.10.5.4 prev()
The syntax for the prev() method is:
function enum prev( unsigned int N = 1 );
The prev() function returns the Nth previous enumeration value (default is the previous one) starting from the current value of the given variable. A wrap to the end of the enumeration occurs when the start of the enumeration is reached. If the given value is not a member of the enumeration, the prev() function returns the last member.
3.10.5.5 num()
The syntax for the num() method is:
function int num();
The num() method
returns the number of elements in the given enumeration.
3.10.5.6 name()
The syntax for the name() method is:
function string name();
The name() method
returns the string representation of the given enumeration value. If the given value is not a member of
the enumeration, the name() function returns the empty string.
Example: The following code fragment shows how to
display the name and value of all the
members of an enumeration.
typedef enum
{ red, green, blue, yellow } Colors;
Colors c = c.first;
forever begin
$display( “%s : %d\n”, c.name, c );
if( c ==
c.last ) break;
c = c.next;
end