Libraries
Enumeration Source Code
 previous   up   next 

Abstract data types
type
new enum (ref expr: elem_expr) end enum
Abstract data type, describing enumeration types.

new enum

const func type: new enum (ref expr: elem_expr) end enum

Abstract data type, describing enumeration types. To define a new enumeration type the desired enumeration literals must be listed. Commas must seperate the enumeration literals.

const type: enumType is new enum
    enum_literal1, enum_literal2
  end enum;

In order to do I/O for a new enumeration type it is necessary to define the functions str and parse.

const func string: str (in enumType: enumValue) is
    return literal(enumValue);
enable_output(enumType);

Operator Summary
enumType
(attr enumType) . value
Default value of enumType.
enumType
(attr enumType) . first
Minimum value of enumType.
enumType
(attr enumType) . last
Maximum value of enumType.
boolean
(in enumType: enum1) = (in enumType: enum2)
Check if two enumeration values are equal.
boolean
(in enumType: enum1) <> (in enumType: enum2)
Check if two enumeration values are not equal.
enumType
(attr enumType) conv (in integer: number)
Conversion from integer number to enumType.
integer
(attr integer) conv (in enumType: enumValue)
Conversion from enumValue to integer.

Function Summary
string
literal (in enumType: enumValue)
Convert an enumeration value to the corresponding literal.
integer
ord (in enumType: enumValue)
Convert enumValue to integer.
integer
integer (in enumType: enumValue)
Convert enumValue to integer.
integer
hashCode (in enumType: enumValue)
Compute the hash value of an enumeration value.
integer
compare (in enumType: enum1, in enumType: enum2)
Compare two enumeration values.
enumType
succ (in enumType: enumValue)
Successor of enumValue.
enumType
pred (in enumType: enumValue)
Predecessor of enumValue.
void
incr (inout enumType: enumValue)
Increment an enumeration variable.
void
decr (inout enumType: enumValue)
Decrement an enumeration variable.
enumType
rand (in enumType: low, in enumType: high)
Compute pseudo-random enumeration value in the range [low, high].

Operator Detail

. value

const enumType: (attr enumType) . value

Default value of enumType.


. first

const enumType: (attr enumType) . first

Minimum value of enumType.


. last

const enumType: (attr enumType) . last

Maximum value of enumType.


=

const func boolean: (in enumType: enum1) = (in enumType: enum2)

Check if two enumeration values are equal.

Returns:
TRUE if the two enumeration values are equal, FALSE otherwise.

<>

const func boolean: (in enumType: enum1) <> (in enumType: enum2)

Check if two enumeration values are not equal.

Returns:
FALSE if the two enumeration values are equal, TRUE otherwise.

conv

const func enumType: (attr enumType) conv (in integer: number)

Conversion from integer number to enumType. The first enumeration literal of enumType corresponds to 0.

Returns:
the corresponding enumeration value.
Raises:
RANGE_ERROR - If number is neither 0 nor 1.

conv

const func integer: (attr integer) conv (in enumType: enumValue)

Conversion from enumValue to integer. The first enumeration literal of enumType corresponds to 0.

Returns:
the integer result of the conversion.

Function Detail

literal

const func string: literal (in enumType: enumValue)

Convert an enumeration value to the corresponding literal.

Returns:
the enumeration literal.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

ord

const func integer: ord (in enumType: enumValue)

Convert enumValue to integer. The first enumeration literal of enumType corresponds to 0.

Returns:
the integer result of the conversion.

integer

const func integer: integer (in enumType: enumValue)

Convert enumValue to integer. The first enumeration literal of enumType corresponds to 0.

Returns:
the integer result of the conversion.

hashCode

const func integer: hashCode (in enumType: enumValue)

Compute the hash value of an enumeration value.

Returns:
the hash value.

compare

const func integer: compare (in enumType: enum1, in enumType: enum2)

Compare two enumeration values.

Returns:
-1, 0 or 1 if the first argument is considered to be respectively less than, equal to, or greater than the second.

succ

const func enumType: succ (in enumType: enumValue)

Successor of enumValue.

succ(enumType.last)  raises  RANGE_ERROR
Returns:
the successor of enumValue.
Raises:
RANGE_ERROR - If enumValue is the last value of the enumeration.

pred

const func enumType: pred (in enumType: enumValue)

Predecessor of enumValue.

pred(enumType.first)  raises  RANGE_ERROR
Returns:
the predecessor of enumValue.
Raises:
RANGE_ERROR - If enumValue is the first value of the enumeration.

incr

const proc: incr (inout enumType: enumValue)

Increment an enumeration variable.

Raises:
RANGE_ERROR - If enumValue is the last value of the enumeration.

decr

const proc: decr (inout enumType: enumValue)

Decrement an enumeration variable.

Raises:
RANGE_ERROR - If enumValue is the first value of the enumeration.

rand

const func enumType: rand (in enumType: low, in enumType: high)

Compute pseudo-random enumeration value in the range [low, high]. The random values are uniform distributed.

Returns:
a random value such that low <= rand(low, high) and rand(low, high) <= high holds.
Raises:
RANGE_ERROR - The range is empty (low > high holds).


 previous   up   next