Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 /// \file regex_error.hpp
|
Chris@16
|
3 /// Contains the definition of the regex_error exception class.
|
Chris@16
|
4 //
|
Chris@16
|
5 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
6 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
7 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 #ifndef BOOST_XPRESSIVE_REGEX_ERROR_HPP_EAN_10_04_2005
|
Chris@16
|
10 #define BOOST_XPRESSIVE_REGEX_ERROR_HPP_EAN_10_04_2005
|
Chris@16
|
11
|
Chris@16
|
12 // MS compatible compilers support #pragma once
|
Chris@101
|
13 #if defined(_MSC_VER)
|
Chris@16
|
14 # pragma once
|
Chris@16
|
15 #endif
|
Chris@16
|
16
|
Chris@16
|
17 #include <string>
|
Chris@16
|
18 #include <stdexcept>
|
Chris@16
|
19 #include <boost/throw_exception.hpp>
|
Chris@16
|
20 #include <boost/current_function.hpp>
|
Chris@16
|
21 #include <boost/exception/exception.hpp>
|
Chris@16
|
22 #include <boost/exception/info.hpp>
|
Chris@16
|
23 #include <boost/xpressive/regex_constants.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 //{{AFX_DOC_COMMENT
|
Chris@16
|
26 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
27 // This is a hack to get Doxygen to show the inheritance relation between
|
Chris@16
|
28 // regex_error and std::runtime_error.
|
Chris@16
|
29 #ifdef BOOST_XPRESSIVE_DOXYGEN_INVOKED
|
Chris@16
|
30 /// INTERNAL ONLY
|
Chris@16
|
31 namespace std
|
Chris@16
|
32 {
|
Chris@16
|
33 /// INTERNAL ONLY
|
Chris@16
|
34 struct runtime_error {};
|
Chris@16
|
35 }
|
Chris@16
|
36 #endif
|
Chris@16
|
37 //}}AFX_DOC_COMMENT
|
Chris@16
|
38
|
Chris@16
|
39 namespace boost { namespace xpressive
|
Chris@16
|
40 {
|
Chris@16
|
41
|
Chris@16
|
42 ////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
43 // regex_error
|
Chris@16
|
44 //
|
Chris@16
|
45 /// \brief The class regex_error defines the type of objects thrown as
|
Chris@16
|
46 /// exceptions to report errors during the conversion from a string representing
|
Chris@16
|
47 /// a regular expression to a finite state machine.
|
Chris@16
|
48 struct regex_error
|
Chris@16
|
49 : std::runtime_error
|
Chris@16
|
50 , boost::exception
|
Chris@16
|
51 {
|
Chris@16
|
52 /// Constructs an object of class regex_error.
|
Chris@16
|
53 /// \param code The error_type this regex_error represents.
|
Chris@16
|
54 /// \param str The message string of this regex_error.
|
Chris@16
|
55 /// \post code() == code
|
Chris@16
|
56 explicit regex_error(regex_constants::error_type code, char const *str = "")
|
Chris@16
|
57 : std::runtime_error(str)
|
Chris@16
|
58 , boost::exception()
|
Chris@16
|
59 , code_(code)
|
Chris@16
|
60 {
|
Chris@16
|
61 }
|
Chris@16
|
62
|
Chris@16
|
63 /// Accessor for the error_type value
|
Chris@16
|
64 /// \return the error_type code passed to the constructor
|
Chris@16
|
65 /// \throw nothrow
|
Chris@16
|
66 regex_constants::error_type code() const
|
Chris@16
|
67 {
|
Chris@16
|
68 return this->code_;
|
Chris@16
|
69 }
|
Chris@16
|
70
|
Chris@16
|
71 /// Destructor for class regex_error
|
Chris@16
|
72 /// \throw nothrow
|
Chris@16
|
73 virtual ~regex_error() throw()
|
Chris@16
|
74 {}
|
Chris@16
|
75
|
Chris@16
|
76 private:
|
Chris@16
|
77
|
Chris@16
|
78 regex_constants::error_type code_;
|
Chris@16
|
79 };
|
Chris@16
|
80
|
Chris@16
|
81 namespace detail
|
Chris@16
|
82 {
|
Chris@16
|
83 inline bool ensure_(
|
Chris@16
|
84 bool cond
|
Chris@16
|
85 , regex_constants::error_type code
|
Chris@16
|
86 , char const *msg
|
Chris@16
|
87 , char const *fun
|
Chris@16
|
88 , char const *file
|
Chris@16
|
89 , unsigned long line
|
Chris@16
|
90 )
|
Chris@16
|
91 {
|
Chris@16
|
92 if(!cond)
|
Chris@16
|
93 {
|
Chris@16
|
94 #ifndef BOOST_EXCEPTION_DISABLE
|
Chris@16
|
95 boost::throw_exception(
|
Chris@16
|
96 boost::xpressive::regex_error(code, msg)
|
Chris@16
|
97 << boost::throw_function(fun)
|
Chris@16
|
98 << boost::throw_file(file)
|
Chris@16
|
99 << boost::throw_line((int)line)
|
Chris@16
|
100 );
|
Chris@16
|
101 #else
|
Chris@16
|
102 boost::throw_exception(boost::xpressive::regex_error(code, msg));
|
Chris@16
|
103 #endif
|
Chris@16
|
104 }
|
Chris@16
|
105 return true;
|
Chris@16
|
106 }
|
Chris@16
|
107 }
|
Chris@16
|
108
|
Chris@16
|
109 #define BOOST_XPR_ENSURE_(pred, code, msg) \
|
Chris@16
|
110 boost::xpressive::detail::ensure_(!!(pred), code, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__) \
|
Chris@16
|
111 /**/
|
Chris@16
|
112
|
Chris@16
|
113 }} // namespace boost::xpressive
|
Chris@16
|
114
|
Chris@16
|
115 #endif
|