Value: static_assert(false, \
"PW_ENUM_STATUS(" #status_name \
") must be compiled with a pw_cc_enum target!"); \
_PW_ENUM_STATUS_MUST_BE_COMPILED_BY_pw_cc_enum( \
#status_name, \
#ok_code, \
PW_APPLY(_PW_ENUM_STRINGIFY_ARG, _PW_ENUM_COMMA, unused, __VA_ARGS__)) \
_PW_ENUM_MACRO_END
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; }).
- Example
#include <cstdint>
#include "pw_enum/generate.h"
namespace my_driver {
enum class I2cStatusCode : uint8_t {
kOk,
kNack,
kBusError,
kTimeout,
};
}
my_driver::I2cStatus, I2cStatusCode::kOk, kOk, kNack, kBusError, kTimeout);
#define PW_ENUM_STATUS(status_name, ok_code,...)
Definition: generate.h:76
Source: pw_enum/examples/private/enum_example/i2c_status.h
- Parameters
-
| 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. |