blob: 9c8ce79f96c30101fcf707b38b7f634d5a11cf28 [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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_RT_VALIDATION_HPP_062604GER
16#define NDNBOOST_RT_VALIDATION_HPP_062604GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
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 Thompson3d613fd2013-10-15 15:39:04 -070028#ifdef NDNBOOST_RT_PARAM_EXCEPTION_INHERIT_STD
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070029#include <stdexcept>
30#endif
31
32namespace ndnboost {
33
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034namespace NDNBOOST_RT_PARAM_NAMESPACE {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070035
36// ************************************************************************** //
37// ************** runtime::logic_error ************** //
38// ************************************************************************** //
39
40class logic_error
Jeff Thompson3d613fd2013-10-15 15:39:04 -070041#ifdef NDNBOOST_RT_PARAM_EXCEPTION_INHERIT_STD
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070042: 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{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070065 throw NDNBOOST_RT_PARAM_NAMESPACE::logic_error( msg.str() );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070066}
67
68//____________________________________________________________________________//
69
Jeff Thompson3d613fd2013-10-15 15:39:04 -070070#define NDNBOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg ) \
71 ndnboost::NDNBOOST_RT_PARAM_NAMESPACE::report_logic_error( format_stream().ref() << msg )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070072
Jeff Thompson3d613fd2013-10-15 15:39:04 -070073#define NDNBOOST_RT_PARAM_VALIDATE_LOGIC( b, msg ) \
74 if( b ) {} else NDNBOOST_RT_PARAM_REPORT_LOGIC_ERROR( msg )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070075
76//____________________________________________________________________________//
77
Jeff Thompson3d613fd2013-10-15 15:39:04 -070078} // namespace NDNBOOST_RT_PARAM_NAMESPACE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070079
80} // namespace ndnboost
81
Jeff Thompson3d613fd2013-10-15 15:39:04 -070082#endif // NDNBOOST_RT_VALIDATION_HPP_062604GER