1 #ifndef GAUDIKERNEL_STATUSCODE_H 2 #define GAUDIKERNEL_STATUSCODE_H 4 #include "boost/preprocessor/facilities/overload.hpp" 66 constexpr
Category() noexcept =
default;
70 virtual const char*
name()
const = 0;
80 virtual bool isRecoverable( code_t code )
const {
return code ==
static_cast<code_t
>( ErrorCode::RECOVERABLE ); }
84 static const Category& default_category() noexcept;
89 constexpr
const static auto RECOVERABLE = ErrorCode::RECOVERABLE;
95 template <typename T, typename = typename std::enable_if<is_StatusCode_enum<T>::value>
::type>
104 bool checked =
false ) noexcept
105 : m_cat( &cat ), m_code( code ), m_checked( checked )
113 StatusCode(
const StatusCode& rhs ) noexcept : m_cat( rhs.m_cat ), m_code( rhs.m_code ), m_checked( rhs.m_checked )
115 rhs.m_checked =
true;
121 rhs.m_checked =
true;
127 if (
UNLIKELY( s_checking ) ) check();
134 m_checked = std::exchange( rhs.m_checked,
true );
138 bool isSuccess()
const;
140 bool isRecoverable()
const;
143 explicit operator bool()
const {
return isSuccess(); }
245 mutable bool m_checked{
false};
258 #define STATUSCODE_ENUM_DECL( ENUM ) \ 260 struct is_StatusCode_enum<ENUM> : std::true_type { \ 261 static const StatusCode::Category& instance; \ 267 #define STATUSCODE_ENUM_IMPL( ... ) BOOST_PP_OVERLOAD( STATUSCODE_ENUM_IMPL_, __VA_ARGS__ )( __VA_ARGS__ ) 269 #define STATUSCODE_ENUM_IMPL_1( ENUM ) \ 270 const StatusCode::Category& is_StatusCode_enum<ENUM>::instance = StatusCode::default_category(); 272 #define STATUSCODE_ENUM_IMPL_2( ENUM, CATEGORY ) \ 273 const StatusCode::Category& is_StatusCode_enum<ENUM>::instance = CATEGORY{}; 290 return ( m_code == static_cast<code_t>(
ErrorCode::SUCCESS ) || m_cat->isSuccess( m_code ) );
296 return m_cat->isRecoverable( m_code );
301 bool save_checked = m_checked;
303 m_checked = save_checked;
353 #endif // GAUDIKERNEL_STATUSCODE_H
StatusCode operator|(StatusCode lhs, const StatusCode &rhs)
Ternary OR operator.
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 checked() const
Has the StatusCode been checked?
bool m_checked
If the StatusCode has been checked.
The category assigned to a StatusCode.
Category
integration category
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)
virtual bool isSuccess(code_t code) const
Is code considered success ?
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
const StatusCode & setChecked(bool checked=true) const
Check/uncheck StatusCode.
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.
StatusCode & setChecked(bool checked=true)
friend std::ostream & operator<<(std::ostream &s, const StatusCode &sc)
StatusCode(T sc, bool checked=false) noexcept
Constructor from enum type (allowing implicit conversion)
virtual bool isRecoverable(code_t code) const
Is code considered recoverable ?
const StatusCode::Category & getCategory() const
Retrieve category (does not "check" the StatusCode)
This class is used for returning status codes from appropriate routines.
friend bool operator!=(const StatusCode &lhs, const StatusCode &rhs)
Simple RAII class to ignore unchecked StatusCode instances in a scope.
StatusCode operator&(StatusCode lhs, const StatusCode &rhs)
Ternary AND operator.
static bool s_checking
Global flag to control if StatusCode need to be checked.
bool isRecoverable() const
bool operator==(const StatusCode &lhs, const StatusCode &rhs)
const StatusCode & ignore() const
Ignore/check StatusCode.
bool & operator|=(bool &lhs, const StatusCode &sc)
Boolean OR assignment operator.
ErrorCode default_value() const
Project onto the default StatusCode values.
static GAUDI_API void disableChecking()
code_t getCode() const
Retrieve value ("checks" the StatusCode)
std::string message() const
Description (or name) of StatusCode value.
bool & operator&=(bool &lhs, const StatusCode &sc)
Boolean AND assignment operator.
StatusCode(StatusCode &&rhs) noexcept
Move constructor.
virtual std::string message(code_t code) const
Description for code within this category.
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.
unsigned long code_t
type of StatusCode value