IUF-SDK-3
Interventional Ultrasound Library
iufError.h
Go to the documentation of this file.
1 
7 #ifndef _IUFERROR_H
8 #define _IUFERROR_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <iuf.h>
15 #include <stdio.h> // fprintf()
16 #include <stdlib.h> // exit()
17 
18 
19 #ifdef __cplusplus
20 }
21 #endif
22 
27 (
28  void
29 );
30 
34 int iufErrorPrint
35 (
36 );
37 
41 char * iufErrorString
42 (
43 );
44 
48 int iufErrorPush
49 (
50  const char *pFileName,
51  const char *pFunctionName,
52  int lineNumber,
53  hid_t maj,
54  hid_t min,
55  char *msg
56 );
57 
58 
63 (
64  const char *pFileName,
65  const char *pFunctionName,
66  int lineNumber,
67  hid_t maj,
68  hid_t min,
69  char *msgFormat,
70  ...
71 );
72 
73 
78 (
79  IUF_BOOL enable
80 );
81 
82 
86 int iufErrorLog
87 (
88  IUF_BOOL enable
89 );
90 
91 
96 (
97  void
98 );
99 
100 
105 (
106  FILE *stream
107 );
108 
113 (
114  const char * pFileName
115 );
116 
121 (
122 );
123 
128 (
129  IUF_BOOL enable
130 );
131 
136 (
137  void
138 );
139 
140 
141 extern hid_t IUF_ERR_MAJ_GENERAL;
142 extern hid_t IUF_ERR_MAJ_MEMORY;
143 extern hid_t IUF_ERR_MAJ_VALUE;
144 extern hid_t IUF_ERR_MAJ_ERROR;
145 extern hid_t IUF_ERR_MAJ_HDF5;
146 
147 extern hid_t IUF_ERR_MIN_ARG_VALUE;
148 extern hid_t IUF_ERR_MIN_ARG_FILENAME;
149 extern hid_t IUF_ERR_MIN_ALLOC;
150 extern hid_t IUF_ERR_MIN_MEMCOPY;
151 extern hid_t IUF_ERR_MIN_FORMAT;
152 extern hid_t IUF_ERR_MIN_ARG_NULL_VALUE;
153 extern hid_t IUF_ERR_MIN_ARG_DUPLICATE_KEY;
154 extern hid_t IUF_ERR_MIN_ARG_INVALID_KEY;
155 extern hid_t IUF_ERR_MIN_HDF5;
156 extern hid_t IUF_ERR_MIN_ASSERT_FAILED;
157 
158 
159 
162 #define IUF_ERROR_PUSH(maj,min,msg) iufErrorPush(__FILE__, __func__, __LINE__, maj, min, msg)
163 
166 #define IUF_ERROR_PRINT(maj,min,msg) iufErrorPush(__FILE__, __func__, __LINE__, maj, min, msg);\
167  iufErrorPrint();
168 
171 #define IUF_ERROR_FMT_PUSH(maj,min,fmt,...) iufErrorFormatAndPush(__FILE__, __func__, __LINE__, maj, min, fmt, __VA_ARGS__)
172 
173 
174 
177 #define IUF_ERROR_FMT_PRINT(maj,min,fmt,...) iufErrorFormatAndPush(__FILE__, __func__, __LINE__, maj, min, fmt, __VA_ARGS__);\
178  iufErrorPrint();
179 
180 
181 // Error handling convenience macro's
182 
186 #define IUF_ERR_ALLOC_NULL_N_RETURN(var, adt, retval) if ((var) == NULL) { \
187  IUF_ERROR_PUSH(IUF_ERR_MAJ_MEMORY, IUF_ERR_MIN_ALLOC, "calloc failed for " #adt); \
188  return retval; \
189  }
190 
191 
195 #define IUF_ERR_CHECK_NULL_N_RETURN(var, retval) if ((var) == NULL) { \
196  IUF_ERROR_PUSH(IUF_ERR_MAJ_VALUE, IUF_ERR_MIN_ARG_NULL_VALUE, "argument " #var " was NULL"); \
197  return retval; \
198  }
199 
203 #define IUF_ERR_CHECK_EMPTYSTR_N_RETURN(var, return_value) if (strcmp((var),"") == 0) { \
204  IUF_ERROR_PUSH(IUF_ERR_MAJ_VALUE, IUF_ERR_MIN_ARG_VALUE, "argument " #var " was empty"); \
205  return return_value; \
206  }
207 
208 
212 #define IUF_ERR_STRP_NULL_EMPTY(var, retval) IUF_ERR_CHECK_NULL_N_RETURN(var, retval); \
213  IUF_ERR_CHECK_EMPTYSTR_N_RETURN(var, retval)
214 
215 
219 #define IUF_ERR_EVAL_N_RETURN(expr, retval) if (expr) { \
220  IUF_ERROR_PUSH(IUF_ERR_MAJ_VALUE, IUF_ERR_MIN_ARG_VALUE, #expr ""); \
221  return retval; \
222  }
223 
224 
228 #define IUF_ERR_GENERAL (100001)
229 #define IUF_ERR_MEMORY (100002)
230 #define IUF_ERR_VALUE (100003)
235 #define IUF_UNUSED(x) (void)(x)
236 
240 #define IUF_ASSERT( IN_CONDITION ) \
241 { \
242  if ( !(IN_CONDITION) )\
243  { \
244  IUF_ERROR_PUSH(IUF_ERR_MAJ_GENERAL,IUF_ERR_MIN_ASSERT_FAILED, "General error occurred, assertion failed for " #IN_CONDITION); \
245  exit( IUF_ERR_GENERAL ); \
246  } \
247 }
248 
252 #define IUF_ASSERT_MEMORY( IN_CONDITION ) \
253 { \
254  if ( !(IN_CONDITION) )\
255  { \
256  IUF_ERROR_PUSH(IUF_ERR_MAJ_MEMORY,IUF_ERR_MIN_ASSERT_FAILED, "Memory error occurred, assertion failed for " #IN_CONDITION); \
257  exit( IUF_ERR_MEMORY ); \
258  } \
259 }
260 
264 #define IUF_ASSERT_VALUE( IN_CONDITION ) \
265 { \
266  if ( !(IN_CONDITION) )\
267  { \
268  IUF_ERROR_PUSH(IUF_ERR_MAJ_VALUE,IUF_ERR_MIN_ASSERT_FAILED, "Value error occurred, assertion failed for " #IN_CONDITION); \
269  exit( IUF_ERR_VALUE ); \
270  } \
271 }
272 
273 
274 #endif // _IUFERROR_H
hid_t IUF_ERR_MAJ_GENERAL
Major error handling class for general errors.
Definition: iufError.c:9
char * iufErrorString()
Create a string representation of the current Error stack.
Definition: iufError.c:264
int iufErrorPrint()
Prints the Error stack.
Definition: iufError.c:240
int iufErrorLog(IUF_BOOL enable)
Enable or disable IUF library error logging.
Definition: iufError.c:272
int iufErrorPush(const char *pFileName, const char *pFunctionName, int lineNumber, hid_t maj, hid_t min, char *msg)
Pushes an Error context onto the IUF error stack.
Definition: iufError.c:142
hid_t IUF_ERR_MIN_ARG_DUPLICATE_KEY
Minor error handling class for duplicate key errors in a dictionary.
Definition: iufError.c:21
hid_t IUF_ERR_MAJ_ERROR
Major error handling class for errors.
Definition: iufError.c:12
int iufErrorLogClear(void)
Removes all messages from the error stack.
Definition: iufError.c:253
int iufErrorSetStreamToFile(const char *pFileName)
Error messages wil be printed to the file with name pFileName.
Definition: iufError.c:325
hid_t IUF_ERR_MIN_ASSERT_FAILED
Minor error handling class for assertion errors.
Definition: iufError.c:25
int iufErrorAutoReportSet(IUF_BOOL enable)
Error messages wil printed when encountered by the library calls.
Definition: iufError.c:305
hid_t IUF_ERR_MAJ_HDF5
Major error handling class for hdf5 io errors.
Definition: iufError.c:13
hid_t IUF_ERR_MIN_MEMCOPY
Minor error handling class for memory errors.
Definition: iufError.c:17
hid_t IUF_ERR_MIN_FORMAT
Minor error handling class for formatting errors.
Definition: iufError.c:19
hid_t IUF_ERR_MIN_ARG_INVALID_KEY
Minor error handling class for invalid key errors in a dictionary.
Definition: iufError.c:22
hid_t IUF_ERR_MIN_ARG_NULL_VALUE
Minor error handling class for NULL values.
Definition: iufError.c:20
hid_t IUF_ERR_MAJ_VALUE
Major error handling class for value related errors.
Definition: iufError.c:11
hid_t IUF_ERR_MIN_HDF5
Minor error handling class for invalid hdf5 file io errors.
Definition: iufError.c:23
int iufErrorSetStream(FILE *stream)
Error messages wil be printed to this FILE stream (i.e. stdout would sent the errors to console outpu...
Definition: iufError.c:315
hid_t IUF_ERR_MIN_ALLOC
Minor error handling class for memory allocation value errors.
Definition: iufError.c:16
hid_t IUF_ERR_MIN_ARG_FILENAME
Minor error handling class for filename errors.
Definition: iufError.c:15
IUF_BOOL iufErrorAutoReportGet(void)
Error messages wil printed when encountered by the library calls.
Definition: iufError.c:296
int iufErrorGetCount(void)
Get the number of errors that occurred so far.
Definition: iufError.c:186
int iufErrorFormatAndPush(const char *pFileName, const char *pFunctionName, int lineNumber, hid_t maj, hid_t min, char *msgFormat,...)
Format and Push an Error context onto the IUF error stack.
Definition: iufError.c:161
int iufHDF5ErrorLog(IUF_BOOL enable)
Enable or disable HDF5 library error logging.
Definition: iufError.c:280
int IUF_BOOL
Definition: iufTypes.h:8
Top level header file, include this file to access all public iuf function declarations.
int iufErrorCloseFileStream()
Closes the filestream opened with iufErrorSetStreamToFile() and resets the stream to stderr...
Definition: iufError.c:339
hid_t IUF_ERR_MIN_ARG_VALUE
Minor error handling class for argument value errors.
Definition: iufError.c:24
hid_t IUF_ERR_MAJ_MEMORY
Major error handling class for memory errors.
Definition: iufError.c:10