Enum Code Features
One enum definition, one set of capabilities — Archmage carries them into every supported language, each rendered in that language’s own idioms and type system.
Typed Constants
Section titled “Typed Constants”Each enum type becomes a distinct named type backed by an integer. Items are defined as typed constants. Where necessary, item names are prefixed with the type name to prevent naming conflicts. An optional prefix option in the type definition overrides the default prefix, if any.
Custom Underlying Type
Section titled “Custom Underlying Type”Each enum type can specify its underlying integer type — int, int8, int16, int32, int64, uint, uint8, uint16, uint32, or uint64. The generated code enforces range bounds in the Parse function.
Enum ↔ String Conversion
Section titled “Enum ↔ String Conversion”Every enum value has a canonical string representation — by default the item name, overridable via the string field in the definition. The generated code converts in both directions: enum to string and string to enum.
Safe Parsing
Section titled “Safe Parsing”The generated Parse function (or equivalent) accepts multiple input formats:
- Item name, or its
stringoverride if defined — case-insensitive TypeName(n)— a fallback numeric format, e.g.,"Armor(99)"- Decimal and hexadecimal integers (e.g.,
"1","0x1F")
When parsing fails, the function returns an error (or throws an exception, depending on the language) rather than silently returning a zero value.
Validity Checks
Section titled “Validity Checks”The generated IsValid function checks if a given value corresponds to a defined enum item. For bitflag enums, it decomposes the value and validates each constituent flag individually.
JSON Integer Serialization
Section titled “JSON Integer Serialization”Enum values serialize as integers in JSON. The string representation exists for runtime use only.
AllValues
Section titled “AllValues”The generated code exposes the full set of valid enum values as an ordered list. Sentinel items are excluded. For duplicate values, only the first-defined item is included.
Sentinel
Section titled “Sentinel”Items marked with sentinel: true serve as boundary markers (e.g., Count). They are excluded from the valid-value set, the AllValues list, and the name map. They appear only as constants in the generated code.
Duplicate Values
Section titled “Duplicate Values”Multiple items can share the same integer value. Each has its own constant. For string conversion, the first-defined item’s name is used for that value; all names remain valid for parsing.
Bitflag Enums
Section titled “Bitflag Enums”Enum types marked with bitflags: true gain additional capabilities:
- Parsing supports comma-separated flag combinations — e.g.,
"frost, fire"yields the bitwise OR:Frost | Fire - String conversion mirrors the above behavior, formatting composite values as comma-separated strings — e.g.,
Frost | Fireyields"frost, fire" IsValidverifies that a value can be fully decomposed into recognized flags