| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

StatusCode.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_STATUSCODE_H
2 #define GAUDIKERNEL_STATUSCODE_H
3
4 #include <ostream>
5 #include <utility>
6
7 #include "GaudiKernel/Kernel.h"
8
19 class IMessageSvc;
20 class IStatusCodeSvc;
21
22 class IgnoreError
23 {
24 };
25
26 class StatusCode final
27 {
28 public:
29 enum { FAILURE = 0, SUCCESS = 1, RECOVERABLE = 2 };
30
32 StatusCode() = default;
33
34 StatusCode( unsigned long code, bool checked = false ) : d_code( code ), m_checked( checked ) {}
35
36 StatusCode( const StatusCode& rhs ) : d_code( rhs.d_code ), m_checked( rhs.m_checked ) { rhs.m_checked = true; }
37
39 StatusCode( StatusCode&& rhs ) noexcept : d_code( rhs.d_code ), m_checked( rhs.m_checked ) { rhs.m_checked = true; }
40
42 ~StatusCode()
43 {
44 if ( UNLIKELY( s_checking ) ) check();
45 }
46
50 bool isSuccess() const
51 {
52 m_checked = true;
53 return ( d_code == SUCCESS );
54 }
55
61 bool isFailure() const { return !isSuccess(); }
62 bool isRecoverable() const
63 {
64 m_checked = true;
65 return ( d_code == RECOVERABLE );
66 }
67
69 unsigned long getCode() const
70 {
71 m_checked = true;
72 return d_code;
73 }
74
76 void setCode( unsigned long value )
77 {
78 m_checked = false;
79 d_code = value;
80 }
81
83 void setChecked() const { m_checked = true; }
84 void ignore() const { setChecked(); }
85
87 bool checked() const { return m_checked; }
88
90 operator unsigned long() const { return getCode(); }
91
93 StatusCode& operator=( unsigned long value )
94 {
95 setCode( value );
96 return *this;
97 }
98 StatusCode& operator=( const StatusCode& rhs )
99 {
100 d_code = rhs.d_code;
101 m_checked = std::exchange( rhs.m_checked, true );
102 return *this;
103 }
104
106 friend bool operator<( const StatusCode& a, const StatusCode& b ) { return a.d_code < b.d_code; }
107
109 friend bool operator>( const StatusCode& a, const StatusCode& b ) { return a.d_code > b.d_code; }
110
111 #ifndef _WIN32
112 operator IgnoreError() const
113 {
114 m_checked = true;
115 return IgnoreError();
116 }
117 #endif
118
119 static GAUDI_API void enableChecking();
120 static GAUDI_API void disableChecking();
121 static GAUDI_API bool checkingEnabled();
122
137 class ScopedDisableChecking
138 {
139 bool m_enabled;
140
141 public:
142 ScopedDisableChecking() : m_enabled( StatusCode::checkingEnabled() )
143 {
144 if ( m_enabled ) StatusCode::disableChecking();
145 }
146 ~ScopedDisableChecking()
147 {
148 if ( m_enabled ) StatusCode::enableChecking();
149 }
150 };
151
152 protected:
154 unsigned long d_code = SUCCESS;
155 mutable bool m_checked = false;
156
157 static bool s_checking;
158
159 private:
160 void check();
161 };
162
163 inline std::ostream& operator<<( std::ostream& s, const StatusCode& sc )
164 {
165 if ( sc.isSuccess() ) {
166 return s << "SUCCESS";
167 }
168 if ( sc.isRecoverable() ) {
169 return s << "RECOVERABLE";
170 }
171 s << "FAILURE";
172 return ( StatusCode::FAILURE != sc.getCode() ) ? s << "(" << sc.getCode() << ")" : s;
173 }
174
175 #endif // GAUDIKERNEL_STATUSCODES_H
StatusCode::StatusCode
StatusCode(unsigned long code, bool checked=false)
Definition: StatusCode.h:34
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
Kernel.h
StatusCode::setCode
void setCode(unsigned long value)
Set the status code by value.
Definition: StatusCode.h:76
StatusCode::getCode
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:69
StatusCode::checked
bool checked() const
Has the StatusCode been checked?
Definition: StatusCode.h:87
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
StatusCode::m_checked
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:155
GaudiPython.Bindings.SUCCESS
SUCCESS
Definition: Bindings.py:56
StatusCode::ScopedDisableChecking::~ScopedDisableChecking
~ScopedDisableChecking()
Definition: StatusCode.h:146
StatusCode::~StatusCode
~StatusCode()
Destructor.
Definition: StatusCode.h:42
StatusCode::enableChecking
static GAUDI_API void enableChecking()
Definition: StatusCode.cpp:18
operator<<
std::ostream & operator<<(std::ostream &s, const StatusCode &sc)
Definition: StatusCode.h:163
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:61
GaudiPython.Bindings.FAILURE
FAILURE
Definition: Bindings.py:57
StatusCode::operator<
friend bool operator<(const StatusCode &a, const StatusCode &b)
Comparison operator.
Definition: StatusCode.h:106
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode::ScopedDisableChecking
Simple RAII class to ignore unchecked StatusCode instances in a scope.
Definition: StatusCode.h:137
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:38
StatusCode::s_checking
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:157
StatusCode::d_code
unsigned long d_code
The status code.
Definition: StatusCode.h:154
StatusCode::isRecoverable
bool isRecoverable() const
Definition: StatusCode.h:62
StatusCode::StatusCode
StatusCode(const StatusCode &rhs)
Definition: StatusCode.h:36
StatusCode::operator=
StatusCode & operator=(const StatusCode &rhs)
Definition: StatusCode.h:98
IgnoreError
Definition: StatusCode.h:22
gaudirun.s
string s
Definition: gaudirun.py:253
StatusCode::disableChecking
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:20
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:84
StatusCode::operator>
friend bool operator>(const StatusCode &a, const StatusCode &b)
Comparison operator.
Definition: StatusCode.h:109
StatusCode::StatusCode
StatusCode(StatusCode &&rhs) noexcept
Move constructor.
Definition: StatusCode.h:39
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
IStatusCodeSvc
Definition: IStatusCodeSvc.h:7
std::ostream
STL class.
StatusCode::ScopedDisableChecking::ScopedDisableChecking
ScopedDisableChecking()
Definition: StatusCode.h:142
StatusCode::setChecked
void setChecked() const
Ignore the checking code;.
Definition: StatusCode.h:83
StatusCode::ScopedDisableChecking::m_enabled
bool m_enabled
Definition: StatusCode.h:139
StatusCode::operator=
StatusCode & operator=(unsigned long value)
Assignment operator.
Definition: StatusCode.h:93