Loading [MathJax]/extensions/tex2jax.js
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;
112 template <typename T, typename = std::enable_if_t<is_StatusCode_enum<T>::value>>
119 [[deprecated(
"use StatusCode(code_t, Category) instead" )]]
explicit StatusCode(
127 [[deprecated(
"use StatusCode(code_t) instead" )]]
explicit StatusCode(
code_t code,
bool ) noexcept
141 bool isSuccess()
const;
143 bool isRecoverable()
const;
146 explicit operator bool()
const {
return isSuccess(); }
179 template <
typename F,
typename... ARGS>
181 if ( isFailure() )
return *
this;
182 return i_invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
201 template <
typename F,
typename... ARGS>
203 if ( isSuccess() )
return *
this;
204 return i_invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
224 if ( isFailure() ) i_doThrow(
message, tag );
233 if ( isFailure() ) i_doThrow(
message(), tag );
238 [[deprecated(
"will be removed" )]]
bool checked()
const {
return true; }
278 [[deprecated(
"will be removed" )]]
static GAUDI_API void enableChecking();
279 [[deprecated(
"will be removed" )]]
static GAUDI_API void disableChecking();
280 [[deprecated(
"will be removed" )]]
static GAUDI_API bool checkingEnabled();
302 ErrorCode default_value()
const;
306 [[noreturn]]
void i_doThrow( std::string_view
message, std::string_view tag )
const;
309 template <
typename F,
typename... ARGS,
typename = std::enable_if_t<std::is_invocable_v<F, ARGS...>>>
311 if constexpr ( std::is_invocable_r_v<StatusCode, F, ARGS...> ) {
312 return std::invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
315 std::invoke( std::forward<F>( f ), std::forward<ARGS>(
args )... );
327 #define STATUSCODE_ENUM_DECL( ENUM ) \
329 struct is_StatusCode_enum<ENUM> : std::true_type { \
330 static const StatusCode::Category& instance; \
336 #define STATUSCODE_ENUM_IMPL( ... ) BOOST_PP_OVERLOAD( STATUSCODE_ENUM_IMPL_, __VA_ARGS__ )( __VA_ARGS__ )
338 #define STATUSCODE_ENUM_IMPL_1( ENUM ) \
339 const StatusCode::Category& is_StatusCode_enum<ENUM>::instance = StatusCode::default_category();
341 #define STATUSCODE_ENUM_IMPL_2( ENUM, CATEGORY ) \
342 const StatusCode::Category& is_StatusCode_enum<ENUM>::instance = CATEGORY{};
393 #endif // GAUDIKERNEL_STATUSCODE_H
const StatusCode::Category & getCategory() const
Retrieve category (does not "check" the StatusCode)
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.
bool checked() const
Has the StatusCode been checked?
StatusCode & setChecked(bool=true)
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.
void check()
Do StatusCode check.
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)
StatusCode(T sc, bool) noexcept
Constructor from enum type (allowing implicit conversion)
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.
const StatusCode & setChecked(bool=true) const
Check/uncheck StatusCode.
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.
Simple RAII class to ignore unchecked StatusCode instances in a scope.
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)
StatusCode(code_t code, bool) noexcept
Constructor from code_t and category (explicit conversion only)
code_t getCode() const
Retrieve value ("checks" the StatusCode)
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 ?
StatusCode(code_t code, const StatusCode::Category &cat, bool) noexcept
Constructor from code_t in the default category (explicit conversion only)
virtual std::string message(code_t code) const
Description for code within this category.