Go to the documentation of this file.
11 #ifndef GAUDIKERNEL_STATUSCODE_H
12 #define GAUDIKERNEL_STATUSCODE_H
14 #include <boost/preprocessor/facilities/overload.hpp>
17 #include <type_traits>
62 #if __cplusplus >= 201703L && !defined( __CLING__ )
83 virtual const char*
name()
const = 0;
97 static const Category& default_category() noexcept;
102 constexpr const static auto RECOVERABLE =
ErrorCode::RECOVERABLE;
128 bool isSuccess()
const;
130 bool isRecoverable()
const;
133 explicit operator bool()
const {
return isSuccess(); }
162 template <
typename F,
typename... ARGS>
164 if ( isFailure() )
return *
this;
165 return i_invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
184 template <
typename F,
typename... ARGS>
186 if ( isSuccess() )
return *
this;
187 return i_invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
207 if ( isFailure() ) i_doThrow(
message, tag );
216 if ( isFailure() ) i_doThrow(
message(), tag );
262 ErrorCode default_value()
const;
265 [[noreturn]]
void i_doThrow( std::string_view
message, std::string_view tag )
const;
268 template <
typename F,
typename... ARGS,
typename = std::enable_if_t<std::is_invocable_v<F, ARGS...>>>
270 if constexpr ( std::is_invocable_r_v<StatusCode, F, ARGS...> ) {
271 return std::invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
274 std::invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
286 #define STATUSCODE_ENUM_DECL( ENUM ) \
288 struct is_StatusCode_enum<ENUM> : std::true_type { \
289 static const StatusCode::Category& instance; \
295 #define STATUSCODE_ENUM_IMPL( ... ) BOOST_PP_OVERLOAD( STATUSCODE_ENUM_IMPL_, __VA_ARGS__ )( __VA_ARGS__ )
297 #define STATUSCODE_ENUM_IMPL_1( ENUM ) \
298 const StatusCode::Category& is_StatusCode_enum<ENUM>::instance = StatusCode::default_category();
300 #define STATUSCODE_ENUM_IMPL_2( ENUM, CATEGORY ) \
301 const StatusCode::Category& is_StatusCode_enum<ENUM>::instance = CATEGORY{};
334 static constexpr
StatusCode::code_t AND[3][3] = { { 0, 0, 0 }, { 0, 1, 2 }, { 0, 2, 2 } };
344 static constexpr
StatusCode::code_t OR[3][3] = { { 0, 1, 2 }, { 1, 1, 1 }, { 2, 1, 2 } };
352 #endif // GAUDIKERNEL_STATUSCODE_H
const StatusCode::Category & getCategory() const
Retrieve category.
constexpr Category() noexcept=default
bool isRecoverable() const
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...
virtual bool isSuccess(code_t code) const
Is code considered success ?
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
const StatusCode & orThrow(std::string_view message, std::string_view tag) const
Throw a GaudiException in case of failures.
StatusCode & operator|=(const StatusCode &rhs)
Ternary logic operator with RECOVERABLE being the "third" state.
std::string message() const
Description (or name) of StatusCode value.
StatusCode orElse(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a failure result.
code_t m_code
The status code value.
friend bool operator!=(const StatusCode &lhs, const StatusCode &rhs)
const StatusCode & orThrow(std::string_view tag="") const
Throw a GaudiException in case of failures.
unsigned long code_t
type of StatusCode value
friend bool operator<(const StatusCode &lhs, const StatusCode &rhs)
Comparison (values are grouped by category first)
bool operator==(const StatusCode &lhs, const StatusCode &rhs)
friend StatusCode operator&(StatusCode lhs, const StatusCode &rhs)
Ternary AND operator.
StatusCode(code_t code, const StatusCode::Category &cat) noexcept
Constructor from code_t and category (explicit conversion only)
StatusCode(const StatusCode &rhs) noexcept=default
Copy constructor.
friend StatusCode operator|(StatusCode lhs, const StatusCode &rhs)
Ternary OR operator.
ErrorCode default_value() const
Project onto the default StatusCode values.
friend std::ostream & operator<<(std::ostream &s, const StatusCode &sc)
friend bool & operator&=(bool &lhs, const StatusCode &sc)
Boolean AND assignment operator.
StatusCode & operator&=(const StatusCode &rhs)
Ternary logic operator with RECOVERABLE being the "third" state.
const Category * m_cat
The status code category.
friend bool & operator|=(bool &lhs, const StatusCode &sc)
Boolean OR assignment operator.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
StatusCode & operator=(const StatusCode &rhs) noexcept=default
StatusCode(code_t code) noexcept
Constructor from code_t in the default category (explicit conversion only)
code_t getCode() const
Retrieve value.
StatusCode(StatusCode &&rhs) noexcept=default
Move constructor.
virtual const char * name() const =0
Name of the category.
~StatusCode()=default
Destructor.
virtual bool isRecoverable(code_t code) const
Is code considered recoverable ?
virtual std::string message(code_t code) const
Description for code within this category.