Automatic versioned tokenized enum support.
Main docs: Home
Namespaces | |
| namespace | pw |
| The Pigweed namespace. | |
Macros | |
| #define | PW_ENUM(enum_name, ...) |
| #define | PW_ENUM_STATUS(status_name, ok_code, ...) |
| #define PW_ENUM | ( | enum_name, | |
| ... | |||
| ) |
Registers a C++ enum for automatic stringification and tokenization.
This macro must be called at the global scope (outside of any namespaces, classes, or functions).
| enum_name | The fully-qualified C++ enum name (e.g., my_ns::MyEnum). |
| ... | The enumerator names to register. By default, Google-style kCamelCase names are converted to UPPER_SNAKE_CASE without the k prefix. A custom display name can be specified with kEnum = "custom". If multiple enumerators share the same value (aliases), they are grouped and their names are joined (e.g., "A|B"). |
| #define PW_ENUM_STATUS | ( | status_name, | |
| ok_code, | |||
| ... | |||
| ) |
Registers a C++ enum and generates a pw::StatusBase-derived status class wrapping it, with automatic stringification, tokenization, static factory functions (e.g. MyStatus::NotFound()), and Is*() query functions (e.g. status.IsNotFound()). IsOk() is not generated for codes named OK; use ok(). A code named OK that is not the OK code is an error.
This macro must be called at the global scope (outside of any namespaces, classes, or functions) in place of PW_ENUM. The status class is generated at the location of the PW_ENUM_STATUS invocation, so place it at the bottom of the header, after any declarations that reference the status class. Otherwise, those declarations require a forward declaration of the status class (e.g. namespace my_ns { class MyStatus; }).
| status_name | The fully-qualified name of the status class to generate (e.g., my_ns::MyStatus). |
| ok_code | The enumerator that represents success, including its enum type (e.g., MyStatusCode::kOk or my_ns::MyStatusCode::kOk). If only the enum type and enumerator are given, the enum is assumed to be in the namespace of status_name. Otherwise, the name is treated as fully qualified, with or without a leading ::. Enums in other namespaces or nested in classes must be fully qualified (e.g., my_ns::MyClass::Code::kOk). The enum type is deduced from this argument. |
| ... | The enumerator names to register (same syntax as PW_ENUM). Must include the OK enumerator. |