11 #ifndef GAUDIKERNEL_STATUSCODE_H 12 #define GAUDIKERNEL_STATUSCODE_H 14 #include "boost/preprocessor/facilities/overload.hpp" 17 #include <type_traits> 75 constexpr
Category() noexcept =
default;
79 virtual const char*
name()
const = 0;
112 bool checked =
false ) noexcept
120 rhs.m_checked =
true;
125 rhs.m_checked =
true;
136 m_checked = std::exchange( rhs.m_checked,
true );
193 template <
typename F,
typename... ARGS>
196 return i_invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
215 template <
typename F,
typename... ARGS>
218 return i_invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
315 template <
typename F,
typename... ARGS,
typename = std::enable_if_t<std::is_invocable_v<F, ARGS...>>>
317 if constexpr ( std::is_invocable_r_v<StatusCode, F, ARGS...> ) {
318 return std::invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
321 std::invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
333 #define STATUSCODE_ENUM_DECL( ENUM ) \ 335 struct is_StatusCode_enum<ENUM> : std::true_type { \ 336 static const StatusCode::Category& instance; \ 342 #define STATUSCODE_ENUM_IMPL( ... ) BOOST_PP_OVERLOAD( STATUSCODE_ENUM_IMPL_, __VA_ARGS__ )( __VA_ARGS__ ) 344 #define STATUSCODE_ENUM_IMPL_1( ENUM ) \ 345 const StatusCode::Category& is_StatusCode_enum<ENUM>::instance = StatusCode::default_category(); 347 #define STATUSCODE_ENUM_IMPL_2( ENUM, CATEGORY ) \ 348 const StatusCode::Category& is_StatusCode_enum<ENUM>::instance = CATEGORY{}; 421 #endif // GAUDIKERNEL_STATUSCODE_H code_t getCode() const
Retrieve value ("checks" the StatusCode)
bool checked() const
Has the StatusCode been checked?
StatusCode operator|(StatusCode lhs, const StatusCode &rhs)
Ternary OR operator.
void check()
Do StatusCode check.
code_t m_code
The status code value.
friend bool operator<(const StatusCode &lhs, const StatusCode &rhs)
Comparison (values are grouped by category first)
bool m_checked
If the StatusCode has been checked.
The category assigned to a StatusCode.
constexpr static const auto RECOVERABLE
StatusCode & operator=(const StatusCode &rhs) noexcept
StatusCode(code_t code, const StatusCode::Category &cat=default_category(), bool checked=false) noexcept
Constructor from code_t in the default category (explicit conversion only)
constexpr static const auto SUCCESS
virtual const char * name() const =0
Name of the category.
StatusCode(code_t code, bool checked) noexcept
Constructor from code_t and category (explicit conversion only)
static GAUDI_API void enableChecking()
StatusCode(const StatusCode &rhs) noexcept
Copy constructor.
static GAUDI_API bool checkingEnabled()
StatusCode & setChecked(bool checked=true)
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
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::Category & getCategory() const
Retrieve category (does not "check" the StatusCode)
virtual bool isSuccess(code_t code) const
Is code considered success ?
friend std::ostream & operator<<(std::ostream &s, const StatusCode &sc)
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
virtual std::string message(code_t code) const
Description for code within this category.
This class is used for returning status codes from appropriate routines.
virtual bool isRecoverable(code_t code) const
Is code considered recoverable ?
friend bool operator!=(const StatusCode &lhs, const StatusCode &rhs)
static const Category & default_category() noexcept
Default Gaudi StatusCode category.
Simple RAII class to ignore unchecked StatusCode instances in a scope.
static bool s_checking
Global flag to control if StatusCode need to be checked.
std::string message() const
Description (or name) of StatusCode value.
StatusCode operator &(StatusCode lhs, const StatusCode &rhs)
Ternary AND operator.
bool operator==(const StatusCode &lhs, const StatusCode &rhs)
const StatusCode & ignore() const
Ignore/check StatusCode.
friend bool operator==(const StatusCode &lhs, const StatusCode &rhs)
Check if StatusCode value and category are the same.
StatusCode orThrow(std::string message, std::string tag) const
Throw a GaudiException in case of failures.
constexpr Category() noexcept=default
bool & operator|=(bool &lhs, const StatusCode &sc)
Boolean OR assignment operator.
bool isRecoverable() const
constexpr static const auto FAILURE
static GAUDI_API void disableChecking()
StatusCode()=default
Default constructor.
bool & operator&=(bool &lhs, const StatusCode &sc)
Boolean AND assignment operator.
StatusCode(StatusCode &&rhs) noexcept
Move constructor.
void i_doThrow(std::string message, std::string tag) const
Helper function to avoid circular dependency between GaudiException.h and StatusCode....
const StatusCode & setChecked(bool checked=true) const
Check/uncheck StatusCode.
ErrorCode default_value() const
Project onto the default StatusCode values.
const Category * m_cat
The status code category.
StatusCode & operator|=(const StatusCode &rhs)
Ternary logic operator with RECOVERABLE being the "third" state.
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.
unsigned long code_t
type of StatusCode value