cpl_error.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**********************************************************************
  2. * $Id: cpl_error.h 27384 2014-05-24 12:28:12Z rouault $
  3. *
  4. * Name: cpl_error.h
  5. * Project: CPL - Common Portability Library
  6. * Purpose: CPL Error handling
  7. * Author: Daniel Morissette, danmo@videotron.ca
  8. *
  9. **********************************************************************
  10. * Copyright (c) 1998, Daniel Morissette
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a
  13. * copy of this software and associated documentation files (the "Software"),
  14. * to deal in the Software without restriction, including without limitation
  15. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  16. * and/or sell copies of the Software, and to permit persons to whom the
  17. * Software is furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be included
  20. * in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  25. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  27. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  28. * DEALINGS IN THE SOFTWARE.
  29. ****************************************************************************/
  30. #ifndef CPL_ERROR_H_INCLUDED
  31. #define CPL_ERROR_H_INCLUDED
  32. #include "cpl_port.h"
  33. /*=====================================================================
  34. Error handling functions (cpl_error.c)
  35. =====================================================================*/
  36. /**
  37. * \file cpl_error.h
  38. *
  39. * CPL error handling services.
  40. */
  41. CPL_C_START
  42. typedef enum
  43. {
  44. CE_None = 0,
  45. CE_Debug = 1,
  46. CE_Warning = 2,
  47. CE_Failure = 3,
  48. CE_Fatal = 4
  49. } CPLErr;
  50. void CPL_DLL CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (3, 4);
  51. void CPL_DLL CPLErrorV(CPLErr, int, const char *, va_list );
  52. void CPL_DLL CPLEmergencyError( const char * );
  53. void CPL_DLL CPL_STDCALL CPLErrorReset( void );
  54. int CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
  55. CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
  56. const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
  57. void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
  58. void CPL_DLL CPLErrorSetState( CPLErr eErrClass, int err_no, const char* pszMsg );
  59. void CPL_DLL CPLCleanupErrorMutex( void );
  60. typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, int, const char*);
  61. void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, int, const char * );
  62. void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, int, const char * );
  63. void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, int, const char * );
  64. void CPLTurnFailureIntoWarning(int bOn );
  65. CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler(CPLErrorHandler);
  66. CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx(CPLErrorHandler, void*);
  67. void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
  68. void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
  69. void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
  70. void CPL_DLL CPL_STDCALL CPLDebug( const char *, const char *, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
  71. void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int );
  72. #ifdef DEBUG
  73. # define CPLAssert(expr) ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
  74. #else
  75. # define CPLAssert(expr)
  76. #endif
  77. CPL_C_END
  78. /*
  79. * Helper macros used for input parameters validation.
  80. */
  81. #ifdef DEBUG
  82. # define VALIDATE_POINTER_ERR CE_Fatal
  83. #else
  84. # define VALIDATE_POINTER_ERR CE_Failure
  85. #endif
  86. #define VALIDATE_POINTER0(ptr, func) \
  87. do { if( NULL == ptr ) \
  88. { \
  89. CPLErr const ret = VALIDATE_POINTER_ERR; \
  90. CPLError( ret, CPLE_ObjectNull, \
  91. "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
  92. return; }} while(0)
  93. #define VALIDATE_POINTER1(ptr, func, rc) \
  94. do { if( NULL == ptr ) \
  95. { \
  96. CPLErr const ret = VALIDATE_POINTER_ERR; \
  97. CPLError( ret, CPLE_ObjectNull, \
  98. "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
  99. return (rc); }} while(0)
  100. /* ==================================================================== */
  101. /* Well known error codes. */
  102. /* ==================================================================== */
  103. #define CPLE_None 0
  104. #define CPLE_AppDefined 1
  105. #define CPLE_OutOfMemory 2
  106. #define CPLE_FileIO 3
  107. #define CPLE_OpenFailed 4
  108. #define CPLE_IllegalArg 5
  109. #define CPLE_NotSupported 6
  110. #define CPLE_AssertionFailed 7
  111. #define CPLE_NoWriteAccess 8
  112. #define CPLE_UserInterrupt 9
  113. #define CPLE_ObjectNull 10
  114. /* 100 - 299 reserved for GDAL */
  115. #endif /* CPL_ERROR_H_INCLUDED */