HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  UT_ERROR_MINIMUM_CPU, // minimum cpu requirement failure
70 };
71 
72 #define UT_CE_EARLY_INPUT_END UT_ERROR_EOF
73 #define UT_CE_PARSE_ERROR UT_ERROR_PARSING
74 #define UT_CE_FILE_ERROR UT_ERROR_FILE_FORMAT
75 
77 {
78 public:
79 
80  // NOTE: A copy of string is stored. String is just an optional
81  // message associated with the error (eg a file name).
82  // "type" is usually a library prefix or it can be either "System"
83  // or "Common".
84  UT_Error(const char *error_type,
85  const int error_code,
86  const char *error_string = 0,
88  const UT_SourceLocation *location = NULL);
89  virtual ~UT_Error();
90 
91  virtual int64 getMemoryUsage(bool inclusive) const
92  {
93  int64 mem = inclusive ? sizeof(*this) : 0;
94  mem += myErrorType.getMemoryUsage(false);
95  mem += myErrorString.getMemoryUsage(false);
96  mem += myLocation.getMemoryUsage(false);
97  return mem;
98  }
99 
100  // If you're stringing several errors together, you should set
101  // last to the severity of the last error for which you got the
102  // error message, so that if the severity hasn't changed, we won't
103  // print the "Error/Warning/Message" headers before the message.
104  //
105  // if the use headers flag is off, then the headers (nor spaces in
106  // their place) will be prepended to the message
107  void getErrorMessage(UT_String &error_str,
108  UT_ErrorSeverity last_severity = UT_ERROR_NONE,
109  bool useheaders = true) const;
110  void getErrorFormattedString(
111  UT_WorkBuffer &error_str) const;
112 
113  const UT_String &getErrorType() const { return myErrorType; }
114  UT_ErrorSeverity getSeverity() const { return mySeverity; }
115  int getErrorCode() const { return myErrorCode; }
116  const UT_String &getString() const { return myErrorString; }
117  const UT_SourceLocation &getLocation() const { return myLocation; }
118 
119  void setErrorType(const char *type);
120  void setSeverity(UT_ErrorSeverity);
121  void setErrorString(const char *string);
122  void setErrorCode(int code);
123  void setErrorLocation(const UT_SourceLocation &loc);
124 
125  // getFileString will open the file specified in the filename parameter
126  // and search for the entry with the given error_code. The entry is
127  // placed in the buffer.
128  //
129  // The format of the file is:
130  // # comments
131  // <error_code><single character (non digit)><error message>
132  //
133  // in other words, an error code (string of digits)
134  // a character (typically a tab)
135  // and a newline terminated string
136  // eg:
137  // 145 Generic Error Message.
138  //
139  // Note: You might have a %s in the message somewhere. And also,
140  // only the first nondigit is ignored. All other chars until
141  // the newline, are significant.
142  // Also, all lines with the same code are appended to each other.
143  //
144  // If the error is not found, 0 is returned.
145  //
146  // Note: These files are cached after reading, you have to restart
147  // Houdini to get them to clear out (or write a clearErrorCache method)
148  static bool getErrorFormat(UT_StringHolder &format,
149  const char *error_file,
150  int error_code);
151  static bool getFileString(UT_String &error_str,
152  const char *error_file,
153  int error_code,
155  UT_ErrorSeverity last_severity,
156  bool useheaders);
157 
158 private:
159  UT_String myErrorType;
160  UT_String myErrorString;
161  UT_ErrorSeverity mySeverity;
162  int myErrorCode;
163  UT_SourceLocation myLocation;
164 };
165 
166 #endif
UT_ErrorSeverity
Definition: UT_Error.h:25
#define UT_API
Definition: UT_API.h:13
const UT_SourceLocation & getLocation() const
Definition: UT_Error.h:117
long long int64
Definition: SYS_Types.h:107
virtual int64 getMemoryUsage(bool inclusive) const
Definition: UT_Error.h:91
int getErrorCode() const
Definition: UT_Error.h:115
UT_ErrorSeverity getSeverity() const
Definition: UT_Error.h:114
GLint location
Definition: glcorearb.h:804
GLenum GLenum severity
Definition: glcorearb.h:2538
const UT_String & getErrorType() const
Definition: UT_Error.h:113
const UT_String & getString() const
Definition: UT_Error.h:116
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