HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Error.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Error.h (Utility Library, C++)
7  *
8  * COMMENTS:
9  * This class is used to store an error or warning, it is
10  * used in conjunction with a global UT_ErrorManager.
11  *
12  */
13 
14 #ifndef __UT_Error__
15 #define __UT_Error__
16 
17 #include "UT_API.h"
18 #include "UT_String.h"
19 #include "UT_SourceLocation.h"
20 
21 class UT_Color;
22 class UT_StringHolder;
23 class UT_WorkBuffer;
24 
26 {
28  UT_ERROR_MESSAGE, // just for communication (eg "ignoring point normals")
29  UT_ERROR_PROMPT, // something that should catch the user's attention
30  UT_ERROR_WARNING, // something bad happened but continuing is an option
31  UT_ERROR_ABORT, // bad error which meant discontinuing current action
32  UT_ERROR_FATAL, // something bad from which we can't recover
34 };
35 
36 // NOTE:
37 // UT_ERROR_JUST_STRING is meant for convenience for times when you need
38 // to list things, or to use more than one string in an error. eg:
39 // Error: Missing token "{"
40 // ref: Animated Parameter Load
41 
43 {
48  UT_ERROR_OUTSTREAM, // output to stream failed in %s.
49  UT_ERROR_INSTREAM, // input from stream failed in %s.
50  UT_ERROR_EARLY_STREAM_END, // unexpected end of input stream is %s.
51  UT_ERROR_SKIP_PACKET_CLASS, // ignoring unrecog data packet (class) in %s.
52  UT_ERROR_SKIP_PACKET_ID, // ignoring unrecog data packet (id) in %s.
53  UT_ERROR_SKIP_TOKEN, // ignoring unrecog token "%s".
54  UT_ERROR_BAD_TOKEN, // unrecog token "%s". Unable to continue
55  UT_ERROR_MISSING_TOKEN, // missing token "%s".
56  UT_ERROR_BAD_INT, // Invalid integer specification (%s)
57  UT_ERROR_BAD_FLOAT, // Invalid float specification (%s)
58  UT_ERROR_JUST_STRING, // %s -- see note above
59  UT_ERROR_BAD_EXTENSION, // Unknown file extension (%s)
60  UT_ERROR_BAD_CPIO_HEADER, // Bad header in CPIO packet
61  UT_ERROR_BAD_CPIO_CONTENTS, // Bad contents in CPIO packet
62  UT_ERROR_CANT_MKDIR_FILE_EXISTS, // Can't make directory, file exists
63  UT_ERROR_FILE_NOT_WRITEABLE, // Unable to write to file (%s)
64  UT_ERROR_ABORT_BY_USER, // Action aborted by user: %s
65  UT_ERROR_LOW_VIDEO_RAM, // Houdini is running low on graphics VRAM
66  UT_ERROR_DEADLOCK, // Deadlock
67  UT_ERROR_TOO_MANY, // (Too many errors detected)
68  UT_ERROR_HOTKEY_REPORT // Hotkey pressed; echo command.
69 };
70 
71 #define UT_CE_EARLY_INPUT_END UT_ERROR_EOF
72 #define UT_CE_PARSE_ERROR UT_ERROR_PARSING
73 #define UT_CE_FILE_ERROR UT_ERROR_FILE_FORMAT
74 
76 {
77 public:
78 
79  // NOTE: A copy of string is stored. String is just an optional
80  // message associated with the error (eg a file name).
81  // "type" is usually a library prefix or it can be either "System"
82  // or "Common".
83  UT_Error(const char *error_type,
84  const int error_code,
85  const char *error_string = 0,
87  const UT_SourceLocation *location = NULL);
88  virtual ~UT_Error();
89 
90  virtual int64 getMemoryUsage(bool inclusive) const
91  {
92  int64 mem = inclusive ? sizeof(*this) : 0;
93  mem += myErrorType.getMemoryUsage(false);
94  mem += myErrorString.getMemoryUsage(false);
95  mem += myLocation.getMemoryUsage(false);
96  return mem;
97  }
98 
99  // If you're stringing several errors together, you should set
100  // last to the severity of the last error for which you got the
101  // error message, so that if the severity hasn't changed, we won't
102  // print the "Error/Warning/Message" headers before the message.
103  //
104  // if the use headers flag is off, then the headers (nor spaces in
105  // their place) will be prepended to the message
106  void getErrorMessage(UT_String &error_str,
107  UT_ErrorSeverity last_severity = UT_ERROR_NONE,
108  int useheaders = 1) const;
109  void getErrorFormattedString(
110  UT_WorkBuffer &error_str) const;
111 
112  const UT_String &getErrorType() const { return myErrorType; }
113  UT_ErrorSeverity getSeverity() const { return mySeverity; }
114  int getErrorCode() const { return myErrorCode; }
115  const UT_String &getString() const { return myErrorString; }
116  const UT_SourceLocation &getLocation() const { return myLocation; }
117 
118  void setErrorType(const char *type);
119  void setSeverity(UT_ErrorSeverity);
120  void setErrorString(const char *string);
121  void setErrorCode(int code);
122  void setErrorLocation(const UT_SourceLocation &loc);
123 
124  // getFileString will open the file specified in the filename parameter
125  // and search for the entry with the given error_code. The entry is
126  // placed in the buffer.
127  //
128  // The format of the file is:
129  // # comments
130  // <error_code><single character (non digit)><error message>
131  //
132  // in other words, an error code (string of digits)
133  // a character (typically a tab)
134  // and a newline terminated string
135  // eg:
136  // 145 Generic Error Message.
137  //
138  // Note: You might have a %s in the message somewhere. And also,
139  // only the first nondigit is ignored. All other chars until
140  // the newline, are significant.
141  // Also, all lines with the same code are appended to each other.
142  //
143  // If the error is not found, 0 is returned.
144  //
145  // Note: These files are cached after reading, you have to restart
146  // Houdini to get them to clear out (or write a clearErrorCache method)
147  static bool getErrorFormat(UT_StringHolder &format,
148  const char *error_file,
149  int error_code);
150  static bool getFileString(UT_String &error_str,
151  const char *error_file,
152  int error_code,
154  UT_ErrorSeverity last_severity,
155  int useheaders);
156 
157 private:
158  UT_String myErrorType;
159  UT_String myErrorString;
160  UT_ErrorSeverity mySeverity;
161  int myErrorCode;
162  UT_SourceLocation myLocation;
163 };
164 
165 #endif
UT_ErrorSeverity
Definition: UT_Error.h:25
#define UT_API
Definition: UT_API.h:12
const UT_SourceLocation & getLocation() const
Definition: UT_Error.h:116
long long int64
Definition: SYS_Types.h:106
virtual int64 getMemoryUsage(bool inclusive) const
Definition: UT_Error.h:90
int getErrorCode() const
Definition: UT_Error.h:114
UT_ErrorSeverity getSeverity() const
Definition: UT_Error.h:113
GLint location
Definition: glcorearb.h:804
GLenum GLenum severity
Definition: glcorearb.h:2538
const UT_String & getErrorType() const
Definition: UT_Error.h:112
const UT_String & getString() const
Definition: UT_Error.h:115
UT_CommonErrorCode
Definition: UT_Error.h:42
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107