template<typename Derived, auto kOkCode,
StatusMessages kMessages = StatusMessages::kDefault>
class pw::StatusBase< Derived, kOkCode, kMessages >
Base class providing standard status operations for status types using CRTP.
StatusBase provides common functionality for status types that wrap an enum or integer status code, including checking for success (ok()), retrieving the code (code()), optional error messages (has_message(), message()), string formatting (str()), updating, and equality comparisons.
Custom status types should derive from StatusBase<Derived, kOkCode> or alias StatusOf<kOkCode>. Derived classes should be declared [[nodiscard]] unless using StatusOf (which is declared [[nodiscard]]).
Equality comparisons consider only the status code; messages are ignored.
Users should not interact directly with StatusBase, except to instantiate a custom status class. Do not use StatusBase for variables or function parameters.
A status type supports messages if its code is an enum registered with PW_ENUM whose values are all from 0 to 65535. Passing a PW_STATUS_MSG to any other status type, or to one that uses StatusMessages::kDisabled, does not compile.
- Warning
- Status codes must be valid enumerators. They are not range checked, and when messages are stored as tokens, the code shares a 32-bit word with the message token. A value that needs more bits than the code's enumerators do (
pw::EnumTraits<Code>::kBitWidth) corrupts both the code and the message. Check integers from outside the program, such as with pw::IsValidEnum, before casting them to the code type.
- Template Parameters
-
| Derived | The derived status class (CRTP parameter). |
| kOkCode | Code value that represents success (ok() == true). |
| kMessages | Pass StatusMessages::kDisabled for a status that never carries a message. |
|
|
constexpr bool | operator== (Derived lhs, Derived rhs) noexcept |
| | Compares two statuses by code only; error messages are ignored.
|
| |
| constexpr bool | operator!= (Derived lhs, Derived rhs) noexcept |
| | Compares two statuses by code only; error messages are ignored.
|
| |
|
constexpr bool | operator== (Derived lhs, Code rhs) noexcept |
| | Compares a status with a status code; error messages are ignored.
|
| |
| constexpr bool | operator== (Code lhs, Derived rhs) noexcept |
| | Compares two statuses by code only; error messages are ignored.
|
| |
| constexpr bool | operator!= (Derived lhs, Code rhs) noexcept |
| | Compares two statuses by code only; error messages are ignored.
|
| |
| constexpr bool | operator!= (Code lhs, Derived rhs) noexcept |
| | Compares two statuses by code only; error messages are ignored.
|
| |