blob: e794df96b77ae720438a9a0cee86adb90569fa4c [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (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 <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
28#ifdef BOOST_RT_PARAM_EXCEPTION_INHERIT_STD
29#include <stdexcept>
30#endif
31
32namespace ndnboost {
33
34namespace BOOST_RT_PARAM_NAMESPACE {
35
36// ************************************************************************** //
37// ************** runtime::logic_error ************** //
38// ************************************************************************** //
39
40class logic_error
41#ifdef BOOST_RT_PARAM_EXCEPTION_INHERIT_STD
42: public std::exception
43#endif
44{
45 typedef shared_ptr<dstring> dstring_ptr;
46public:
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
54private:
55 dstring_ptr m_msg;
56};
57
58// ************************************************************************** //
59// ************** runtime::report_logic_error ************** //
60// ************************************************************************** //
61
62inline void
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 ndnboost::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 ndnboost
81
82#endif // BOOST_RT_VALIDATION_HPP_062604GER