ifw-odp  2.0.0-alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
clipm_priv_error.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  * E.S.O. - VLT project
4  *
5  * "@(#) $Id: clipm_priv_error.h 279867 2016-03-10 10:39:31Z cgarcia $"
6  *
7  * PRIVATE functions for clipm internal error handling, requires CPL 4.0
8  *
9  * who when what
10  * -------- ---------- ----------------------------------------------
11  * hlorch 2006-05-11 created
12  */
13 
35 #ifndef CLIPM_PRIV_ERROR_H
36 #define CLIPM_PRIV_ERROR_H
37 
38 /*-----------------------------------------------------------------------------
39  Includes
40  -----------------------------------------------------------------------------*/
41 
42 #include <cpl.h>
43 
44 #include <string.h>
45 
46 /*-----------------------------------------------------------------------------
47  Functional Macros
48  -----------------------------------------------------------------------------*/
49 
50 #define _CLIPM_ERROR_SET_WHERE_() \
51 do { \
52  if (CLIPM_ERROR_IS_SET()) \
53  { \
54  const char *_msg; \
55  int _n = 0; \
56  \
57  _msg = cpl_error_get_message(); \
58  /* search the beginning of the last custom message */ \
59  while (_msg[_n] != '\0' && _msg[_n] != ':') \
60  _n++; \
61  while (_msg[_n] == ':' || _msg[_n] == ' ') \
62  _n++; \
63  cpl_error_set_message( __func__, \
64  cpl_error_get_code(), \
65  "%s", _msg+_n); \
66  clipm_error_is_set_where = 1; \
67  } \
68 } while (0)
69 
70 #define _CLIPM_ERROR_SET_MSG_(code, object, msg) \
71 do { \
72  char _clipm_error_msg[256]; \
73  _clipm_priv_error_sprint_messages( _clipm_error_msg, \
74  object, \
75  msg, \
76  255); \
77  cpl_error_set_message( __func__, \
78  code, \
79  "%s", _clipm_error_msg); \
80  clipm_error_is_set_where = 1; \
81 } while (0)
82 
83 /*----------------------------------------------------------------------------*/
171 /*----------------------------------------------------------------------------*/
172 #define CLIPM_TRY \
173  int clipm_error_catch_call_flag, \
174  clipm_error_is_set_where = 0; \
175  cpl_errorstate clipm_error_trystate; \
176  \
177  clipm_error_trystate = cpl_errorstate_get(); \
178  \
179  do
180 
181 /*----------------------------------------------------------------------------*/
188 /*----------------------------------------------------------------------------*/
189 #define CLIPM_CATCH \
190  while (0); \
191  \
192  goto _CLIPM_CATCH_LABEL_; /* avoid warning if not used */ \
193  _CLIPM_CATCH_LABEL_: \
194  \
195  if ((clipm_error_catch_call_flag = (CLIPM_ERROR_IS_SET()))) \
196  { \
197  if (!clipm_error_is_set_where) \
198  _CLIPM_ERROR_SET_WHERE_(); \
199  } \
200  \
201  if (clipm_error_catch_call_flag)
202 
203 /*----------------------------------------------------------------------------*/
213 /*----------------------------------------------------------------------------*/
214 #define CLIPM_ERROR_GET_NEW_SINCE_TRY(void) \
215  (CLIPM_ERROR_IS_NONE() ? CPL_ERROR_NONE : cpl_error_get_code())
216 
217 /*----------------------------------------------------------------------------*/
225 /*----------------------------------------------------------------------------*/
226 #define CLIPM_ERROR_RECOVER_TRYSTATE(void) \
227 do { \
228  cpl_errorstate_set(clipm_error_trystate); \
229  clipm_error_is_set_where = 0; \
230 } while (0)
231 
232 /*----------------------------------------------------------------------------*/
240 /*----------------------------------------------------------------------------*/
241 #define CLIPM_ERROR_SET(code) \
242 do { \
243  CLIPM_TRY_ASSERT(code != CPL_ERROR_NONE); \
244  cpl_error_set(__func__, code); \
245  clipm_error_is_set_where = 1; \
246 } while (0)
247 
248 /*----------------------------------------------------------------------------*/
256 /*----------------------------------------------------------------------------*/
257 #define CLIPM_ERROR_SET_MSG(code, object, msg) \
258 do { \
259  CLIPM_TRY_ASSERT(code != CPL_ERROR_NONE); \
260  _CLIPM_ERROR_SET_MSG_(code, object, msg); \
261 } while (0)
262 
263 /*----------------------------------------------------------------------------*/
272 /*----------------------------------------------------------------------------*/
273 #define CLIPM_ERROR_SET_MSG_IF_CODE(code, object, msg) \
274 do { \
275  CLIPM_TRY_ASSERT(code != CPL_ERROR_NONE); \
276  if (CLIPM_ERROR_GET_NEW_SINCE_TRY() == code) \
277  _CLIPM_ERROR_SET_MSG_(code, object, msg); \
278 } while (0)
279 
280 /*----------------------------------------------------------------------------*/
290 /*----------------------------------------------------------------------------*/
291 #define CLIPM_ERROR_IS_SET(void) \
292  (!cpl_errorstate_is_equal(clipm_error_trystate))
293 
294 /*----------------------------------------------------------------------------*/
304 /*----------------------------------------------------------------------------*/
305 #define CLIPM_ERROR_IS_NONE(void) \
306  (cpl_errorstate_is_equal(clipm_error_trystate))
307 
308 /*----------------------------------------------------------------------------*/
321 /*----------------------------------------------------------------------------*/
322 #define CLIPM_TRY_CHECK(condition, code, object, msg) \
323 do { \
324  if (!(condition)) \
325  { \
326  CLIPM_ERROR_SET_MSG( (code), (object), (msg)); \
327  CLIPM_TRY_EXIT(); \
328  } \
329 } while (0)
330 
331 /*----------------------------------------------------------------------------*/
342 /*----------------------------------------------------------------------------*/
343 #define CLIPM_TRY_CHECK_AUTOMSG(condition, code) \
344 do { \
345  if (!(condition)) \
346  { \
347  CLIPM_ERROR_SET_MSG( (code), "!("#condition")", ""); \
348  CLIPM_TRY_EXIT(); \
349  } \
350 } while (0)
351 
352 /*----------------------------------------------------------------------------*/
361 /*----------------------------------------------------------------------------*/
362 #define CLIPM_TRY_CHECK_ERROR_STATE(void) \
363 do { \
364  if (CLIPM_ERROR_IS_SET()) \
365  { \
366  if (!clipm_error_is_set_where) \
367  _CLIPM_ERROR_SET_WHERE_(); \
368  CLIPM_TRY_EXIT(); \
369  } \
370 } while (0)
371 
372 /*----------------------------------------------------------------------------*/
381 /*----------------------------------------------------------------------------*/
382 #define CLIPM_TRY_ASSERT(condition) \
383 do { \
384  if (!(condition)) \
385  { \
386  _CLIPM_ERROR_SET_MSG_( CLIPM_ERROR_UNEXPECTED, \
387  "!("#condition")", \
388  _CLIPM_MSG_ERR_UNEXPECTED); \
389  CLIPM_TRY_EXIT(); \
390  } \
391 } while (0)
392 
393 /*----------------------------------------------------------------------------*/
402 /*----------------------------------------------------------------------------*/
403 #define CLIPM_TRY_ASSERT_ERROR_STATE(void) \
404 do { \
405  if (CLIPM_ERROR_IS_SET()) \
406  { \
407  _CLIPM_ERROR_SET_MSG_( CLIPM_ERROR_UNEXPECTED, \
408  NULL, \
409  _CLIPM_MSG_ERR_UNEXPECTED); \
410  CLIPM_TRY_EXIT(); \
411  } \
412 } while (0)
413 
414 /*----------------------------------------------------------------------------*/
422 /*----------------------------------------------------------------------------*/
423 #define CLIPM_TRY_EXIT_WITH_ERROR(code) \
424 do { \
425  CLIPM_ERROR_SET((code)); \
426  CLIPM_TRY_EXIT(); \
427 } while (0)
428 
429 /*----------------------------------------------------------------------------*/
439 /*----------------------------------------------------------------------------*/
440 #define CLIPM_TRY_EXIT_WITH_ERROR_MSG(code, object, msg) \
441 do { \
442  CLIPM_ERROR_SET_MSG((code), (object), (msg)); \
443  CLIPM_TRY_EXIT(); \
444 } while (0)
445 
446 /*----------------------------------------------------------------------------*/
460 /*----------------------------------------------------------------------------*/
461 #define CLIPM_TRY_EXIT_IFN(condition) \
462 do { \
463  if (!(condition)) \
464  { \
465  CLIPM_TRY_ASSERT(CLIPM_ERROR_IS_SET()); \
466  if (!clipm_error_is_set_where) \
467  _CLIPM_ERROR_SET_WHERE_(); \
468  CLIPM_TRY_EXIT(); \
469  } \
470 } while (0)
471 
472 /*----------------------------------------------------------------------------*/
481 /*----------------------------------------------------------------------------*/
482 #define CLIPM_TRY_EXIT(void) \
483  goto _CLIPM_CATCH_LABEL_
484 
485 
486 /*-----------------------------------------------------------------------------
487  Declarations
488  -----------------------------------------------------------------------------*/
489 
490 #ifdef __cplusplus
491 extern "C" {
492 #endif
493 
494 /*-----------------------------------------------------------------------------
495  Types
496  -----------------------------------------------------------------------------*/
497 
502 typedef enum _clipm_error_code_ {
503  CLIPM_ERROR_UNEXPECTED = CPL_ERROR_EOL + 0
506 
508 extern const char _CLIPM_MSG_ERR_UNEXPECTED[];
510 extern const char _CLIPM_MSG_ERR_HANDLING[];
511 
513 extern const char CLIPM_MSG_ERR_2ROWXY[];
515 extern const char CLIPM_MSG_ERR_DIFFSIZES[];
517 extern const char CLIPM_MSG_ERR_DIFFTYPES[];
518 
520 /*-----------------------------------------------------------------------------
521  Prototypes
522  -----------------------------------------------------------------------------*/
523 
525  char *outstr,
526  const char *msg1,
527  const char *msg2,
528  size_t maxlen);
529 
530 /*----------------------------------------------------------------------------*/
531 
532 #ifdef __cplusplus
533 } /* extern "C" */
534 #endif
535 
536 #endif /* CLIPM_PRIV_ERROR_H */
const char _CLIPM_MSG_ERR_UNEXPECTED[]
Internal error.
Definition: clipm_priv_error.c:26
const char CLIPM_MSG_ERR_DIFFSIZES[]
Location matrices differ in size.
Definition: clipm_priv_error.c:34
enum _clipm_error_code_ clipm_error_code
Extension to CPL error codes.
void _clipm_priv_error_sprint_messages(char *outstr, const char *msg1, const char *msg2, size_t maxlen)
Definition: clipm_priv_error.c:58
Definition: clipm_priv_error.h:503
_clipm_error_code_
Extension to CPL error codes.
Definition: clipm_priv_error.h:502
const char CLIPM_MSG_ERR_2ROWXY[]
Location matrix must contain 2 rows.
Definition: clipm_priv_error.c:32
const char _CLIPM_MSG_ERR_HANDLING[]
Internal error handling bug.
Definition: clipm_priv_error.c:29
const char CLIPM_MSG_ERR_DIFFTYPES[]
Location matrices differ in size.
Definition: clipm_priv_error.c:36