All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
8 
9 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
10 #include <memory>
11 #else
12 #include "boost/shared_ptr.hpp"
13 #endif
14 
25 class IMessageSvc;
26 class IStatusCodeSvc;
27 
28 class IgnoreError {};
29 
30 class StatusCode {
31 public:
32  enum {
33  FAILURE = 0,
34  SUCCESS = 1,
36  };
37 
40  d_code(SUCCESS), m_checked(false), m_severity() {}
41  StatusCode( unsigned long code, const IssueSeverity& sev ):
42  d_code(code),m_checked(false), m_severity() {
43  try { // ensure that we do not throw even if the we cannot copy the severity
45  }
46  catch (...) {}
47  }
48  StatusCode( unsigned long code, bool checked = false ):
49  d_code(code),m_checked(checked), m_severity() {}
50 
51  StatusCode( const StatusCode& rhs ):
52  d_code(rhs.d_code), m_checked(rhs.m_checked),
54  { rhs.m_checked = true; }
55 
58 
62  bool isSuccess() const {
63  m_checked = true;
64  return (d_code == SUCCESS);
65  }
66 
72  bool isFailure() const { return !isSuccess(); }
73  bool isRecoverable() const {
74  m_checked = true;
75  return (d_code == RECOVERABLE);
76  }
77 
79  unsigned long getCode() const{
80  m_checked = true;
81  return d_code;
82  }
83 
85  void setCode(unsigned long value) {
86  m_checked = false;
87  d_code = value;
88  }
89 
91  void setChecked() const{
92  m_checked = true;
93  }
94  void ignore() const { setChecked(); }
95 
97  operator unsigned long() const { return getCode(); }
98 
100  GAUDI_API const IssueSeverity& severity() const;
101 
103  StatusCode& operator=(unsigned long value) {
104  setCode(value);
105  return *this;
106  }
108  if (this == &rhs) return *this; // Protection against self-assignment
109  d_code = rhs.d_code;
110  m_checked = rhs.m_checked;
111  rhs.m_checked = true;
112  m_severity = rhs.m_severity;
113  return *this;
114  }
115 
117  friend bool operator< ( const StatusCode& a, const StatusCode& b ) {
118  return a.d_code < b.d_code;
119  }
120 
122  friend bool operator> ( const StatusCode& a, const StatusCode& b ) {
123  return a.d_code > b.d_code;
124  }
125 
126 #ifndef _WIN32
127  operator IgnoreError() const {
128  m_checked = true;
129  return IgnoreError();
130  }
131 #endif
132 
133  static GAUDI_API void enableChecking();
134  static GAUDI_API void disableChecking();
135 
136 protected:
138  unsigned long d_code;
139  mutable bool m_checked;
140 #if defined(__GCCXML__)
141  // This is because GCCXML needs to see something that is not too in conflict with
142  // boost or std
143  typedef IssueSeverity* SeverityPtr;
144 #elif defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
145  typedef std::shared_ptr<IssueSeverity> SeverityPtr;
146 #else
147  typedef boost::shared_ptr<IssueSeverity> SeverityPtr;
148 #endif
150 
151  static bool s_checking;
152 };
153 
154 inline std::ostream& operator<< ( std::ostream& s , const StatusCode& sc )
155 {
156  if ( sc.isSuccess() ) { return s << "SUCCESS" ; }
157  else if ( sc.isRecoverable() ) { return s << "RECOVERABLE" ; }
158  s << "FAILURE" ;
159  if ( StatusCode::FAILURE != sc.getCode() )
160  { s << "(" << sc.getCode() << ")" ;}
161  return s ;
162 }
163 
164 #endif // GAUDIKERNEL_STATUSCODES_H
165 
166 
167 
StatusCode(unsigned long code, bool checked=false)
Definition: StatusCode.h:48
GAUDI_API const IssueSeverity & severity() const
Severity.
Definition: StatusCode.cpp:27
void setCode(unsigned long value)
Set the status code by value.
Definition: StatusCode.h:85
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:79
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
bool m_checked
If the Status code has been checked.
Definition: StatusCode.h:139
SeverityPtr m_severity
Pointer to a IssueSeverity.
Definition: StatusCode.h:149
StatusCode(unsigned long code, const IssueSeverity &sev)
Definition: StatusCode.h:41
GAUDI_API ~StatusCode()
Destructor.
Definition: StatusCode.cpp:33
static GAUDI_API void enableChecking()
Definition: StatusCode.cpp:19
StatusCode()
Constructor.
Definition: StatusCode.h:39
std::ostream & operator<<(std::ostream &s, const StatusCode &sc)
Definition: StatusCode.h:154
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:72
friend bool operator<(const StatusCode &a, const StatusCode &b)
Comparison operator.
Definition: StatusCode.h:117
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
static bool s_checking
Global flag to control if StatusCode need to be checked.
Definition: StatusCode.h:151
unsigned long d_code
The status code.
Definition: StatusCode.h:138
bool isRecoverable() const
Definition: StatusCode.h:73
StatusCode(const StatusCode &rhs)
Definition: StatusCode.h:51
StatusCode & operator=(const StatusCode &rhs)
Definition: StatusCode.h:107
string s
Definition: gaudirun.py:210
static GAUDI_API void disableChecking()
Definition: StatusCode.cpp:23
void ignore() const
Definition: StatusCode.h:94
friend bool operator>(const StatusCode &a, const StatusCode &b)
Comparison operator.
Definition: StatusCode.h:122
boost::shared_ptr< IssueSeverity > SeverityPtr
Definition: StatusCode.h:147
#define GAUDI_API
Definition: Kernel.h:108
void setChecked() const
Ignore the checking code;.
Definition: StatusCode.h:91
StatusCode & operator=(unsigned long value)
Assignment operator.
Definition: StatusCode.h:103