| The Gaudi Framework v27r1

- 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
61 #ifndef __GCCXML__
62 StatusCode( StatusCode&& rhs ) noexcept:
64 d_code(rhs.d_code), m_checked(rhs.m_checked),
65 m_severity( std::move(rhs.m_severity) )
66 { rhs.m_checked = true; }
67 #endif
68
70 ~StatusCode()
71 { if (UNLIKELY(s_checking)) check(); }
72
76 bool isSuccess() const {
77 m_checked = true;
78 return (d_code == SUCCESS);
79 }
80
86 bool isFailure() const { return !isSuccess(); }
87 bool isRecoverable() const {
88 m_checked = true;
89 return (d_code == RECOVERABLE);
90 }
91
93 unsigned long getCode() const{
94 m_checked = true;
95 return d_code;
96 }
97
99 void setCode(unsigned long value) {
100 m_checked = false;
101 d_code = value;
102 }
103
105 void setChecked() const{
106 m_checked = true;
107 }
108 void ignore() const { setChecked(); }
109
111 operator unsigned long() const { return getCode(); }
112
114 GAUDI_API const IssueSeverity& severity() const;
115
117 StatusCode& operator=(unsigned long value) {
118 setCode(value);
119 return *this;
120 }
121 StatusCode& operator=(const StatusCode& rhs){
122 if (this == &rhs) return *this; // Protection against self-assignment
123 d_code = rhs.d_code;
124 m_checked = rhs.m_checked;
125 rhs.m_checked = true;
126 m_severity = rhs.m_severity;
127 return *this;
128 }
129
131 friend bool operator< ( const StatusCode& a, const StatusCode& b ) {
132 return a.d_code < b.d_code;
133 }
134
136 friend bool operator> ( const StatusCode& a, const StatusCode& b ) {
137 return a.d_code > b.d_code;
138 }
139
140 #ifndef _WIN32
141 operator IgnoreError() const {
142 m_checked = true;
143 return IgnoreError();
144 }
145 #endif
146
147 static GAUDI_API void enableChecking();
148 static GAUDI_API void disableChecking();
149 static GAUDI_API bool checkingEnabled();
150
165 class ScopedDisableChecking {
166 bool m_enabled;
167 public:
168 ScopedDisableChecking(): m_enabled(StatusCode::checkingEnabled()) {
169 if (m_enabled) StatusCode::disableChecking();
170 }
171 ~ScopedDisableChecking() {
172 if (m_enabled) StatusCode::enableChecking();
173 }
174 };
175
176 protected:
178 unsigned long d_code = SUCCESS;
179 mutable bool m_checked = false;
180 std::shared_ptr<const IssueSeverity> m_severity;
181
182 static bool s_checking;
183
184 private:
185 void check();
186 };
187
188 inline std::ostream& operator<< ( std::ostream& s , const StatusCode& sc )
189 {
190 if ( sc.isSuccess() ) { return s << "SUCCESS" ; }
191 if ( sc.isRecoverable() ) { return s << "RECOVERABLE" ; }
192 s << "FAILURE" ;
193 return ( StatusCode::FAILURE != sc.getCode() ) ? s << "(" << sc.getCode() << ")"
194 : s ;
195 }
196
197 #endif // GAUDIKERNEL_STATUSCODES_H
198
199
200
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
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
StatusCode::severity
GAUDI_API const IssueSeverity & severity() const
Severity.
Definition: StatusCode.cpp:31
std::shared_ptr< const IssueSeverity >
Kernel.h
StatusCode::setCode
void setCode(unsigned long value)
Set the status code by value.
Definition: StatusCode.h:99
IssueSeverity
Definition: IssueSeverity.h:42
StatusCode::check
void check()
Definition: StatusCode.cpp:36
StatusCode::getCode
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:93
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
StatusCode::m_checked
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:179
StatusCode::ScopedDisableChecking::~ScopedDisableChecking
~ScopedDisableChecking()
Definition: StatusCode.h:171
std
STL namespace.
StatusCode::~StatusCode
~StatusCode()
Destructor.
Definition: StatusCode.h:70
StatusCode::enableChecking
static GAUDI_API void enableChecking()
Definition: StatusCode.cpp:19
StatusCode::checkingEnabled
static GAUDI_API bool checkingEnabled()
Definition: StatusCode.cpp:27
merge_files.sc
int sc
Definition: merge_files.py:167
operator<<
std::ostream & operator<<(std::ostream &s, const StatusCode &sc)
Definition: StatusCode.h:188
StatusCode::RECOVERABLE
Definition: StatusCode.h:31
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::operator<
friend bool operator<(const StatusCode &a, const StatusCode &b)
Comparison operator.
Definition: StatusCode.h:131
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:165
StatusCode::StatusCode
StatusCode(IssueSeverity &&is)
Definition: StatusCode.h:45
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
StatusCode::s_checking
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:182
StatusCode::d_code
unsigned long d_code
The status code.
Definition: StatusCode.h:178
StatusCode::isRecoverable
bool isRecoverable() const
Definition: StatusCode.h:87
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:121
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::StatusCode
StatusCode()=default
Constructor.
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
StatusCode::operator>
friend bool operator>(const StatusCode &a, const StatusCode &b)
Comparison operator.
Definition: StatusCode.h:136
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:180
StatusCode::ScopedDisableChecking::ScopedDisableChecking
ScopedDisableChecking()
Definition: StatusCode.h:168
StatusCode::setChecked
void setChecked() const
Ignore the checking code;.
Definition: StatusCode.h:105
StatusCode::ScopedDisableChecking::m_enabled
bool m_enabled
Definition: StatusCode.h:166
StatusCode::operator=
StatusCode & operator=(unsigned long value)
Assignment operator.
Definition: StatusCode.h:117