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 6 // See http://www.boost.org/libs/test for the library home page. 7 // 8 // File : $RCSfile$ 9 // 10 // Version : $Revision: 49312 $ 11 // 12 // Description : defines exceptions and validation tools 13 // *************************************************************************** 14 15 #ifndef BOOST_RT_VALIDATION_HPP_062604GER 16 #define BOOST_RT_VALIDATION_HPP_062604GER 17 18 // Boost.Runtime.Parameter 19 #include <boost/test/utils/runtime/config.hpp> 20 21 // Boost.Test 22 #include <boost/test/utils/class_properties.hpp> 23 24 // Boost 25 #include <boost/shared_ptr.hpp> 26 27 // STL 28 #ifdef BOOST_RT_PARAM_EXCEPTION_INHERIT_STD 29 #include <stdexcept> 30 #endif 31 32 namespace boost { 33 34 namespace BOOST_RT_PARAM_NAMESPACE { 35 36 // ************************************************************************** // 37 // ************** runtime::logic_error ************** // 38 // ************************************************************************** // 39 40 class logic_error 41 #ifdef BOOST_RT_PARAM_EXCEPTION_INHERIT_STD 42 : public std::exception 43 #endif 44 { 45 typedef shared_ptr<dstring> dstring_ptr; 46 public: 47 // Constructor // !! could we eliminate shared_ptr logic_error(cstring msg)48 explicit logic_error( cstring msg ) : m_msg( new dstring( msg.begin(), msg.size() ) ) {} ~logic_error()49 ~logic_error() throw() {} 50 msg() const51 dstring const& msg() const { return *m_msg; } what() const52 virtual char_type const* what() const throw() { return m_msg->c_str(); } 53 54 private: 55 dstring_ptr m_msg; 56 }; 57 58 // ************************************************************************** // 59 // ************** runtime::report_logic_error ************** // 60 // ************************************************************************** // 61 62 inline void report_logic_error(format_stream & msg)63report_logic_error( format_stream& msg ) 64 { 65 throw BOOST_RT_PARAM_NAMESPACE::logic_error( msg.str() ); 66 } 67 68 //____________________________________________________________________________// 69 70 #define BOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg ) \ 71 boost::BOOST_RT_PARAM_NAMESPACE::report_logic_error( format_stream().ref() << msg ) 72 73 #define BOOST_RT_PARAM_VALIDATE_LOGIC( b, msg ) \ 74 if( b ) {} else BOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg ) 75 76 //____________________________________________________________________________// 77 78 } // namespace BOOST_RT_PARAM_NAMESPACE 79 80 } // namespace boost 81 82 #endif // BOOST_RT_VALIDATION_HPP_062604GER 83