opennurbs_error.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_ERROR_INC_)
18 #define OPENNURBS_ERROR_INC_
19 
20 /*
21 // Macros used to log errors and warnings. The ON_Warning() and ON_Error()
22 // functions are defined in opennurbs_error.cpp.
23 */
24 #define ON_ERROR(msg) ON_ErrorEx(__FILE__,__LINE__,OPENNURBS__FUNCTION__,msg)
25 #define ON_WARNING(msg) ON_WarningEx(__FILE__,__LINE__,OPENNURBS__FUNCTION__,msg)
26 #define ON_ASSERT_OR_RETURN(cond,returncode) do{if (!(cond)) {ON_ErrorEx(__FILE__,__LINE__,OPENNURBS__FUNCTION__, #cond " is false");return(returncode);}}while(0)
27 #define ON_ASSERT_OR_RETURNVOID(cond) do{if (!(cond)) {ON_ErrorEx(__FILE__,__LINE__,OPENNURBS__FUNCTION__, #cond " is false");return;}}while(0)
28 
29 // Do not use ON_ASSERT. If a condition can be checked by ON_ASSERT, then the
30 // code must be written detect and respond to that condition. This define will
31 // be deleted ASAP. It is being used to detect situations where a crash will
32 // occur and then letting the crash occur.
33 #define ON_ASSERT(cond) ON_REMOVE_ASAP_AssertEx(cond,__FILE__,__LINE__,OPENNURBS__FUNCTION__, #cond " is false")
34 
35 
36 ON_BEGIN_EXTERNC
37 
38 /*
39 // All error/warning messages are sent to ON_ErrorMessage(). Replace the
40 // default handler (defined in opennurbs_error_message.cpp) with something
41 // that is appropriate for debugging your application.
42 */
43 ON_DECL
44 void ON_ErrorMessage(
45  int, /* 0 = warning message, 1 = serious error message, 2 = assert failure */
46  const char*
47  );
48 
49 /*
50 Returns:
51  Number of opennurbs errors since program started.
52 */
53 ON_DECL
54 int ON_GetErrorCount(void);
55 
56 /*
57 Returns:
58  Number of opennurbs warnings since program started.
59 */
60 ON_DECL
61 int ON_GetWarningCount(void);
62 
63 /*
64 Returns:
65  Number of math library or floating point errors that have
66  been handled since program started.
67 */
68 ON_DECL
69 int ON_GetMathErrorCount(void);
70 
71 
72 ON_DECL
73 int ON_GetDebugErrorMessage(void);
74 
75 ON_DECL
76 void ON_EnableDebugErrorMessage( int bEnableDebugErrorMessage );
77 
78 ON_DECL
79 void ON_VARGS_FUNC_CDECL ON_Error(
80  const char* file_name, /* __FILE__ will do fine */
81  int line_number, /* __LINE__ will do fine */
82  const char* format, /* format string */
83  ... /* format ags */
84  );
85 
86 ON_DECL
87 void ON_VARGS_FUNC_CDECL ON_ErrorEx(
88  const char* file_name, /* __FILE__ will do fine */
89  int line_number, /* __LINE__ will do fine */
90  const char* function_name, /* OPENNURBS__FUNCTION__ will do fine */
91  const char* format, /* format string */
92  ... /* format ags */
93  );
94 
95 ON_DECL
96 void ON_VARGS_FUNC_CDECL ON_Warning(
97  const char* file_name, /* __FILE__ will do fine */
98  int line_number, /* __LINE__ will do fine */
99  const char* format, /* format string */
100  ... /* format ags */
101  );
102 
103 ON_DECL
104 void ON_VARGS_FUNC_CDECL ON_WarningEx(
105  const char* file_name, /* __FILE__ will do fine */
106  int line_number, /* __LINE__ will do fine */
107  const char* function_name, /*OPENNURBS__FUNCTION__ will do fine */
108  const char* format, /* format string */
109  ... /* format ags */
110  );
111 
112 // Ideally - these "assert" functions will be deleted when the SDK can be changed.
113 ON_DECL
114 void ON_VARGS_FUNC_CDECL ON_REMOVE_ASAP_AssertEx(
115  int, // if false, error is flagged
116  const char* file_name, /* __FILE__ will do fine */
117  int line_number, /* __LINE__ will do fine */
118  const char* function_name, /* OPENNURBS__FUNCTION__ will do fine */
119  const char* format, /* format string */
120  ... /* format ags */
121  );
122 
123 ON_DECL
124 void ON_MathError(
125  const char*, /* sModuleName */
126  const char*, /* sErrorType */
127  const char* /* sFunctionName */
128  );
129 
130 ON_END_EXTERNC
131 
132 #endif