13#include <boost/preprocessor/facilities/overload.hpp>
61#if !defined( __CLING__ )
82 virtual const char*
name()
const = 0;
85 virtual std::string
message(
code_t code )
const {
return "UNKNOWN(" + std::to_string( code ) +
")"; }
96 static const Category& default_category() noexcept;
107 template <typename T>
130 bool isRecoverable()
const;
162 template <
typename F,
typename... ARGS>
165 return i_invoke( std::forward<F>( f ), std::forward<ARGS>( args )... );
184 template <
typename F,
typename... ARGS>
187 return i_invoke( std::forward<F>( f ), std::forward<ARGS>( args )... );
262 ErrorCode default_value()
const;
265 [[noreturn]]
void i_doThrow( std::string_view message, std::string_view tag )
const;
268 template <
typename... ARGS, std::invocable<ARGS...> F>
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 } };
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
bool operator==(const StatusCode &lhs, const StatusCode &rhs)
This class is used for returning status codes from appropriate routines.
StatusCode(const StatusCode &rhs) noexcept=default
Copy constructor.
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.
StatusCode orElse(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a failure result.
friend bool & operator|=(bool &lhs, const StatusCode &sc)
Boolean OR assignment operator.
ErrorCode default_value() const
Project onto the default StatusCode values.
StatusCode(code_t code, const StatusCode::Category &cat) noexcept
Constructor from code_t and category (explicit conversion only)
friend StatusCode operator&(StatusCode lhs, const StatusCode &rhs)
Ternary AND operator.
StatusCode & operator&=(const StatusCode &rhs)
Ternary logic operator with RECOVERABLE being the "third" state.
code_t m_code
The status code value.
StatusCode()=default
Default constructor.
const StatusCode & orThrow(std::string_view tag="") const
Throw a GaudiException in case of failures.
StatusCode & operator=(const StatusCode &rhs) noexcept=default
friend StatusCode operator|(StatusCode lhs, const StatusCode &rhs)
Ternary OR operator.
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
StatusCode(code_t code) noexcept
Constructor from code_t in the default category (explicit conversion only)
unsigned long code_t
type of StatusCode value
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...
const StatusCode & orThrow(std::string_view message, std::string_view tag) const
Throw a GaudiException in case of failures.
~StatusCode()=default
Destructor.
friend bool operator<(const StatusCode &lhs, const StatusCode &rhs)
Comparison (values are grouped by category first)
std::string message() const
Description (or name) of StatusCode value.
constexpr static const auto RECOVERABLE
friend bool operator!=(const StatusCode &lhs, const StatusCode &rhs)
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
const Category * m_cat
The status code category.
friend std::ostream & operator<<(std::ostream &s, const StatusCode &sc)
void i_doThrow(std::string_view message, std::string_view tag) const
Helper function to avoid circular dependency between GaudiException.h and StatusCode....
StatusCode(StatusCode &&rhs) noexcept=default
Move constructor.
bool isRecoverable() const
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
const StatusCode::Category & getCategory() const
Retrieve category.
code_t getCode() const
Retrieve value.
The category assigned to a StatusCode.
virtual bool isSuccess(code_t code) const
Is code considered success ?
constexpr Category() noexcept=default
virtual std::string message(code_t code) const
Description for code within this category.
virtual const char * name() const =0
Name of the category.
virtual bool isRecoverable(code_t code) const
Is code considered recoverable ?