The Gaudi Framework
master (37c0b60a)
|
#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/StatusCode.h>
Classes | |
class | Category |
Public Types | |
enum | ErrorCode : code_t { ErrorCode::FAILURE = 0, ErrorCode::SUCCESS = 1, ErrorCode::RECOVERABLE = 2 } |
typedef unsigned long | code_t |
type of StatusCode value More... | |
Public Member Functions | |
StatusCode ()=default | |
Default constructor. More... | |
template<typename T , typename = std::enable_if_t<is_StatusCode_enum<T>::value>> | |
StatusCode (T sc) noexcept | |
Constructor from enum type (allowing implicit conversion) More... | |
StatusCode (code_t code, const StatusCode::Category &cat) noexcept | |
Constructor from code_t and category (explicit conversion only) More... | |
StatusCode (code_t code) noexcept | |
Constructor from code_t in the default category (explicit conversion only) More... | |
StatusCode (const StatusCode &rhs) noexcept=default | |
Copy constructor. More... | |
StatusCode (StatusCode &&rhs) noexcept=default | |
Move constructor. More... | |
~StatusCode ()=default | |
Destructor. More... | |
StatusCode & | operator= (const StatusCode &rhs) noexcept=default |
bool | isSuccess () const |
bool | isFailure () const |
bool | isRecoverable () const |
operator bool () const | |
Shorthand for isSuccess() More... | |
code_t | getCode () const |
Retrieve value. More... | |
const StatusCode & | ignore () const |
Allow discarding a StatusCode without warning. More... | |
StatusCode & | ignore () |
template<typename F , typename... ARGS> | |
StatusCode | andThen (F &&f, ARGS &&... args) const |
Chain code blocks making the execution conditional a success result. More... | |
template<typename F , typename... ARGS> | |
StatusCode | orElse (F &&f, ARGS &&... args) const |
Chain code blocks making the execution conditional a failure result. More... | |
const StatusCode & | orThrow (std::string_view message, std::string_view tag) const |
Throw a GaudiException in case of failures. More... | |
const StatusCode & | orThrow (std::string_view tag="") const |
Throw a GaudiException in case of failures. More... | |
const StatusCode::Category & | getCategory () const |
Retrieve category. More... | |
std::string | message () const |
Description (or name) of StatusCode value. More... | |
StatusCode & | operator&= (const StatusCode &rhs) |
Ternary logic operator with RECOVERABLE being the "third" state. More... | |
StatusCode & | operator|= (const StatusCode &rhs) |
Ternary logic operator with RECOVERABLE being the "third" state. More... | |
Static Public Member Functions | |
static const Category & | default_category () noexcept |
Default Gaudi StatusCode category. More... | |
Static Public Attributes | |
constexpr static const auto | SUCCESS = ErrorCode::SUCCESS |
constexpr static const auto | FAILURE = ErrorCode::FAILURE |
constexpr static const auto | RECOVERABLE = ErrorCode::RECOVERABLE |
Private Member Functions | |
ErrorCode | default_value () const |
Project onto the default StatusCode values. More... | |
void | i_doThrow (std::string_view message, std::string_view tag) const |
Helper function to avoid circular dependency between GaudiException.h and StatusCode.h. More... | |
template<typename F , typename... ARGS, typename = std::enable_if_t<std::is_invocable_v<F, ARGS...>>> | |
StatusCode | i_invoke (F &&f, ARGS &&... args) const |
Helper to invoke a callable and return the resulting StatusCode or this, if the callable returns void. More... | |
Private Attributes | |
const Category * | m_cat { &default_category() } |
The status code category. More... | |
code_t | m_code { static_cast<code_t>( ErrorCode::SUCCESS ) } |
The status code value. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &s, const StatusCode &sc) |
bool | operator== (const StatusCode &lhs, const StatusCode &rhs) |
Check if StatusCode value and category are the same. More... | |
bool | operator!= (const StatusCode &lhs, const StatusCode &rhs) |
bool | operator< (const StatusCode &lhs, const StatusCode &rhs) |
Comparison (values are grouped by category first) More... | |
StatusCode | operator& (StatusCode lhs, const StatusCode &rhs) |
Ternary AND operator. More... | |
StatusCode | operator| (StatusCode lhs, const StatusCode &rhs) |
Ternary OR operator. More... | |
bool & | operator&= (bool &lhs, const StatusCode &sc) |
Boolean AND assignment operator. More... | |
bool & | operator|= (bool &lhs, const StatusCode &sc) |
Boolean OR assignment operator. More... | |
This class is used for returning status codes from appropriate routines. A StatusCode is comprised of an (integer) value and a category (similar to std::error_code). By default StatusCodes are created within a default StatusCode::Category, which defines the isSuccess(), isFailure() and isRecoverable() behaviour depending on the value of the StatusCode. This behaviour can be modified by defining a custom StatusCode::Category and overriding the respective methods.
To define a new StatusCode::Category, do the following:
STATUSCODE_ENUM_DECL( MyEnum )
STATUSCODE_ENUM_IMPL( MyEnum, MyCategory )
in a .cpp fileDefinition at line 61 of file StatusCode.h.
typedef unsigned long StatusCode::code_t |
type of StatusCode value
Definition at line 67 of file StatusCode.h.
|
strong |
|
default |
Default constructor.
|
inlinenoexcept |
Constructor from enum type (allowing implicit conversion)
Definition at line 109 of file StatusCode.h.
|
inlineexplicitnoexcept |
Constructor from code_t and category (explicit conversion only)
Definition at line 112 of file StatusCode.h.
|
inlineexplicitnoexcept |
Constructor from code_t in the default category (explicit conversion only)
Definition at line 115 of file StatusCode.h.
|
defaultnoexcept |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
default |
Destructor.
|
inline |
Chain code blocks making the execution conditional a success result.
The chained execution stops on the first non-success StatusCode in the chain and returns it, or continues until the end and returns the last produced StatusCode.
For example:
Definition at line 163 of file StatusCode.h.
|
inlinestaticnoexcept |
Default Gaudi StatusCode category.
Definition at line 310 of file StatusCode.h.
|
inlineprivate |
Project onto the default StatusCode values.
Definition at line 320 of file StatusCode.h.
|
inline |
|
inline |
|
private |
Helper function to avoid circular dependency between GaudiException.h and StatusCode.h.
Definition at line 49 of file StatusCode.cpp.
|
inlineprivate |
Helper to invoke a callable and return the resulting StatusCode or this, if the callable returns void.
Definition at line 269 of file StatusCode.h.
|
inline |
Definition at line 140 of file StatusCode.h.
|
inline |
Allow discarding a StatusCode without warning.
Definition at line 139 of file StatusCode.h.
|
inline |
Definition at line 129 of file StatusCode.h.
|
inline |
Definition at line 318 of file StatusCode.h.
|
inline |
Definition at line 314 of file StatusCode.h.
|
inline |
|
inlineexplicit |
|
inline |
Ternary logic operator with RECOVERABLE being the "third" state.
Definition at line 332 of file StatusCode.h.
|
defaultnoexcept |
|
inline |
Ternary logic operator with RECOVERABLE being the "third" state.
Definition at line 342 of file StatusCode.h.
|
inline |
Chain code blocks making the execution conditional a failure result.
Inverse of StatusCode::andThen(), the passed function gets invoked only if if the StatusCode is a failure, in which case it either pass it on or overrides it, If the StatusCode is a success, it is passed on.
For example:
Definition at line 185 of file StatusCode.h.
|
inline |
Throw a GaudiException in case of failures.
It can be chained with StatusCode::then, behaving as a pass-through for a success StatusCode, while for non-success a GaudiException is thrown, propagating the failure into the exception (using the StatusCode field of the exception).
For example:
Definition at line 206 of file StatusCode.h.
|
inline |
Throw a GaudiException in case of failures.
See above, but in this case the message is not specified explicitly, but taken from message()
Definition at line 215 of file StatusCode.h.
|
friend |
Definition at line 235 of file StatusCode.h.
|
friend |
|
friend |
|
friend |
|
friend |
Definition at line 226 of file StatusCode.h.
|
friend |
Check if StatusCode value and category are the same.
0(FAILURE)
and 1(SUCCESS)
the category is ignored sc==StatusCode::SUCCESS
is equivalent to sc.isSuccess()
for all categories Definition at line 325 of file StatusCode.h.
|
friend |
|
friend |
|
staticconstexpr |
Definition at line 101 of file StatusCode.h.
|
private |
The status code category.
Definition at line 259 of file StatusCode.h.
|
private |
The status code value.
Definition at line 260 of file StatusCode.h.
|
staticconstexpr |
Definition at line 102 of file StatusCode.h.
|
staticconstexpr |
Definition at line 100 of file StatusCode.h.