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 UT_ERROR_LOW_VIDEO_RAM, // Houdini is running low on graphics VRAM 00070 UT_ERROR_DEADLOCK // Deadlock 00071 }; 00072 00073 00074 #define UT_CE_EARLY_INPUT_END UT_ERROR_EOF 00075 #define UT_CE_PARSE_ERROR UT_ERROR_PARSING 00076 #define UT_CE_FILE_ERROR UT_ERROR_FILE_FORMAT 00077 00078 00079 class UT_API UT_Error 00080 { 00081 public: 00082 00083 // NOTE: A copy of string is stored. String is just an optional 00084 // message associated with the error (eg a file name). 00085 // "type" is usually a library prefix or it can be either "System" 00086 // or "Common". 00087 // 00088 UT_Error(const char *type, const int errorcode, const char *string = 0, 00089 const UT_ErrorSeverity = UT_ERROR_ABORT); 00090 00091 virtual ~UT_Error(); 00092 00093 // If you're stringing several errors together, you should set 00094 // last to the severity of the last error for which you got the 00095 // error message, so that if the severity hasn't changed, we won't 00096 // print the "Error/Warning/Message" headers before the message. 00097 // 00098 // if the use headers flag is off, then the headers (nor spaces in 00099 // their place) will be prepended to the message 00100 virtual void getErrorMessage(UT_String &error, 00101 const UT_ErrorSeverity last = UT_ERROR_NONE, 00102 int useheaders = 1); 00103 00104 const UT_String &getErrorType() const { return myErrorType; } 00105 UT_ErrorSeverity getSeverity() const { return mySeverity; } 00106 int getErrorCode() const { return myErrorCode; } 00107 const UT_String &getString() const { return myErrorString; } 00108 00109 void setErrorType(const char *type); 00110 void setErrorString(const char *string); 00111 void setErrorCode(int code); 00112 00113 // 00114 // getFileString will open the file specified in the filename parameter 00115 // and search for the entry with the given errorcode. The entry is 00116 // placed in the buffer. 00117 // 00118 // The format of the file is: 00119 // # comments 00120 // <errorcode><single character (non digit)><error message> 00121 // 00122 // in other words, an error code (string of digits) 00123 // a character (typically a tab) 00124 // and a newline terminated string 00125 // eg: 00126 // 145 Generic Error Message. 00127 // 00128 // Note: You might have a %s in the message somewhere. And also, 00129 // only the first nondigit is ignored. All other chars until 00130 // the newline, are significant. 00131 // Also, all lines with the same code are appended to each other. 00132 // 00133 // If the error is not found, 0 is returned. 00134 // 00135 // Note: These files are cached after reading, you have to restart 00136 // Houdini to get them to clear out (or write a clearErrorCache method) 00137 // 00138 static int getFileString(UT_String &buffer, const char *errorfile, 00139 const int errorcode, UT_ErrorSeverity severity, 00140 const UT_ErrorSeverity last, int useheaders); 00141 void setSeverity(UT_ErrorSeverity); 00142 00143 protected: 00144 00145 // Since most errors follow the same pattern, they can use this 00146 // method to generate an error string. 00147 // errorfile may be an absolute or relative pathname. 00148 // (relative to /ufs/prisms/support/error) 00149 // The error will be sprintf(buffer, errorformat, str); 00150 // errorformat is taken out of error file, and str is the 00151 // string in the constructor. "last" contains the severity of 00152 // the last error on which this method was called if we're 00153 // stringing a bunch of errors together. If this error has 00154 // the same severity as the last one, then we don't prepend 00155 // the message with the Error/Warning/Message header. 00156 // Furthermore, if the useheaders flag is zero, then the 00157 // header (and/or filler spaces) are omitted altogether. 00158 // 00159 void stdGetErrorMessage(UT_String &errorstring, 00160 const char *errorfile, 00161 const UT_ErrorSeverity last, 00162 int useheaders) const; 00163 00164 private: 00165 UT_String myErrorType; 00166 UT_String myErrorString; 00167 UT_ErrorSeverity mySeverity; 00168 int myErrorCode; 00169 }; 00170 00171 #endif
1.5.9