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