| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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
6 #include "GaudiKernel/Kernel.h"
7 #include "GaudiKernel/IssueSeverity.h"
8
9 #include <memory>
10
21 class IMessageSvc;
22 class IStatusCodeSvc;
23
24 class IgnoreError {};
25
26 class StatusCode final {
27 public:
28 enum {
29 FAILURE = 0,
30 SUCCESS = 1,
31 RECOVERABLE = 2
32 };
33
35 StatusCode() = default;
36
37 StatusCode( unsigned long code, IssueSeverity&& sev ):
38 d_code(code) {
39 try { // ensure that we do not throw even if we cannot move the severity
40 m_severity = std::make_shared<const IssueSeverity>(std::move(sev));
41 }
42 catch (...) {}
43 }
44
45 StatusCode( IssueSeverity&& is) :
46 StatusCode( is.getLevel() == IssueSeverity::RECOVERABLE ?
47 StatusCode::RECOVERABLE :
48 ( is.getLevel() < IssueSeverity::ERROR ?
49 StatusCode::SUCCESS :
50 StatusCode::FAILURE )
51 , std::move(is) ) { }
52
53 StatusCode( unsigned long code, bool checked = false ):
54 d_code(code),m_checked(checked) {}
55
56 StatusCode( const StatusCode& rhs ):
57 d_code(rhs.d_code), m_checked(rhs.m_checked),
58 m_severity(rhs.m_severity)
59 { rhs.m_checked = true; }
60
62 StatusCode( StatusCode&& rhs ) noexcept:
63 d_code(rhs.d_code), m_checked(rhs.m_checked),
64 m_severity( std::move(rhs.m_severity) )
65 { rhs.m_checked = true; }
66
68 ~StatusCode()
69 { if (UNLIKELY(s_checking)) check(); }
70
74 bool isSuccess() const {
75 m_checked = true;
76 return (d_code == SUCCESS);
77 }
78
84 bool isFailure() const { return !isSuccess(); }
85 bool isRecoverable() const {
86 m_checked = true;
87 return (d_code == RECOVERABLE);
88 }
89
91 unsigned long getCode() const{
92 m_checked = true;
93 return d_code;
94 }
95
97 void setCode(unsigned long value) {
98 m_checked = false;
99 d_code = value;
100 }
101
103 void setChecked() const{
104 m_checked = true;
105 }
106 void ignore() const { setChecked(); }
107
109 operator unsigned long() const { return getCode(); }
110
112 GAUDI_API const IssueSeverity& severity() const;
113
115 StatusCode& operator=(unsigned long value) {
116 setCode(value);
117 return *this;
118 }
119 StatusCode& operator=(const StatusCode& rhs){
120 if (this == &rhs) return *this; // Protection against self-assignment
121 d_code = rhs.d_code;
122 m_checked = rhs.m_checked;
123 rhs.m_checked = true;
124 m_severity = rhs.m_severity;
125 return *this;
126 }
127
129 friend bool operator< ( const StatusCode& a, const StatusCode& b ) {
130 return a.d_code < b.d_code;
131 }
132
134 friend bool operator> ( const StatusCode& a, const StatusCode& b ) {
135 return a.d_code > b.d_code;
136 }
137
138 #ifndef _WIN32
139 operator IgnoreError() const {
140 m_checked = true;
141 return IgnoreError();
142 }
143 #endif
144
145 static GAUDI_API void enableChecking();
146 static GAUDI_API void disableChecking();
147 static GAUDI_API bool checkingEnabled();
148
163 class ScopedDisableChecking {
164 bool m_enabled;
165 public:
166 ScopedDisableChecking(): m_enabled(StatusCode::checkingEnabled()) {
167 if (m_enabled) StatusCode::disableChecking();
168 }
169 ~ScopedDisableChecking() {
170 if (m_enabled) StatusCode::enableChecking();
171 }
172 };
173
174 protected:
176 unsigned long d_code = SUCCESS;
177 mutable bool m_checked = false;
178 std::shared_ptr<const IssueSeverity> m_severity;
179
180 static bool s_checking;
181
182 private:
183 void check();
184 };
185
186 inline std::ostream& operator<< ( std::ostream& s , const StatusCode& sc )
187 {
188 if ( sc.isSuccess() ) { return s << "SUCCESS" ; }
189 if ( sc.isRecoverable() ) { return s << "RECOVERABLE" ; }
190 s << "FAILURE" ;
191 return ( StatusCode::FAILURE != sc.getCode() ) ? s << "(" << sc.getCode() << ")"
192 : s ;
193 }
194
195 #endif // GAUDIKERNEL_STATUSCODES_H
196
197
198
StatusCode::StatusCode
StatusCode(unsigned long code, IssueSeverity &&sev)
Definition: StatusCode.h:37
StatusCode::StatusCode
StatusCode(unsigned long code, bool checked=false)
Definition: StatusCode.h:53
std::shared_ptr< const IssueSeverity >
Kernel.h
StatusCode::setCode
void setCode(unsigned long value)
Set the status code by value.
Definition: StatusCode.h:97
IssueSeverity
Definition: IssueSeverity.h:42
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::getCode
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:91
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
StatusCode::m_checked
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:177
GaudiPython.Bindings.SUCCESS
SUCCESS
Definition: Bindings.py:52
StatusCode::ScopedDisableChecking::~ScopedDisableChecking
~ScopedDisableChecking()
Definition: StatusCode.h:169
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
std
STL namespace.
StatusCode::~StatusCode
~StatusCode()
Destructor.
Definition: StatusCode.h:68
StatusCode::enableChecking
static GAUDI_API void enableChecking()
Definition: StatusCode.cpp:19
operator<<
std::ostream & operator<<(std::ostream &s, const StatusCode &sc)
Definition: StatusCode.h:186
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
operator>
bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:208
GaudiPython.Bindings.FAILURE
FAILURE
Definition: Bindings.py:53
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IssueSeverity.h
StatusCode::ScopedDisableChecking
Simple RAII class to ignore unchecked StatusCode instances in a scope.
Definition: StatusCode.h:163
StatusCode::StatusCode
StatusCode(IssueSeverity &&is)
Definition: StatusCode.h:45
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
StatusCode::s_checking
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:180
StatusCode::d_code
unsigned long d_code
The status code.
Definition: StatusCode.h:176
StatusCode::isRecoverable
bool isRecoverable() const
Definition: StatusCode.h:85
StatusCode::StatusCode
StatusCode(const StatusCode &rhs)
Definition: StatusCode.h:56
std::move
T move(T...args)
StatusCode::operator=
StatusCode & operator=(const StatusCode &rhs)
Definition: StatusCode.h:119
operator<
bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:185
IgnoreError
Definition: StatusCode.h:24
gaudirun.s
string s
Definition: gaudirun.py:245
MSG::ERROR
Definition: IMessageSvc.h:21
StatusCode::disableChecking
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:23
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:106
StatusCode::StatusCode
StatusCode(StatusCode &&rhs) noexcept
Move constructor.
Definition: StatusCode.h:62
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
IStatusCodeSvc
Definition: IStatusCodeSvc.h:7
std::ostream
STL class.
StatusCode::m_severity
std::shared_ptr< const IssueSeverity > m_severity
Pointer to a IssueSeverity.
Definition: StatusCode.h:178
StatusCode::ScopedDisableChecking::ScopedDisableChecking
ScopedDisableChecking()
Definition: StatusCode.h:166
StatusCode::setChecked
void setChecked() const
Ignore the checking code;.
Definition: StatusCode.h:103
StatusCode::ScopedDisableChecking::m_enabled
bool m_enabled
Definition: StatusCode.h:164
StatusCode::operator=
StatusCode & operator=(unsigned long value)
Assignment operator.
Definition: StatusCode.h:115