| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# StatusCode.h

Go to the documentation of this file.

    00001 // $Id: StatusCode.h,v 1.12 2008/10/28 17:21:58 marcocle Exp $
    00002 #ifndef GAUDIKERNEL_STATUSCODE_H
    00003 #define GAUDIKERNEL_STATUSCODE_H
    00004
    00005 #include <ostream>
    00006
    00007 #include "GaudiKernel/IssueSeverity.h"
    00008
    00019 class IMessageSvc;
    00020 class IStatusCodeSvc;
    00021
    00022 class IgnoreError {};
    00023
    00024 class StatusCode {
    00025 public:
    00026   enum {
    00027     FAILURE = 0,
    00028     SUCCESS = 1,
    00029     RECOVERABLE = 2
    00030   };
    00031
    00033   StatusCode();
    00034   StatusCode( unsigned long code, const IssueSeverity& );
    00035   StatusCode( unsigned long code, bool checked = false );
    00036
    00037   StatusCode( const StatusCode& sc );
    00038
    00040   ~StatusCode();
    00041
    00045   bool isSuccess() const;
    00046
    00052   bool isFailure() const;
    00053   bool isRecoverable() const;
    00054
    00056   unsigned long getCode() const;
    00057
    00059   void setCode( unsigned long );
    00060
    00062   void setChecked() const;
    00063   void ignore() const;
    00064
    00066   operator unsigned long() const;
    00067
    00069   const IssueSeverity& severity() const;
    00070
    00072   StatusCode& operator=(unsigned long value);
    00073   StatusCode& operator=(const StatusCode& rhs);
    00074
    00076   friend bool operator< ( const StatusCode& a, const StatusCode& b );
    00077
    00079   friend bool operator> ( const StatusCode& a, const StatusCode& b );
    00080
    00081 #ifndef _WIN32
    00082   operator IgnoreError() const {
    00083     m_checked = true;
    00084     return IgnoreError();
    00085   }
    00086 #endif
    00087
    00088   static void enableChecking();
    00089   static void disableChecking();
    00090
    00091 protected:
    00093   unsigned long   d_code;
    00094   mutable bool    m_checked;
    00095   IssueSeverity*  m_severity;
    00096
    00097   static bool     s_checking;
    00098
    00099   static IssueSeverity* cloneSeverity(const IssueSeverity*);
    00100 };
    00101
    00102 inline StatusCode::StatusCode():
    00103   d_code(SUCCESS), m_checked(false), m_severity(0) {}
    00104
    00105 inline StatusCode::StatusCode( unsigned long code, bool checked ) :
    00106   d_code(code),m_checked(checked), m_severity(0) {}
    00107
    00108 inline StatusCode::StatusCode( unsigned long code, const IssueSeverity& sev ) :
    00109   d_code(code),m_checked(false), m_severity(cloneSeverity(&sev)) {
    00110 }
    00111
    00112 inline StatusCode::StatusCode( const StatusCode &rhs ) {
    00113   d_code = rhs.d_code;
    00114   m_checked = rhs.m_checked;
    00115   rhs.m_checked = true;
    00116   m_severity = rhs.m_severity ? cloneSeverity(rhs.m_severity) : 0;
    00117 }
    00118
    00119 inline StatusCode& StatusCode::operator=(const StatusCode& rhs) {
    00120   if (this == &rhs) return *this; // Protection against self-assignment
    00121   d_code = rhs.d_code;
    00122   m_checked = rhs.m_checked;
    00123   rhs.m_checked = true;
    00124   if (m_severity) delete m_severity;
    00125   m_severity = rhs.m_severity ? cloneSeverity(rhs.m_severity): 0;
    00126   return *this;
    00127 }
    00128
    00129 inline bool StatusCode::isSuccess() const {
    00130   m_checked = true;
    00131   return (d_code == SUCCESS );
    00132 }
    00133
    00134 inline bool StatusCode::isFailure() const {
    00135   m_checked = true;
    00136   return (d_code != SUCCESS );
    00137 }
    00138
    00139 inline bool StatusCode::isRecoverable() const {
    00140   m_checked = true;
    00141   return (d_code == RECOVERABLE);
    00142 }
    00143
    00144 inline unsigned long StatusCode::getCode() const {
    00145   m_checked = true;
    00146   return d_code;
    00147 }
    00148
    00149 inline void StatusCode::setCode(unsigned long value) {
    00150   m_checked = false;
    00151   d_code = value;
    00152 }
    00153
    00154 inline void StatusCode::setChecked() const {
    00155   m_checked = true;
    00156 }
    00157
    00158 inline void StatusCode::ignore() const {
    00159   m_checked = true;
    00160 }
    00161
    00162 inline StatusCode::operator unsigned long() const  {
    00163   m_checked = true;
    00164   return d_code;
    00165 }
    00166
    00167 inline StatusCode& StatusCode::operator=(unsigned long value)   {
    00168   d_code = value;
    00169   m_checked = false;
    00170   return *this;
    00171 }
    00172
    00173 inline bool operator< ( const StatusCode& a, const StatusCode& b ) {
    00174   return a.d_code < b.d_code;
    00175 }
    00176
    00177 inline bool operator> ( const StatusCode& a, const StatusCode& b ) {
    00178   return a.d_code > b.d_code;
    00179 }
    00180
    00181 inline std::ostream& operator<< ( std::ostream& s , const StatusCode& sc )
    00182 {
    00183   if ( sc.isSuccess() ) { return s << "SUCCESS" ; }
    00184   else if ( sc.isRecoverable() ) { return s << "RECOVERABLE" ; }
    00185   s << "FAILURE" ;
    00186   if ( StatusCode::FAILURE != sc.getCode() )
    00187     { s << "(" << sc.getCode() << ")" ;}
    00188   return s ;
    00189 }
    00190
    00191 #endif  // GAUDIKERNEL_STATUSCODES_H
    00192
    00193
    00194