|
TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
|
Represents the status of an execution with error details. More...
#include <tec_status.hpp>
Public Member Functions | |
| constexpr bool | ok () const |
| Checks if the status indicates success. | |
| constexpr | operator bool () const |
| Conversion operator to check if the status is successful. | |
| std::string | as_string () |
| Converts the status to a string representation. | |
| TStatus () | |
| Constructs a successful status. | |
| TStatus (Error::Kind _kind) | |
| Constructs an error status with an unspecified code. | |
| TStatus (const TDesc &_desc, Error::Kind _kind=Error::Kind::Err) | |
| Constructs an error status with a description. | |
| TStatus (const TCode &_code, Error::Kind _kind=Error::Kind::Err) | |
| Constructs an error status with a code. | |
| TStatus (const TCode &_code, const TDesc &_desc, Error::Kind _kind=Error::Kind::Err) | |
| Constructs an error status with code and description. | |
Public Attributes | |
| Error::Kind | kind |
| The error category. | |
| std::optional< TCode > | code |
| Optional error code. | |
| std::optional< TDesc > | desc |
| Optional error description. | |
Friends | |
| std::ostream & | operator<< (std::ostream &out, const TStatus &status) |
| Outputs the status to an output stream. | |
Represents the status of an execution with error details.
A templated class that encapsulates an error kind, an optional error code, and an optional description to represent the outcome of an operation.
| TCode | The type used for error codes (e.g., int). |
| TDesc | The type used for error descriptions (e.g., std::string). |
Constructs a successful status.
Initializes the status with Error::Kind::Ok and no code or description.
|
inline |
Constructs an error status with an unspecified code.
Initializes the status with the specified error kind and an unspecified error code.
| _kind | The error kind (from Error::Kind). tec::Status do_something2() {
// ...
// IO error with unspecified error code [-1].
return {tec::Error::Kind::IOErr};
}
|
|
inline |
Constructs an error status with a description.
Initializes the status with a generic error kind (or specified kind), an unspecified error code, and the provided description.
| _desc | The error description. |
| _kind | The error kind (defaults to Error::Kind::Err). tec::Status do_something3() {
// ...
// IO error with description and unspecified error code [-1].
}
|
|
inline |
Constructs an error status with a code.
Initializes the status with a generic error kind (or specified kind) and the provided error code, with no description.
| _code | The error code. |
| _kind | The error kind (defaults to Error::Kind::Err). |
|
inline |
Constructs an error status with code and description.
Initializes the status with the specified error kind, code, and description.
| _code | The error code. |
| _desc | The error description. |
| _kind | The error kind (defaults to Error::Kind::Err). tec::Status do_something5() {
std::string addr{"127.0.0.1"};
// ...
// Network error with code and description.
return {404,
tec::format("Cannot connect to {}", addr),
}
std::string format(const T &arg) Formats a single argument into a string. Definition tec_print.hpp:171 |
|
inline |
Converts the status to a string representation.
Uses the stream output operator to create a string representation of the status.
|
inlineconstexpr |
Checks if the status indicates success.
Returns true if the error kind is Error::Kind::Ok, false otherwise.
|
inlineconstexpr |
Conversion operator to check if the status is successful.
Implicitly converts the status to a boolean, equivalent to calling ok().
Outputs the status to an output stream.
Formats the status as a string, including the error kind, and optionally the error code and description if the status is not Ok.
| out | The output stream to write to. |
| status | The TStatus object to output. |