Chris@16: // (C) Copyright Gennadiy Rozental 2005-2008. Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org/libs/test for the library home page. Chris@16: // Chris@16: // File : $RCSfile$ Chris@16: // Chris@101: // Version : $Revision$ Chris@16: // Chris@16: // Description : defines exceptions and validation tools Chris@16: // *************************************************************************** Chris@16: Chris@16: #ifndef BOOST_RT_VALIDATION_HPP_062604GER Chris@16: #define BOOST_RT_VALIDATION_HPP_062604GER Chris@16: Chris@16: // Boost.Runtime.Parameter Chris@16: #include Chris@16: Chris@16: // Boost.Test Chris@16: #include Chris@16: Chris@16: // Boost Chris@16: #include Chris@16: Chris@16: // STL Chris@16: #ifdef BOOST_RT_PARAM_EXCEPTION_INHERIT_STD Chris@16: #include Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: namespace BOOST_RT_PARAM_NAMESPACE { Chris@16: Chris@16: // ************************************************************************** // Chris@16: // ************** runtime::logic_error ************** // Chris@16: // ************************************************************************** // Chris@16: Chris@16: class logic_error Chris@16: #ifdef BOOST_RT_PARAM_EXCEPTION_INHERIT_STD Chris@16: : public std::exception Chris@16: #endif Chris@16: { Chris@16: typedef shared_ptr dstring_ptr; Chris@16: public: Chris@16: // Constructor // !! could we eliminate shared_ptr Chris@16: explicit logic_error( cstring msg ) : m_msg( new dstring( msg.begin(), msg.size() ) ) {} Chris@16: ~logic_error() throw() {} Chris@16: Chris@16: dstring const& msg() const { return *m_msg; } Chris@16: virtual char_type const* what() const throw() { return m_msg->c_str(); } Chris@16: Chris@16: private: Chris@16: dstring_ptr m_msg; Chris@16: }; Chris@16: Chris@16: // ************************************************************************** // Chris@16: // ************** runtime::report_logic_error ************** // Chris@16: // ************************************************************************** // Chris@16: Chris@16: inline void Chris@16: report_logic_error( format_stream& msg ) Chris@16: { Chris@16: throw BOOST_RT_PARAM_NAMESPACE::logic_error( msg.str() ); Chris@16: } Chris@16: Chris@16: //____________________________________________________________________________// Chris@16: Chris@16: #define BOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg ) \ Chris@16: boost::BOOST_RT_PARAM_NAMESPACE::report_logic_error( format_stream().ref() << msg ) Chris@16: Chris@16: #define BOOST_RT_PARAM_VALIDATE_LOGIC( b, msg ) \ Chris@16: if( b ) {} else BOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg ) Chris@16: Chris@16: //____________________________________________________________________________// Chris@16: Chris@16: } // namespace BOOST_RT_PARAM_NAMESPACE Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_RT_VALIDATION_HPP_062604GER