| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# 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/Kernel.h"
    00008 #include "GaudiKernel/IssueSeverity.h"
    00009 #include "boost/shared_ptr.hpp"
    00010
    00021 class IMessageSvc;
    00022 class IStatusCodeSvc;
    00023
    00024 class IgnoreError {};
    00025
    00026 class StatusCode {
    00027 public:
    00028   enum {
    00029     FAILURE = 0,
    00030     SUCCESS = 1,
    00031     RECOVERABLE = 2
    00032   };
    00033
    00035   StatusCode():
    00036     d_code(SUCCESS), m_checked(false), m_severity() {}
    00037   StatusCode( unsigned long code, const IssueSeverity& sev ):
    00038     d_code(code),m_checked(false), m_severity() {
    00039     try { // ensure that we do not throw even if the we cannot copy the severity
    00040       m_severity = SeverityPtr(new IssueSeverity(sev));
    00041     }
    00042     catch (...) {}
    00043   }
    00044   StatusCode( unsigned long code, bool checked = false ):
    00045     d_code(code),m_checked(checked), m_severity() {}
    00046
    00047   StatusCode( const StatusCode& rhs ):
    00048     d_code(rhs.d_code), m_checked(rhs.m_checked),
    00049     m_severity(rhs.m_severity)
    00050     { rhs.m_checked = true; }
    00051
    00053   GAUDI_API ~StatusCode();
    00054
    00058   bool isSuccess() const {
    00059     m_checked = true;
    00060     return (d_code == SUCCESS);
    00061   }
    00062
    00068   bool isFailure() const { return !isSuccess(); }
    00069   bool isRecoverable() const {
    00070     m_checked = true;
    00071     return (d_code == RECOVERABLE);
    00072   }
    00073
    00075   unsigned long getCode() const{
    00076     m_checked = true;
    00077     return d_code;
    00078   }
    00079
    00081   void setCode(unsigned long value)  {
    00082     m_checked = false;
    00083     d_code = value;
    00084   }
    00085
    00087   void setChecked() const{
    00088     m_checked = true;
    00089   }
    00090   void ignore() const { setChecked(); }
    00091
    00093   operator unsigned long() const { return getCode(); }
    00094
    00096   GAUDI_API const IssueSeverity& severity() const;
    00097
    00099   StatusCode& operator=(unsigned long value) {
    00100     setCode(value);
    00101     return *this;
    00102   }
    00103   StatusCode& operator=(const StatusCode& rhs){
    00104     if (this == &rhs) return *this; // Protection against self-assignment
    00105     d_code = rhs.d_code;
    00106     m_checked = rhs.m_checked;
    00107     rhs.m_checked = true;
    00108     m_severity = rhs.m_severity;
    00109     return *this;
    00110   }
    00111
    00113   friend bool operator< ( const StatusCode& a, const StatusCode& b ) {
    00114     return a.d_code < b.d_code;
    00115   }
    00116
    00118   friend bool operator> ( const StatusCode& a, const StatusCode& b ) {
    00119     return a.d_code > b.d_code;
    00120   }
    00121
    00122 #ifndef _WIN32
    00123   operator IgnoreError() const {
    00124     m_checked = true;
    00125     return IgnoreError();
    00126   }
    00127 #endif
    00128
    00129   static GAUDI_API void enableChecking();
    00130   static GAUDI_API void disableChecking();
    00131
    00132 protected:
    00134   unsigned long   d_code;
    00135   mutable bool    m_checked;
    00136   typedef boost::shared_ptr<IssueSeverity> SeverityPtr;
    00137   SeverityPtr     m_severity;
    00138
    00139   static bool     s_checking;
    00140 };
    00141
    00142 inline std::ostream& operator<< ( std::ostream& s , const StatusCode& sc )
    00143 {
    00144   if ( sc.isSuccess() ) { return s << "SUCCESS" ; }
    00145   else if ( sc.isRecoverable() ) { return s << "RECOVERABLE" ; }
    00146   s << "FAILURE" ;
    00147   if ( StatusCode::FAILURE != sc.getCode() )
    00148     { s << "(" << sc.getCode() << ")" ;}
    00149   return s ;
    00150 }
    00151
    00152 #endif  // GAUDIKERNEL_STATUSCODES_H
    00153
    00154
    00155