Gaudi Framework, version v21r4

Home   Generated: 7 Sep 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/Kernel.h"
00008 #include "GaudiKernel/IssueSeverity.h"
00009 
00020 class IMessageSvc;
00021 class IStatusCodeSvc;
00022 
00023 class IgnoreError {};
00024 
00025 class StatusCode {
00026 public:
00027   enum {
00028     FAILURE = 0,
00029     SUCCESS = 1,
00030     RECOVERABLE = 2
00031   };
00032 
00034   StatusCode():
00035     d_code(SUCCESS), m_checked(false), m_severity(0) {}
00036   StatusCode( unsigned long code, const IssueSeverity& sev ):
00037     d_code(code),m_checked(false), m_severity(cloneSeverity(&sev)) {}
00038   StatusCode( unsigned long code, bool checked = false ):
00039     d_code(code),m_checked(checked), m_severity(0) {}
00040 
00041   StatusCode( const StatusCode& rhs ):
00042     d_code(rhs.d_code), m_checked(rhs.m_checked),
00043     m_severity(rhs.m_severity ? cloneSeverity(rhs.m_severity) : 0)
00044     { rhs.m_checked = true; }
00045 
00047   GAUDI_API ~StatusCode();
00048 
00052   bool isSuccess() const {
00053     m_checked = true;
00054     return (d_code == SUCCESS);
00055   }
00056 
00062   bool isFailure() const { return !isSuccess(); }
00063   bool isRecoverable() const {
00064     m_checked = true;
00065     return (d_code == RECOVERABLE);
00066   }
00067 
00069   unsigned long getCode() const{
00070     m_checked = true;
00071     return d_code;
00072   }
00073 
00075   void setCode(unsigned long value)  {
00076     m_checked = false;
00077     d_code = value;
00078   }
00079 
00081   void setChecked() const{
00082     m_checked = true;
00083   }
00084   void ignore() const { setChecked(); }
00085 
00087   operator unsigned long() const { return getCode(); }
00088 
00090   GAUDI_API const IssueSeverity& severity() const;
00091 
00093   StatusCode& operator=(unsigned long value) {
00094     setCode(value);
00095     return *this;
00096   }
00097   StatusCode& operator=(const StatusCode& rhs){
00098     if (this == &rhs) return *this; // Protection against self-assignment
00099     d_code = rhs.d_code;
00100     m_checked = rhs.m_checked;
00101     rhs.m_checked = true;
00102     if (m_severity) delete m_severity;
00103     m_severity = rhs.m_severity ? cloneSeverity(rhs.m_severity): 0;
00104     return *this;
00105   }
00106 
00108   friend bool operator< ( const StatusCode& a, const StatusCode& b ) {
00109     return a.d_code < b.d_code;
00110   }
00111 
00113   friend bool operator> ( const StatusCode& a, const StatusCode& b ) {
00114     return a.d_code > b.d_code;
00115   }
00116 
00117 #ifndef _WIN32
00118   operator IgnoreError() const {
00119     m_checked = true;
00120     return IgnoreError();
00121   }
00122 #endif
00123 
00124   static GAUDI_API void enableChecking();
00125   static GAUDI_API void disableChecking();
00126 
00127 protected:
00129   unsigned long   d_code;      
00130   mutable bool    m_checked;   
00131   IssueSeverity*  m_severity;  
00132 
00133   static bool     s_checking;  
00134 
00135   static GAUDI_API IssueSeverity* cloneSeverity(const IssueSeverity*);
00136 };
00137 
00138 inline std::ostream& operator<< ( std::ostream& s , const StatusCode& sc )
00139 {
00140   if ( sc.isSuccess() ) { return s << "SUCCESS" ; }
00141   else if ( sc.isRecoverable() ) { return s << "RECOVERABLE" ; }
00142   s << "FAILURE" ;
00143   if ( StatusCode::FAILURE != sc.getCode() )
00144     { s << "(" << sc.getCode() << ")" ;}
00145   return s ;
00146 }
00147 
00148 #endif  // GAUDIKERNEL_STATUSCODES_H
00149 
00150 
00151 

Generated at Mon Sep 7 18:05:41 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004