00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * ramin 00008 * Side Effects 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_Error.h (Utility Library, C++) 00015 * 00016 * COMMENTS: 00017 * This class is used to store an error or warning, it is 00018 * used in conjunction with a global UT_ErrorManager. 00019 * 00020 */ 00021 00022 #ifndef __UT_Error__ 00023 #define __UT_Error__ 00024 00025 #include "UT_API.h" 00026 #include "UT_String.h" 00027 class UT_Color; 00028 00029 enum UT_ErrorSeverity 00030 { 00031 UT_ERROR_NONE = 0, 00032 UT_ERROR_MESSAGE, // just for communication (eg "ignoring point normals") 00033 UT_ERROR_PROMPT, // something that should catch the user's attention 00034 UT_ERROR_WARNING, // something bad happened but continuing is an option 00035 UT_ERROR_ABORT, // bad error which meant discontinuing current action 00036 UT_ERROR_FATAL, // something bad from which we can't recover 00037 UT_NUM_ERROR_SEVERITIES 00038 }; 00039 00040 // NOTE: 00041 // UT_ERROR_JUST_STRING is meant for convenience for times when you need 00042 // to list things, or to use more than one string in an error. eg: 00043 // Error: Missing token "{" 00044 // ref: Animated Parameter Load 00045 00046 enum UT_CommonErrorCode 00047 { 00048 UT_ERROR_FILE_NOT_FOUND = 0, 00049 UT_ERROR_EOF, 00050 UT_ERROR_PARSING, 00051 UT_ERROR_FILE_FORMAT, 00052 UT_ERROR_OUTSTREAM, // output to stream failed in %s. 00053 UT_ERROR_INSTREAM, // input from stream failed in %s. 00054 UT_ERROR_EARLY_STREAM_END, // unexpected end of input stream is %s. 00055 UT_ERROR_SKIP_PACKET_CLASS, // ignoring unrecog data packet (class) in %s. 00056 UT_ERROR_SKIP_PACKET_ID, // ignoring unrecog data packet (id) in %s. 00057 UT_ERROR_SKIP_TOKEN, // ignoring unrecog token "%s". 00058 UT_ERROR_BAD_TOKEN, // unrecog token "%s". Unable to continue 00059 UT_ERROR_MISSING_TOKEN, // missing token "%s". 00060 UT_ERROR_BAD_INT, // Invalid integer specification (%s) 00061 UT_ERROR_BAD_FLOAT, // Invalid float specification (%s) 00062 UT_ERROR_JUST_STRING, // %s -- see note above 00063 UT_ERROR_BAD_EXTENSION, // Unknown file extension (%s) 00064 UT_ERROR_BAD_CPIO_HEADER, // Bad header in CPIO packet 00065 UT_ERROR_BAD_CPIO_CONTENTS, // Bad contents in CPIO packet 00066 UT_ERROR_CANT_MKDIR_FILE_EXISTS, // Can't make directory, file exists 00067 UT_ERROR_FILE_NOT_WRITEABLE, // Unable to write to file (%s) 00068 UT_ERROR_ABORT_BY_USER // Action aborted by user: %s 00069 }; 00070 00071 00072 #define UT_CE_EARLY_INPUT_END UT_ERROR_EOF 00073 #define UT_CE_PARSE_ERROR UT_ERROR_PARSING 00074 #define UT_CE_FILE_ERROR UT_ERROR_FILE_FORMAT 00075 00076 00077 class UT_API UT_Error 00078 { 00079 public: 00080 00081 // NOTE: A copy of string is stored. String is just an optional 00082 // message associated with the error (eg a file name). 00083 // "type" is usually a library prefix or it can be either "System" 00084 // or "Common". 00085 // 00086 UT_Error(const char *type, const int errorcode, const char *string = 0, 00087 const UT_ErrorSeverity = UT_ERROR_ABORT); 00088 00089 virtual ~UT_Error(); 00090 00091 // If you're stringing several errors together, you should set 00092 // last to the severity of the last error for which you got the 00093 // error message, so that if the severity hasn't changed, we won't 00094 // print the "Error/Warning/Message" headers before the message. 00095 // 00096 // if the use headers flag is off, then the headers (nor spaces in 00097 // their place) will be prepended to the message 00098 virtual void getErrorMessage(UT_String &error, 00099 const UT_ErrorSeverity last = UT_ERROR_NONE, 00100 int useheaders = 1); 00101 00102 const UT_String &getErrorType() const { return myErrorType; } 00103 UT_ErrorSeverity getSeverity() const { return mySeverity; } 00104 int getErrorCode() const { return myErrorCode; } 00105 const UT_String &getString() const { return myErrorString; } 00106 00107 void setErrorType(const char *type); 00108 void setErrorString(const char *string); 00109 void setErrorCode(int code); 00110 00111 // 00112 // getFileString will open the file specified in the filename parameter 00113 // and search for the entry with the given errorcode. The entry is 00114 // placed in the buffer. 00115 // 00116 // The format of the file is: 00117 // # comments 00118 // <errorcode><single character (non digit)><error message> 00119 // 00120 // in other words, an error code (string of digits) 00121 // a character (typically a tab) 00122 // and a newline terminated string 00123 // eg: 00124 // 145 Generic Error Message. 00125 // 00126 // Note: You might have a %s in the message somewhere. And also, 00127 // only the first nondigit is ignored. All other chars until 00128 // the newline, are significant. 00129 // Also, all lines with the same code are appended to each other. 00130 // 00131 // If the error is not found, 0 is returned. 00132 // 00133 // Note: These files are cached after reading, you have to restart 00134 // Houdini to get them to clear out (or write a clearErrorCache method) 00135 // 00136 static int getFileString(UT_String &buffer, const char *errorfile, 00137 const int errorcode, UT_ErrorSeverity severity, 00138 const UT_ErrorSeverity last, int useheaders); 00139 void setSeverity(UT_ErrorSeverity); 00140 00141 protected: 00142 00143 // Since most errors follow the same pattern, they can use this 00144 // method to generate an error string. 00145 // errorfile may be an absolute or relative pathname. 00146 // (relative to /ufs/prisms/support/error) 00147 // The error will be sprintf(buffer, errorformat, str); 00148 // errorformat is taken out of error file, and str is the 00149 // string in the constructor. "last" contains the severity of 00150 // the last error on which this method was called if we're 00151 // stringing a bunch of errors together. If this error has 00152 // the same severity as the last one, then we don't prepend 00153 // the message with the Error/Warning/Message header. 00154 // Furthermore, if the useheaders flag is zero, then the 00155 // header (and/or filler spaces) are omitted altogether. 00156 // 00157 void stdGetErrorMessage(UT_String &errorstring, 00158 const char *errorfile, 00159 const UT_ErrorSeverity last, 00160 int useheaders) const; 00161 00162 private: 00163 UT_String myErrorType; 00164 UT_String myErrorString; 00165 UT_ErrorSeverity mySeverity; 00166 int myErrorCode; 00167 }; 00168 00169 #endif
1.5.9