Newer
Older
snipet / kyscript / trunk / lib / nstdc / include / nstdc_assert.h
  1. /**
  2. * @file nstdc_assert.h
  3. * @brief アサーションを扱うヘッダーファイル
  4. * @author Nomura Kei
  5. * @copyright 2003 - 2017 Nomura Kei
  6. * License: New BSD License (3-cclause BSD license)
  7. */
  8. #ifndef NSTDC_ASSERT_H
  9. #define NSTDC_ASSERT_H
  10.  
  11. #include <stddef.h>
  12. #include <stdbool.h>
  13.  
  14. #include <config.h>
  15. #include <nstdc.h>
  16. #include <nstdc_compiler.h>
  17.  
  18.  
  19. #ifdef NSTDC_DEBUG
  20. #define nstdc_assert(val) nstdc_assert_( val , #val, __FILE__, __LINE__, __func__)
  21. #define nstdc_assert_num(v1, v2) nstdc_assert_num_(v1, v2, #v2 , __FILE__, __LINE__, __func__)
  22. #define nstdc_assert_str(v1, v2) nstdc_assert_str_(v1, v2, #v2 , __FILE__, __LINE__, __func__)
  23. #define nstdc_assert_mem(v1, v2, size) nstdc_assert_mem_(v1, v2, size, #v2 , __FILE__, __LINE__, __func__)
  24.  
  25. #else
  26. #define nstdc_assert(val) UNUSED_VARIABLE(val)
  27. #define nstdc_assert_num(v1, v2) UNUSED_VARIABLE(v1); UNUSED_VARIABLE(v2)
  28. #define nstdc_assert_str(v1, v2) UNUSED_VARIABLE(v1); UNUSED_VARIABLE(v2)
  29. #define nstdc_assert_mem(v1, v2, size) UNUSED_VARIABLE(v1); UNUSED_VARIABLE(v2); UNUED_VARIABLE(size)
  30.  
  31. #endif /* NSTDC_DEBUG */
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36.  
  37. typedef struct
  38. {
  39. /** 真偽判定時のアサーションエラー発生時に呼び出されるハンドラ関数. */
  40. void (*handler )(long val , const char* vname, const char* file, int line, const char* func);
  41.  
  42. /** 数値比較時のアサーションエラー発生時に呼び出されるハンドラ関数. */
  43. void (*handler_num)(long v1, long v2 , const char* vname, const char* file, int line, const char* func);
  44.  
  45. /** 文字列比較時のアサーションエラー発生時に呼び出されるハンドラ関数. */
  46. void (*handler_str)(const char* v1, const char* v2 , const char* vname, const char* file, int line, const char* func);
  47.  
  48. /** メモリ比較時のアサーションエラー発生時に呼び出されるハンドラ関数. */
  49. void (*handler_mem)(const void* v1, const void* v2, size_t size, const char* vname, const char* file, int line, const char* func);
  50.  
  51. /**
  52. * アサーションの前処理として呼び出されるハンドラ関数.
  53. * @param is_error true/false (アサーションエラー発生/エラーなし)
  54. */
  55. void (*handler_bef)(bool is_error);
  56.  
  57. /**
  58. * アサーションの後処理として呼び出されるハンドラ関数.
  59. * @param is_error true/false (アサーションエラー発生/エラーなし)
  60. */
  61. void (*handler_aft)(bool is_error);
  62.  
  63. } NstdcAssertHandlers;
  64.  
  65. void nstdc_assert_ ( long val , const char* vname, const char* file, int line, const char* func);
  66. void nstdc_assert_num_( long v1, long v2 , const char* vname, const char* file, int line, const char* func);
  67. void nstdc_assert_str_( const char* v1, const char* v2 , const char* vname, const char* file, int line, const char* func);
  68. void nstdc_assert_mem_( const char* v1, const char* v2, size_t size, const char* vname, const char* file, int line, const char* func);
  69. void nstdc_assert_set_handlers(NstdcAssertHandlers* handlers);
  70.  
  71.  
  72. #ifdef __cplusplus
  73. }
  74. #endif
  75.  
  76. #endif /* NSTDC_ASSERT_H */
  77.