/Src/Dependencies/Boost/boost/assert.hpp

http://hadesmem.googlecode.com/ · C++ Header · 131 lines · 69 code · 29 blank · 33 comment · 3 complexity · 6d51492f59a39ddd76f6edf7b5ce4ee7 MD5 · raw file

  1. //
  2. // boost/assert.hpp - BOOST_ASSERT(expr)
  3. // BOOST_ASSERT_MSG(expr, msg)
  4. // BOOST_VERIFY(expr)
  5. //
  6. // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
  7. // Copyright (c) 2007 Peter Dimov
  8. // Copyright (c) Beman Dawes 2011
  9. //
  10. // Distributed under the Boost Software License, Version 1.0. (See
  11. // accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. //
  14. // Note: There are no include guards. This is intentional.
  15. //
  16. // See http://www.boost.org/libs/utility/assert.html for documentation.
  17. //
  18. //
  19. // Stop inspect complaining about use of 'assert':
  20. //
  21. // boostinspect:naassert_macro
  22. //
  23. //--------------------------------------------------------------------------------------//
  24. // BOOST_ASSERT //
  25. //--------------------------------------------------------------------------------------//
  26. #undef BOOST_ASSERT
  27. #if defined(BOOST_DISABLE_ASSERTS)
  28. # define BOOST_ASSERT(expr) ((void)0)
  29. #elif defined(BOOST_ENABLE_ASSERT_HANDLER)
  30. #include <boost/current_function.hpp>
  31. namespace boost
  32. {
  33. void assertion_failed(char const * expr,
  34. char const * function, char const * file, long line); // user defined
  35. } // namespace boost
  36. #define BOOST_ASSERT(expr) ((expr) \
  37. ? ((void)0) \
  38. : ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
  39. #else
  40. # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
  41. # define BOOST_ASSERT(expr) assert(expr)
  42. #endif
  43. //--------------------------------------------------------------------------------------//
  44. // BOOST_ASSERT_MSG //
  45. //--------------------------------------------------------------------------------------//
  46. # undef BOOST_ASSERT_MSG
  47. #if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
  48. #define BOOST_ASSERT_MSG(expr, msg) ((void)0)
  49. #elif defined(BOOST_ENABLE_ASSERT_HANDLER)
  50. #include <boost/current_function.hpp>
  51. namespace boost
  52. {
  53. void assertion_failed_msg(char const * expr, char const * msg,
  54. char const * function, char const * file, long line); // user defined
  55. } // namespace boost
  56. #define BOOST_ASSERT_MSG(expr, msg) ((expr) \
  57. ? ((void)0) \
  58. : ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
  59. #else
  60. #ifndef BOOST_ASSERT_HPP
  61. #define BOOST_ASSERT_HPP
  62. #include <cstdlib>
  63. #include <iostream>
  64. #include <boost/current_function.hpp>
  65. // IDE's like Visual Studio perform better if output goes to std::cout or
  66. // some other stream, so allow user to configure output stream:
  67. #ifndef BOOST_ASSERT_MSG_OSTREAM
  68. # define BOOST_ASSERT_MSG_OSTREAM std::cerr
  69. #endif
  70. namespace boost
  71. {
  72. namespace assertion
  73. {
  74. namespace detail
  75. {
  76. inline void assertion_failed_msg(char const * expr, char const * msg, char const * function,
  77. char const * file, long line)
  78. {
  79. BOOST_ASSERT_MSG_OSTREAM
  80. << "***** Internal Program Error - assertion (" << expr << ") failed in "
  81. << function << ":\n"
  82. << file << '(' << line << "): " << msg << std::endl;
  83. std::abort();
  84. }
  85. } // detail
  86. } // assertion
  87. } // detail
  88. #endif
  89. #define BOOST_ASSERT_MSG(expr, msg) ((expr) \
  90. ? ((void)0) \
  91. : ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \
  92. BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
  93. #endif
  94. //--------------------------------------------------------------------------------------//
  95. // BOOST_VERIFY //
  96. //--------------------------------------------------------------------------------------//
  97. #undef BOOST_VERIFY
  98. #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )
  99. # define BOOST_VERIFY(expr) ((void)(expr))
  100. #else
  101. # define BOOST_VERIFY(expr) BOOST_ASSERT(expr)
  102. #endif