00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __UT_ErrorManager_h__
00024 #define __UT_ErrorManager_h__
00025
00026 #include "UT_API.h"
00027 #include "UT_Error.h"
00028 #include "UT_PtrArray.h"
00029 #include <fstream.h>
00030
00031 typedef UT_PtrArray<UT_Error *> UT_ErrorList;
00032
00033 class UT_API UT_ErrorManager
00034 {
00035 public:
00036 UT_ErrorManager();
00037 ~UT_ErrorManager();
00038
00039 UT_ErrorSeverity addMessage (const char *type, int code, const char *msg=0);
00040 UT_ErrorSeverity addPrompt (const char *type, int code, const char *msg=0);
00041 UT_ErrorSeverity addWarning (const char *type, int code, const char *msg=0);
00042 UT_ErrorSeverity addError (const char *type, int code, const char *msg=0);
00043 UT_ErrorSeverity addFatal (const char *type, int code, const char *msg=0);
00044 UT_ErrorSeverity systemError(const char *msg=0);
00045 UT_ErrorSeverity commonWarning(UT_CommonErrorCode what, const char *msg=0);
00046 UT_ErrorSeverity commonError(UT_CommonErrorCode what, const char *msg=0);
00047
00048 void clearAndDestroyErrors();
00049
00050 int getNumErrors() const { return myList.entries(); }
00051
00052 UT_ErrorSeverity append(UT_Error *error);
00053
00054 int stealErrors(UT_ErrorManager &victim,
00055 int rangestart = 0, int rangeend = -1,
00056 UT_ErrorSeverity severity = UT_ERROR_NONE,
00057 bool borrow_only = false);
00058
00059 int removeError(int index);
00060 int findError(const char *type, int code) const;
00061
00062
00063
00064 int getErrorMessages(UT_String &messages,
00065 UT_ErrorSeverity severity = UT_ERROR_NONE,
00066 int headerflag=1);
00067
00068
00069
00070 UT_ErrorSeverity getSeverity()
00071 {
00072 if( getNeedScan() )
00073 computeSeverity();
00074 return mySeverity;
00075 }
00076
00077
00078 UT_ErrorSeverity getErrorState() { return getSeverity(); }
00079
00080 void pruneDuplicates();
00081
00082 protected:
00083 enum { FLAG_ERRORS_READ = 0x01, FLAG_SCAN_NEEDED = 0x02 };
00084
00085 void setReadFlag(int state);
00086 int getReadFlag() const
00087 {
00088 return (myFlags & FLAG_ERRORS_READ) != 0;
00089 }
00090
00091 void setNeedScan(int state);
00092 int getNeedScan() const
00093 {
00094 return (myFlags & FLAG_SCAN_NEEDED) != 0;
00095 }
00096
00097 private:
00098 void computeSeverity();
00099
00100 UT_ErrorList myList;
00101 UT_ErrorSeverity mySeverity;
00102 char myFlags;
00103 };
00104
00105 UT_API UT_ErrorManager *UTgetErrorManager();
00106 UT_API UT_ErrorManager *UTgetErrorManager(int thraed);
00107 UT_API void UTpushErrorManager();
00108 UT_API void UTpushErrorManager(int thread);
00109 UT_API void UTpopErrorManager();
00110 UT_API void UTpopErrorManager(int thread);
00111
00112 UT_API UT_ErrorSeverity UTaddWarning(const char *type, int code,
00113 const char *msg=0);
00114 UT_API UT_ErrorSeverity UTaddPrompt(const char *type, int code,
00115 const char *msg=0);
00116 UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code,
00117 const char *msg=0);
00118 UT_API UT_ErrorSeverity UTaddError (const char *type, int code,
00119 const char *msg=0);
00120 UT_API UT_ErrorSeverity UTaddFatal (const char *type, int code,
00121 const char *msg=0);
00122 UT_API UT_ErrorSeverity UTaddSystemError(const char *msg=0);
00123 UT_API UT_ErrorSeverity UTaddCommonWarning(UT_CommonErrorCode what,
00124 const char *msg=0);
00125 UT_API UT_ErrorSeverity UTaddCommonError(UT_CommonErrorCode what,
00126 const char *msg=0);
00127 UT_API UT_ErrorSeverity UTaddError(UT_Error *error);
00128
00129 UT_API int UTfindError(const char *type, int code);
00130
00131 UT_API UT_ErrorSeverity UTgetErrorSeverity();
00132
00133 UT_API int UTcheckOutStream(ostream &os, const char *m, const char *path=0);
00134 #endif