46. Enumeration traits
The enum_trait module implements typeinfo traits for the enumerations.
All functions and symbols are in “enum_trait” module, use require to get access to it.
require daslib/enum_trait
46.1. Typeinfo macros
- enum_names
Implements typeinfo(enum_names EnumOrEnumType) which returns array of strings with enumValue names.
- enum_length
Implements typeinfo(enum_length EnumOrEnumType) which returns total number of elements in enumeration.
46.2. Handled enumerations
- string_to_enum
Enumeration annotation which implements string constructor for enumeration.
46.3. Uncategorized
- string(arg: auto const)
string returns auto
| argument | argument type | 
|---|---|
| arg | auto const | 
- converts enum value to string
- usage: let s = string(EnumValue) 
- to_enum(ent: auto(EnumT) const; name: string const)
to_enum returns EnumT
| argument | argument type | 
|---|---|
| ent | auto(EnumT) const | 
| name | string const | 
- converts string to enum value, returns defaultValue if not found
- usage: let e = to_enum(type<EnumType>,”EnumValueName”, EnumType.DefaultValue) 
- to_enum(ent: auto(EnumT) const; name: string const; defaultValue: EnumT const)
to_enum returns EnumT
| argument | argument type | 
|---|---|
| ent | auto(EnumT) const | 
| name | string const | 
| defaultValue | EnumT const | 
- converts string to enum value, returns defaultValue if not found
- usage: let e = to_enum(type<EnumType>,”EnumValueName”, EnumType.DefaultValue) 
- enum_to_table(ent: auto(EnumT) const)
enum_to_table returns table<string;EnumT>
| argument | argument type | 
|---|---|
| ent | auto(EnumT) const | 
- converts enum type to array of tuples (name, value)
- usage: let t = enum_to_table(type<EnumType>)