validation.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // (C) Copyright Gennadiy Rozental 2005-2008.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision: 49312 $
  10. //
  11. // Description : defines exceptions and validation tools
  12. // ***************************************************************************
  13. #ifndef BOOST_RT_VALIDATION_HPP_062604GER
  14. #define BOOST_RT_VALIDATION_HPP_062604GER
  15. // Boost.Runtime.Parameter
  16. #include <boost/test/utils/runtime/config.hpp>
  17. // Boost.Test
  18. #include <boost/test/utils/class_properties.hpp>
  19. // Boost
  20. #include <boost/shared_ptr.hpp>
  21. // STL
  22. #ifdef BOOST_RT_PARAM_EXCEPTION_INHERIT_STD
  23. #include <stdexcept>
  24. #endif
  25. namespace boost {
  26. namespace BOOST_RT_PARAM_NAMESPACE {
  27. // ************************************************************************** //
  28. // ************** runtime::logic_error ************** //
  29. // ************************************************************************** //
  30. class logic_error
  31. #ifdef BOOST_RT_PARAM_EXCEPTION_INHERIT_STD
  32. : public std::exception
  33. #endif
  34. {
  35. typedef shared_ptr<dstring> dstring_ptr;
  36. public:
  37. // Constructor // !! could we eliminate shared_ptr
  38. explicit logic_error( cstring msg ) : m_msg( new dstring( msg.begin(), msg.size() ) ) {}
  39. ~logic_error() throw() {}
  40. dstring const& msg() const { return *m_msg; }
  41. virtual char_type const* what() const throw() { return m_msg->c_str(); }
  42. private:
  43. dstring_ptr m_msg;
  44. };
  45. // ************************************************************************** //
  46. // ************** runtime::report_logic_error ************** //
  47. // ************************************************************************** //
  48. inline void
  49. report_logic_error( format_stream& msg )
  50. {
  51. throw BOOST_RT_PARAM_NAMESPACE::logic_error( msg.str() );
  52. }
  53. //____________________________________________________________________________//
  54. #define BOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg ) \
  55. boost::BOOST_RT_PARAM_NAMESPACE::report_logic_error( format_stream().ref() << msg )
  56. #define BOOST_RT_PARAM_VALIDATE_LOGIC( b, msg ) \
  57. if( b ) {} else BOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg )
  58. //____________________________________________________________________________//
  59. } // namespace BOOST_RT_PARAM_NAMESPACE
  60. } // namespace boost
  61. #endif // BOOST_RT_VALIDATION_HPP_062604GER