ifw-odp 5.1.1
 
Loading...
Searching...
No Matches
clipm_priv_error.h
Go to the documentation of this file.
1
7
28
29#ifndef CLIPM_PRIV_ERROR_H
30#define CLIPM_PRIV_ERROR_H
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include <cpl.h>
37
38#include <string.h>
39
40/*-----------------------------------------------------------------------------
41 Functional Macros
42 -----------------------------------------------------------------------------*/
43
44#define _CLIPM_ERROR_SET_WHERE_() \
45do { \
46 if (CLIPM_ERROR_IS_SET()) \
47 { \
48 const char *_msg; \
49 int _n = 0; \
50 \
51 _msg = cpl_error_get_message(); \
52 /* search the beginning of the last custom message */ \
53 while (_msg[_n] != '\0' && _msg[_n] != ':') \
54 _n++; \
55 while (_msg[_n] == ':' || _msg[_n] == ' ') \
56 _n++; \
57 cpl_error_set_message( __func__, \
58 cpl_error_get_code(), \
59 "%s", _msg+_n); \
60 clipm_error_is_set_where = 1; \
61 } \
62} while (0)
63
64#define _CLIPM_ERROR_SET_MSG_(code, object, msg) \
65do { \
66 char _clipm_error_msg[256]; \
67 _clipm_priv_error_sprint_messages( _clipm_error_msg, \
68 object, \
69 msg, \
70 255); \
71 cpl_error_set_message( __func__, \
72 code, \
73 "%s", _clipm_error_msg); \
74 clipm_error_is_set_where = 1; \
75} while (0)
76
77/*----------------------------------------------------------------------------*/
165
166/*----------------------------------------------------------------------------*/
167#define CLIPM_TRY \
168 int clipm_error_catch_call_flag, \
169 clipm_error_is_set_where = 0; \
170 cpl_errorstate clipm_error_trystate; \
171 \
172 clipm_error_trystate = cpl_errorstate_get(); \
173 \
174 do
175
176/*----------------------------------------------------------------------------*/
183/*----------------------------------------------------------------------------*/
184#define CLIPM_CATCH \
185 while (0); \
186 \
187 goto _CLIPM_CATCH_LABEL_; /* avoid warning if not used */ \
188 _CLIPM_CATCH_LABEL_: \
189 \
190 if ((clipm_error_catch_call_flag = (CLIPM_ERROR_IS_SET()))) \
191 { \
192 if (!clipm_error_is_set_where) \
193 _CLIPM_ERROR_SET_WHERE_(); \
194 } \
195 \
196 if (clipm_error_catch_call_flag)
197
198/*----------------------------------------------------------------------------*/
208/*----------------------------------------------------------------------------*/
209#define CLIPM_ERROR_GET_NEW_SINCE_TRY(void) \
210 (CLIPM_ERROR_IS_NONE() ? CPL_ERROR_NONE : cpl_error_get_code())
211
212/*----------------------------------------------------------------------------*/
220/*----------------------------------------------------------------------------*/
221#define CLIPM_ERROR_RECOVER_TRYSTATE(void) \
222do { \
223 cpl_errorstate_set(clipm_error_trystate); \
224 clipm_error_is_set_where = 0; \
225} while (0)
226
227/*----------------------------------------------------------------------------*/
235/*----------------------------------------------------------------------------*/
236#define CLIPM_ERROR_SET(code) \
237do { \
238 CLIPM_TRY_ASSERT(code != CPL_ERROR_NONE); \
239 cpl_error_set(__func__, code); \
240 clipm_error_is_set_where = 1; \
241} while (0)
242
243/*----------------------------------------------------------------------------*/
251/*----------------------------------------------------------------------------*/
252#define CLIPM_ERROR_SET_MSG(code, object, msg) \
253do { \
254 CLIPM_TRY_ASSERT(code != CPL_ERROR_NONE); \
255 _CLIPM_ERROR_SET_MSG_(code, object, msg); \
256} while (0)
257
258/*----------------------------------------------------------------------------*/
267/*----------------------------------------------------------------------------*/
268#define CLIPM_ERROR_SET_MSG_IF_CODE(code, object, msg) \
269do { \
270 CLIPM_TRY_ASSERT(code != CPL_ERROR_NONE); \
271 if (CLIPM_ERROR_GET_NEW_SINCE_TRY() == code) \
272 _CLIPM_ERROR_SET_MSG_(code, object, msg); \
273} while (0)
274
275/*----------------------------------------------------------------------------*/
285/*----------------------------------------------------------------------------*/
286#define CLIPM_ERROR_IS_SET(void) \
287 (!cpl_errorstate_is_equal(clipm_error_trystate))
288
289/*----------------------------------------------------------------------------*/
299/*----------------------------------------------------------------------------*/
300#define CLIPM_ERROR_IS_NONE(void) \
301 (cpl_errorstate_is_equal(clipm_error_trystate))
302
303/*----------------------------------------------------------------------------*/
316/*----------------------------------------------------------------------------*/
317#define CLIPM_TRY_CHECK(condition, code, object, msg) \
318do { \
319 if (!(condition)) \
320 { \
321 CLIPM_ERROR_SET_MSG( (code), (object), (msg)); \
322 CLIPM_TRY_EXIT(); \
323 } \
324} while (0)
325
326/*----------------------------------------------------------------------------*/
337/*----------------------------------------------------------------------------*/
338#define CLIPM_TRY_CHECK_AUTOMSG(condition, code) \
339do { \
340 if (!(condition)) \
341 { \
342 CLIPM_ERROR_SET_MSG( (code), "!("#condition")", ""); \
343 CLIPM_TRY_EXIT(); \
344 } \
345} while (0)
346
347/*----------------------------------------------------------------------------*/
356/*----------------------------------------------------------------------------*/
357#define CLIPM_TRY_CHECK_ERROR_STATE(void) \
358do { \
359 if (CLIPM_ERROR_IS_SET()) \
360 { \
361 if (!clipm_error_is_set_where) \
362 _CLIPM_ERROR_SET_WHERE_(); \
363 CLIPM_TRY_EXIT(); \
364 } \
365} while (0)
366
367/*----------------------------------------------------------------------------*/
376/*----------------------------------------------------------------------------*/
377#define CLIPM_TRY_ASSERT(condition) \
378do { \
379 if (!(condition)) \
380 { \
381 _CLIPM_ERROR_SET_MSG_( CLIPM_ERROR_UNEXPECTED, \
382 "!("#condition")", \
383 _CLIPM_MSG_ERR_UNEXPECTED); \
384 CLIPM_TRY_EXIT(); \
385 } \
386} while (0)
387
388/*----------------------------------------------------------------------------*/
397/*----------------------------------------------------------------------------*/
398#define CLIPM_TRY_ASSERT_ERROR_STATE(void) \
399do { \
400 if (CLIPM_ERROR_IS_SET()) \
401 { \
402 _CLIPM_ERROR_SET_MSG_( CLIPM_ERROR_UNEXPECTED, \
403 NULL, \
404 _CLIPM_MSG_ERR_UNEXPECTED); \
405 CLIPM_TRY_EXIT(); \
406 } \
407} while (0)
408
409/*----------------------------------------------------------------------------*/
417/*----------------------------------------------------------------------------*/
418#define CLIPM_TRY_EXIT_WITH_ERROR(code) \
419do { \
420 CLIPM_ERROR_SET((code)); \
421 CLIPM_TRY_EXIT(); \
422} while (0)
423
424/*----------------------------------------------------------------------------*/
434/*----------------------------------------------------------------------------*/
435#define CLIPM_TRY_EXIT_WITH_ERROR_MSG(code, object, msg) \
436do { \
437 CLIPM_ERROR_SET_MSG((code), (object), (msg)); \
438 CLIPM_TRY_EXIT(); \
439} while (0)
440
441/*----------------------------------------------------------------------------*/
455/*----------------------------------------------------------------------------*/
456#define CLIPM_TRY_EXIT_IFN(condition) \
457do { \
458 if (!(condition)) \
459 { \
460 CLIPM_TRY_ASSERT(CLIPM_ERROR_IS_SET()); \
461 if (!clipm_error_is_set_where) \
462 _CLIPM_ERROR_SET_WHERE_(); \
463 CLIPM_TRY_EXIT(); \
464 } \
465} while (0)
466
467/*----------------------------------------------------------------------------*/
476/*----------------------------------------------------------------------------*/
477#define CLIPM_TRY_EXIT(void) \
478 goto _CLIPM_CATCH_LABEL_
479
480
481/*-----------------------------------------------------------------------------
482 Declarations
483 -----------------------------------------------------------------------------*/
484
485#ifdef __cplusplus
486extern "C" {
487#endif
488
489/*-----------------------------------------------------------------------------
490 Types
491 -----------------------------------------------------------------------------*/
492
496
501
503extern const char _CLIPM_MSG_ERR_UNEXPECTED[];
505extern const char _CLIPM_MSG_ERR_HANDLING[];
506
508extern const char CLIPM_MSG_ERR_2ROWXY[];
510extern const char CLIPM_MSG_ERR_DIFFSIZES[];
512extern const char CLIPM_MSG_ERR_DIFFTYPES[];
513
515/*-----------------------------------------------------------------------------
516 Prototypes
517 -----------------------------------------------------------------------------*/
518
520 char *outstr,
521 const char *msg1,
522 const char *msg2,
523 size_t maxlen);
524
525/*----------------------------------------------------------------------------*/
526
527#ifdef __cplusplus
528} /* extern "C" */
529#endif
530
531#endif /* CLIPM_PRIV_ERROR_H */
const char CLIPM_MSG_ERR_2ROWXY[]
Location matrix must contain 2 rows.
Definition clipm_priv_error.c:25
_clipm_error_code_
Extension to CPL error codes.
Definition clipm_priv_error.h:497
@ CLIPM_ERROR_UNEXPECTED
Definition clipm_priv_error.h:498
enum _clipm_error_code_ clipm_error_code
Extension to CPL error codes.
const char CLIPM_MSG_ERR_DIFFTYPES[]
Location matrices differ in size.
Definition clipm_priv_error.c:29
const char _CLIPM_MSG_ERR_HANDLING[]
Internal error handling bug.
Definition clipm_priv_error.c:22
const char CLIPM_MSG_ERR_DIFFSIZES[]
Location matrices differ in size.
Definition clipm_priv_error.c:27
const char _CLIPM_MSG_ERR_UNEXPECTED[]
Internal error.
Definition clipm_priv_error.c:19
void _clipm_priv_error_sprint_messages(char *outstr, const char *msg1, const char *msg2, size_t maxlen)
Definition clipm_priv_error.c:51