1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | /// \file regex_error.hpp |
---|
3 | /// Contains the definition of the regex_error exception class. |
---|
4 | // |
---|
5 | // Copyright 2004 Eric Niebler. Distributed under the Boost |
---|
6 | // Software License, Version 1.0. (See accompanying file |
---|
7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
8 | |
---|
9 | #ifndef BOOST_XPRESSIVE_REGEX_ERROR_HPP_EAN_10_04_2005 |
---|
10 | #define BOOST_XPRESSIVE_REGEX_ERROR_HPP_EAN_10_04_2005 |
---|
11 | |
---|
12 | // MS compatible compilers support #pragma once |
---|
13 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
14 | # pragma once |
---|
15 | #endif |
---|
16 | |
---|
17 | #include <string> |
---|
18 | #include <stdexcept> |
---|
19 | #include <boost/xpressive/regex_constants.hpp> |
---|
20 | |
---|
21 | //{{AFX_DOC_COMMENT |
---|
22 | /////////////////////////////////////////////////////////////////////////////// |
---|
23 | // This is a hack to get Doxygen to show the inheritance relation between |
---|
24 | // regex_error and std::runtime_error. |
---|
25 | #ifdef BOOST_XPRESSIVE_DOXYGEN_INVOKED |
---|
26 | /// INTERNAL ONLY |
---|
27 | namespace std |
---|
28 | { |
---|
29 | /// INTERNAL ONLY |
---|
30 | struct runtime_error {}; |
---|
31 | } |
---|
32 | #endif |
---|
33 | //}}AFX_DOC_COMMENT |
---|
34 | |
---|
35 | namespace boost { namespace xpressive |
---|
36 | { |
---|
37 | |
---|
38 | //////////////////////////////////////////////////////////////////////////////// |
---|
39 | // regex_error |
---|
40 | // |
---|
41 | /// \brief The class regex_error defines the type of objects thrown as |
---|
42 | /// exceptions to report errors during the conversion from a string representing |
---|
43 | /// a regular expression to a finite state machine. |
---|
44 | struct regex_error |
---|
45 | : std::runtime_error |
---|
46 | { |
---|
47 | /// Constructs an object of class regex_error. |
---|
48 | /// \param code The error_type this regex_error represents. |
---|
49 | /// \post code() == code |
---|
50 | explicit regex_error(regex_constants::error_type code, char const *str = "") |
---|
51 | : std::runtime_error(str) |
---|
52 | , code_(code) |
---|
53 | { |
---|
54 | } |
---|
55 | |
---|
56 | /// Accessor for the error_type value |
---|
57 | /// \return the error_type code passed to the constructor |
---|
58 | /// \throw nothrow |
---|
59 | regex_constants::error_type code() const |
---|
60 | { |
---|
61 | return this->code_; |
---|
62 | } |
---|
63 | |
---|
64 | private: |
---|
65 | |
---|
66 | regex_constants::error_type code_; |
---|
67 | }; |
---|
68 | |
---|
69 | namespace detail |
---|
70 | { |
---|
71 | |
---|
72 | ////////////////////////////////////////////////////////////////////////// |
---|
73 | // ensure |
---|
74 | /// INTERNAL ONLY |
---|
75 | inline bool ensure(bool predicate, regex_constants::error_type code, char const *str = "") |
---|
76 | { |
---|
77 | return predicate ? true : throw regex_error(code, str); |
---|
78 | } |
---|
79 | |
---|
80 | }}} // namespace boost::xpressive::detail |
---|
81 | |
---|
82 | #endif |
---|