assert.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*=============================================================================
  2. Copyright (c) 2001-2003 Joel de Guzman
  3. Copyright (c) 2002-2003 Hartmut Kaiser
  4. http://spirit.sourceforge.net/
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_SPIRIT_ASSERT_HPP)
  9. #define BOOST_SPIRIT_ASSERT_HPP
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //
  12. // BOOST_SPIRIT_ASSERT is used throughout the framework. It can be
  13. // overridden by the user. If BOOST_SPIRIT_ASSERT_EXCEPTION is defined,
  14. // then that will be thrown, otherwise, BOOST_SPIRIT_ASSERT simply turns
  15. // into a plain BOOST_ASSERT()
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #if !defined(BOOST_SPIRIT_ASSERT)
  19. #if defined(NDEBUG)
  20. #define BOOST_SPIRIT_ASSERT(x)
  21. #elif defined (BOOST_SPIRIT_ASSERT_EXCEPTION)
  22. #include <boost/throw_exception.hpp>
  23. #define BOOST_SPIRIT_ASSERT_AUX(f, l, x) BOOST_SPIRIT_ASSERT_AUX2(f, l, x)
  24. #define BOOST_SPIRIT_ASSERT_AUX2(f, l, x) \
  25. ( (x) ? (void)0 : boost::throw_exception( \
  26. BOOST_SPIRIT_ASSERT_EXCEPTION(f "(" #l "): " #x)) )
  27. #define BOOST_SPIRIT_ASSERT(x) BOOST_SPIRIT_ASSERT_AUX(__FILE__, __LINE__, x)
  28. #else
  29. #include <boost/assert.hpp>
  30. #define BOOST_SPIRIT_ASSERT(x) BOOST_ASSERT(x)
  31. #endif
  32. #endif // !defined(BOOST_SPIRIT_ASSERT)
  33. #endif // BOOST_SPIRIT_ASSERT_HPP