Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 15 | #ifndef NDNBOOST_RT_VALIDATION_HPP_062604GER |
| 16 | #define NDNBOOST_RT_VALIDATION_HPP_062604GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | |
| 18 | // Boost.Runtime.Parameter |
| 19 | #include <ndnboost/test/utils/runtime/config.hpp> |
| 20 | |
| 21 | // Boost.Test |
| 22 | #include <ndnboost/test/utils/class_properties.hpp> |
| 23 | |
| 24 | // Boost |
| 25 | #include <ndnboost/shared_ptr.hpp> |
| 26 | |
| 27 | // STL |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 28 | #ifdef NDNBOOST_RT_PARAM_EXCEPTION_INHERIT_STD |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 29 | #include <stdexcept> |
| 30 | #endif |
| 31 | |
| 32 | namespace ndnboost { |
| 33 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 34 | namespace NDNBOOST_RT_PARAM_NAMESPACE { |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 35 | |
| 36 | // ************************************************************************** // |
| 37 | // ************** runtime::logic_error ************** // |
| 38 | // ************************************************************************** // |
| 39 | |
| 40 | class logic_error |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 41 | #ifdef NDNBOOST_RT_PARAM_EXCEPTION_INHERIT_STD |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 42 | : public std::exception |
| 43 | #endif |
| 44 | { |
| 45 | typedef shared_ptr<dstring> dstring_ptr; |
| 46 | public: |
| 47 | // Constructor // !! could we eliminate shared_ptr |
| 48 | explicit logic_error( cstring msg ) : m_msg( new dstring( msg.begin(), msg.size() ) ) {} |
| 49 | ~logic_error() throw() {} |
| 50 | |
| 51 | dstring const& msg() const { return *m_msg; } |
| 52 | 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 |
| 63 | report_logic_error( format_stream& msg ) |
| 64 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 65 | throw NDNBOOST_RT_PARAM_NAMESPACE::logic_error( msg.str() ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | //____________________________________________________________________________// |
| 69 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 70 | #define NDNBOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg ) \ |
| 71 | ndnboost::NDNBOOST_RT_PARAM_NAMESPACE::report_logic_error( format_stream().ref() << msg ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 72 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 73 | #define NDNBOOST_RT_PARAM_VALIDATE_LOGIC( b, msg ) \ |
| 74 | if( b ) {} else NDNBOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 75 | |
| 76 | //____________________________________________________________________________// |
| 77 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 78 | } // namespace NDNBOOST_RT_PARAM_NAMESPACE |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 79 | |
| 80 | } // namespace ndnboost |
| 81 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 82 | #endif // NDNBOOST_RT_VALIDATION_HPP_062604GER |