gooderp18绿色标准版
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

285 líneas
9.0KB

  1. /**********************************************************************
  2. * $Id: cpl_error.h e3511844a11959bd81f5956a1e7e2de96900e7ac 2019-04-25 11:53:15 +0200 Even 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. #include <stdarg.h>
  34. #include <stddef.h>
  35. /*=====================================================================
  36. Error handling functions (cpl_error.c)
  37. =====================================================================*/
  38. /**
  39. * \file cpl_error.h
  40. *
  41. * CPL error handling services.
  42. */
  43. CPL_C_START
  44. /** Error category */
  45. typedef enum
  46. {
  47. CE_None = 0,
  48. CE_Debug = 1,
  49. CE_Warning = 2,
  50. CE_Failure = 3,
  51. CE_Fatal = 4
  52. } CPLErr;
  53. /* ==================================================================== */
  54. /* Well known error codes. */
  55. /* ==================================================================== */
  56. #ifdef STRICT_CPLERRORNUM_TYPE
  57. /* This is not appropriate for the general case, as there are parts */
  58. /* of GDAL which use custom error codes, but this can help diagnose confusions */
  59. /* between CPLErr and CPLErrorNum */
  60. typedef enum
  61. {
  62. CPLE_None,
  63. CPLE_AppDefined,
  64. CPLE_OutOfMemory,
  65. CPLE_FileIO,
  66. CPLE_OpenFailed,
  67. CPLE_IllegalArg,
  68. CPLE_NotSupported,
  69. CPLE_AssertionFailed,
  70. CPLE_NoWriteAccess,
  71. CPLE_UserInterrupt,
  72. CPLE_ObjectNull,
  73. CPLE_HttpResponse,
  74. CPLE_AWSBucketNotFound,
  75. CPLE_AWSObjectNotFound,
  76. CPLE_AWSAccessDenied,
  77. CPLE_AWSInvalidCredentials,
  78. CPLE_AWSSignatureDoesNotMatch,
  79. } CPLErrorNum;
  80. #else
  81. /** Error number */
  82. typedef int CPLErrorNum;
  83. /** No error */
  84. #define CPLE_None 0
  85. /** Application defined error */
  86. #define CPLE_AppDefined 1
  87. /** Out of memory error */
  88. #define CPLE_OutOfMemory 2
  89. /** File I/O error */
  90. #define CPLE_FileIO 3
  91. /** Open failed */
  92. #define CPLE_OpenFailed 4
  93. /** Illegal argument */
  94. #define CPLE_IllegalArg 5
  95. /** Not supported */
  96. #define CPLE_NotSupported 6
  97. /** Assertion failed */
  98. #define CPLE_AssertionFailed 7
  99. /** No write access */
  100. #define CPLE_NoWriteAccess 8
  101. /** User interrupted */
  102. #define CPLE_UserInterrupt 9
  103. /** NULL object */
  104. #define CPLE_ObjectNull 10
  105. /*
  106. * Filesystem-specific errors
  107. */
  108. /** HTTP response */
  109. #define CPLE_HttpResponse 11
  110. /** AWSBucketNotFound */
  111. #define CPLE_AWSBucketNotFound 12
  112. /** AWSObjectNotFound */
  113. #define CPLE_AWSObjectNotFound 13
  114. /** AWSAccessDenied */
  115. #define CPLE_AWSAccessDenied 14
  116. /** AWSInvalidCredentials */
  117. #define CPLE_AWSInvalidCredentials 15
  118. /** AWSSignatureDoesNotMatch */
  119. #define CPLE_AWSSignatureDoesNotMatch 16
  120. /** VSIE_AWSError */
  121. #define CPLE_AWSError 17
  122. /* 100 - 299 reserved for GDAL */
  123. #endif
  124. void CPL_DLL CPLError(CPLErr eErrClass, CPLErrorNum err_no, CPL_FORMAT_STRING(const char *fmt), ...) CPL_PRINT_FUNC_FORMAT (3, 4);
  125. void CPL_DLL CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list );
  126. void CPL_DLL CPLEmergencyError( const char * ) CPL_NO_RETURN;
  127. void CPL_DLL CPL_STDCALL CPLErrorReset( void );
  128. CPLErrorNum CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
  129. CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
  130. const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
  131. GUInt32 CPL_DLL CPL_STDCALL CPLGetErrorCounter( void );
  132. void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
  133. void CPL_DLL CPLErrorSetState( CPLErr eErrClass, CPLErrorNum err_no, const char* pszMsg );
  134. /*! @cond Doxygen_Suppress */
  135. void CPL_DLL CPLCleanupErrorMutex( void );
  136. /*! @endcond */
  137. /** Callback for a custom error handler */
  138. typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, CPLErrorNum, const char*);
  139. void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, CPLErrorNum, const char * );
  140. void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, CPLErrorNum, const char * );
  141. void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, CPLErrorNum, const char * );
  142. void CPLTurnFailureIntoWarning( int bOn );
  143. CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler( CPLErrorHandler );
  144. CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx( CPLErrorHandler, void* );
  145. void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
  146. void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
  147. void CPL_DLL CPL_STDCALL CPLSetCurrentErrorHandlerCatchDebug( int bCatchDebug );
  148. void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
  149. #ifdef WITHOUT_CPLDEBUG
  150. #define CPLDebug(...) /* Eat all CPLDebug calls. */
  151. #else
  152. void CPL_DLL CPL_STDCALL CPLDebug(const char *, CPL_FORMAT_STRING(const char *), ...)
  153. CPL_PRINT_FUNC_FORMAT(2, 3);
  154. #endif
  155. void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int ) CPL_NO_RETURN;
  156. #ifdef DEBUG
  157. /** Assert on an expression. Only enabled in DEBUG mode */
  158. # define CPLAssert(expr) ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
  159. /** Assert on an expression in DEBUG mode. Evaluate it also in non-DEBUG mode (useful to 'consume' a error return variable) */
  160. # define CPLAssertAlwaysEval(expr) CPLAssert(expr)
  161. #else
  162. /** Assert on an expression. Only enabled in DEBUG mode */
  163. # define CPLAssert(expr)
  164. #ifdef __cplusplus
  165. /** Assert on an expression in DEBUG mode. Evaluate it also in non-DEBUG mode (useful to 'consume' a error return variable) */
  166. # define CPLAssertAlwaysEval(expr) CPL_IGNORE_RET_VAL(expr)
  167. #else
  168. /** Assert on an expression in DEBUG mode. Evaluate it also in non-DEBUG mode (useful to 'consume' a error return variable) */
  169. # define CPLAssertAlwaysEval(expr) (void)(expr)
  170. #endif
  171. #endif
  172. CPL_C_END
  173. /*! @cond Doxygen_Suppress */
  174. /*
  175. * Helper macros used for input parameters validation.
  176. */
  177. #ifdef DEBUG
  178. # define VALIDATE_POINTER_ERR CE_Fatal
  179. #else
  180. # define VALIDATE_POINTER_ERR CE_Failure
  181. #endif
  182. #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && !defined(DOXYGEN_SKIP)
  183. extern "C++"
  184. {
  185. #include <string>
  186. class CPLErrorHandlerPusher
  187. {
  188. public:
  189. explicit CPLErrorHandlerPusher(CPLErrorHandler hHandler)
  190. {
  191. CPLPushErrorHandler(hHandler);
  192. }
  193. CPLErrorHandlerPusher(CPLErrorHandler hHandler, void* user_data)
  194. {
  195. CPLPushErrorHandlerEx(hHandler, user_data);
  196. }
  197. ~CPLErrorHandlerPusher()
  198. {
  199. CPLPopErrorHandler();
  200. }
  201. };
  202. class CPLErrorStateBackuper
  203. {
  204. CPLErrorNum m_nLastErrorNum;
  205. CPLErr m_nLastErrorType;
  206. std::string m_osLastErrorMsg;
  207. public:
  208. CPLErrorStateBackuper() :
  209. m_nLastErrorNum(CPLGetLastErrorNo()),
  210. m_nLastErrorType(CPLGetLastErrorType()),
  211. m_osLastErrorMsg(CPLGetLastErrorMsg())
  212. {}
  213. ~CPLErrorStateBackuper()
  214. {
  215. CPLErrorSetState(m_nLastErrorType, m_nLastErrorNum,
  216. m_osLastErrorMsg.c_str());
  217. }
  218. };
  219. }
  220. #ifdef GDAL_COMPILATION
  221. // internal only
  222. bool CPLIsDefaultErrorHandlerAndCatchDebug();
  223. #endif
  224. #endif
  225. /*! @endcond */
  226. /** Validate that a pointer is not NULL */
  227. #define VALIDATE_POINTER0(ptr, func) \
  228. do { if( CPL_NULLPTR == ptr ) \
  229. { \
  230. CPLErr const ret = VALIDATE_POINTER_ERR; \
  231. CPLError( ret, CPLE_ObjectNull, \
  232. "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
  233. return; }} while(0)
  234. /** Validate that a pointer is not NULL, and return rc if it is NULL */
  235. #define VALIDATE_POINTER1(ptr, func, rc) \
  236. do { if( CPL_NULLPTR == ptr ) \
  237. { \
  238. CPLErr const ret = VALIDATE_POINTER_ERR; \
  239. CPLError( ret, CPLE_ObjectNull, \
  240. "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
  241. return (rc); }} while(0)
  242. #endif /* CPL_ERROR_H_INCLUDED */
上海开阖软件有限公司 沪ICP备12045867号-1