Assert.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // "$Id$"
  3. //
  4. // Copyright (c)1992-2011, ZheJiang Dahua Technology Stock CO.LTD.
  5. // All Rights Reserved.
  6. //
  7. // Description:
  8. // Revisions: Year-Month-Day SVN-Author Modification
  9. //
  10. /// \file: Dahua/Assert.h
  11. ///
  12. /// \brief 提供三个断言宏:
  13. /// DAHUA_ASSERT(expr)
  14. /// DAHAU_ASSERT_MSG(expr, msg)
  15. /// DAHUA_VERIFY(expr)
  16. ///
  17. #ifndef DAHUA_CURRENT_FUNCTION_INCLUDED
  18. #define DAHUA_CURRENT_FUNCTION_INCLUDED
  19. #include "Defs.h"
  20. namespace Dahua {
  21. namespace Infra {
  22. namespace Detail {
  23. /// 断言失败处理函数
  24. INFRA_API void assertionFailed(char const * expr, char const * function, char const * file, long line);
  25. /// 断言失败处理函数
  26. INFRA_API void assertionFailedMsg(char const * expr, char const * msg, char const * function, char const * file, long line);
  27. inline void current_function_helper()
  28. {
  29. #if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600))
  30. # define DAHUA_CURRENT_FUNCTION __PRETTY_FUNCTION__
  31. #elif defined(__DMC__) && (__DMC__ >= 0x810)
  32. # define DAHUA_CURRENT_FUNCTION __PRETTY_FUNCTION__
  33. #elif defined(__FUNCSIG__)
  34. # define DAHUA_CURRENT_FUNCTION __FUNCSIG__
  35. #elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
  36. # define DAHUA_CURRENT_FUNCTION __FUNCTION__
  37. #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
  38. # define DAHUA_CURRENT_FUNCTION __FUNC__
  39. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
  40. # define DAHUA_CURRENT_FUNCTION __func__
  41. #else
  42. # define DAHUA_CURRENT_FUNCTION "(unknown)"
  43. #endif
  44. }
  45. } // namespace Detail
  46. } // namespace Infra
  47. } // namespace Dahua
  48. #endif // DAHUA_CURRENT_FUNCTION_INCLUDED
  49. //--------------------------------------------------------------------------------------//
  50. // DAHUA_ASSERT //
  51. //--------------------------------------------------------------------------------------//
  52. #undef DAHUA_ASSERT
  53. #if defined(NDEBUG)
  54. # define DAHUA_ASSERT(expr) ((void)0)
  55. #else
  56. #define DAHUA_ASSERT(expr) ((expr) \
  57. ? ((void)0) \
  58. : ::Dahua::Infra::Detail::assertionFailed(#expr, DAHUA_CURRENT_FUNCTION, __FILE__, __LINE__))
  59. #endif
  60. //--------------------------------------------------------------------------------------//
  61. // DAHUA_ASSERT_MSG //
  62. //--------------------------------------------------------------------------------------//
  63. # undef DAHUA_ASSERT_MSG
  64. #if defined(NDEBUG)
  65. #define DAHUA_ASSERT_MSG(expr, msg) ((void)0)
  66. #else
  67. #define DAHUA_ASSERT_MSG(expr, msg) ((expr) \
  68. ? ((void)0) \
  69. : ::Dahua::Infra::Detail::assertionFailedMsg(#expr, msg, DAHUA_CURRENT_FUNCTION, __FILE__, __LINE__))
  70. #endif
  71. //--------------------------------------------------------------------------------------//
  72. // DAHUA_VERIFY //
  73. //--------------------------------------------------------------------------------------//
  74. #undef DAHUA_VERIFY
  75. #if defined(NDEBUG)
  76. # define DAHUA_VERIFY(expr) ((void)(expr))
  77. #else
  78. # define DAHUA_VERIFY(expr) DAHUA_ASSERT(expr)
  79. #endif