Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Boost.Wave: A Standard compliant C++ preprocessor library
|
Chris@16
|
3
|
Chris@16
|
4 http://www.boost.org/
|
Chris@16
|
5
|
Chris@16
|
6 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
|
Chris@16
|
7 Software License, Version 1.0. (See accompanying file
|
Chris@16
|
8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 =============================================================================*/
|
Chris@16
|
10
|
Chris@16
|
11 #if !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)
|
Chris@16
|
12 #define BOOST_WAVE_CPP_THROW_HPP_INCLUDED
|
Chris@16
|
13
|
Chris@16
|
14 #include <string>
|
Chris@16
|
15 #include <boost/throw_exception.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 #ifdef BOOST_NO_STRINGSTREAM
|
Chris@16
|
18 #include <strstream>
|
Chris@16
|
19 #else
|
Chris@16
|
20 #include <sstream>
|
Chris@16
|
21 #endif
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost { namespace wave { namespace util
|
Chris@16
|
24 {
|
Chris@16
|
25 #ifdef BOOST_NO_STRINGSTREAM
|
Chris@16
|
26 template <typename Exception, typename S1, typename Pos>
|
Chris@16
|
27 void throw_(typename Exception::error_code code, S1 msg, Pos const& pos)
|
Chris@16
|
28 {
|
Chris@16
|
29 std::strstream stream;
|
Chris@16
|
30 stream << Exception::severity_text(code) << ": "
|
Chris@16
|
31 << Exception::error_text(code);
|
Chris@16
|
32 if (msg[0] != 0)
|
Chris@16
|
33 stream << ": " << msg;
|
Chris@16
|
34 stream << std::ends;
|
Chris@16
|
35 std::string throwmsg = stream.str(); stream.freeze(false);
|
Chris@16
|
36 boost::throw_exception(Exception(throwmsg.c_str(), code,
|
Chris@16
|
37 pos.get_line(), pos.get_column(), pos.get_file().c_str()));
|
Chris@16
|
38 }
|
Chris@16
|
39
|
Chris@16
|
40 template <typename Exception, typename Context, typename S1, typename Pos>
|
Chris@16
|
41 void throw_(Context& ctx, typename Exception::error_code code,
|
Chris@16
|
42 S1 msg, Pos const& pos)
|
Chris@16
|
43 {
|
Chris@16
|
44 std::strstream stream;
|
Chris@16
|
45 stream << Exception::severity_text(code) << ": "
|
Chris@16
|
46 << Exception::error_text(code);
|
Chris@16
|
47 if (msg[0] != 0)
|
Chris@16
|
48 stream << ": " << msg;
|
Chris@16
|
49 stream << std::ends;
|
Chris@16
|
50 std::string throwmsg = stream.str(); stream.freeze(false);
|
Chris@16
|
51 ctx.get_hooks().throw_exception(ctx.derived(),
|
Chris@16
|
52 Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
|
Chris@16
|
53 pos.get_file().c_str()));
|
Chris@16
|
54 }
|
Chris@16
|
55
|
Chris@16
|
56 template <typename Exception, typename S1, typename Pos, typename S2>
|
Chris@16
|
57 void throw_(typename Exception::error_code code, S1 msg, Pos const& pos,
|
Chris@16
|
58 S2 name)
|
Chris@16
|
59 {
|
Chris@16
|
60 std::strstream stream;
|
Chris@16
|
61 stream << Exception::severity_text(code) << ": "
|
Chris@16
|
62 << Exception::error_text(code);
|
Chris@16
|
63 if (msg[0] != 0)
|
Chris@16
|
64 stream << ": " << msg;
|
Chris@16
|
65 stream << std::ends;
|
Chris@16
|
66 std::string throwmsg = stream.str(); stream.freeze(false);
|
Chris@16
|
67 boost::throw_exception(Exception(throwmsg.c_str(), code,
|
Chris@16
|
68 pos.get_line(), pos.get_column(), pos.get_file().c_str(), name));
|
Chris@16
|
69 }
|
Chris@16
|
70
|
Chris@16
|
71 template <typename Exception, typename Context, typename S1, typename Pos,
|
Chris@16
|
72 typename S2>
|
Chris@16
|
73 void throw_(Context& ctx, typename Exception::error_code code,
|
Chris@16
|
74 S1 msg, Pos const& pos, S2 name)
|
Chris@16
|
75 {
|
Chris@16
|
76 std::strstream stream;
|
Chris@16
|
77 stream << Exception::severity_text(code) << ": "
|
Chris@16
|
78 << Exception::error_text(code);
|
Chris@16
|
79 if (msg[0] != 0)
|
Chris@16
|
80 stream << ": " << msg;
|
Chris@16
|
81 stream << std::ends;
|
Chris@16
|
82 std::string throwmsg = stream.str(); stream.freeze(false);
|
Chris@16
|
83 ctx.get_hooks().throw_exception(ctx.derived(),
|
Chris@16
|
84 Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
|
Chris@16
|
85 pos.get_file().c_str(), name));
|
Chris@16
|
86 }
|
Chris@16
|
87 #else
|
Chris@16
|
88 template <typename Exception, typename S1, typename Pos>
|
Chris@16
|
89 void throw_(typename Exception::error_code code, S1 msg, Pos const& pos)
|
Chris@16
|
90 {
|
Chris@16
|
91 std::stringstream stream;
|
Chris@16
|
92 stream << Exception::severity_text(code) << ": "
|
Chris@16
|
93 << Exception::error_text(code);
|
Chris@16
|
94 if (msg[0] != 0)
|
Chris@16
|
95 stream << ": " << msg;
|
Chris@16
|
96 stream << std::ends;
|
Chris@16
|
97 std::string throwmsg = stream.str();
|
Chris@16
|
98 boost::throw_exception(Exception(throwmsg.c_str(), code,
|
Chris@16
|
99 pos.get_line(), pos.get_column(), pos.get_file().c_str()));
|
Chris@16
|
100 }
|
Chris@16
|
101
|
Chris@16
|
102 template <typename Exception, typename Context, typename S1, typename Pos>
|
Chris@16
|
103 void throw_(Context& ctx, typename Exception::error_code code,
|
Chris@16
|
104 S1 msg, Pos const& pos)
|
Chris@16
|
105 {
|
Chris@16
|
106 std::stringstream stream;
|
Chris@16
|
107 stream << Exception::severity_text(code) << ": "
|
Chris@16
|
108 << Exception::error_text(code);
|
Chris@16
|
109 if (msg[0] != 0)
|
Chris@16
|
110 stream << ": " << msg;
|
Chris@16
|
111 stream << std::ends;
|
Chris@16
|
112 std::string throwmsg = stream.str();
|
Chris@16
|
113 ctx.get_hooks().throw_exception(ctx.derived(),
|
Chris@16
|
114 Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
|
Chris@16
|
115 pos.get_file().c_str()));
|
Chris@16
|
116 }
|
Chris@16
|
117
|
Chris@16
|
118 template <typename Exception, typename S1, typename Pos, typename S2>
|
Chris@16
|
119 void throw_(typename Exception::error_code code, S1 msg, Pos const& pos,
|
Chris@16
|
120 S2 name)
|
Chris@16
|
121 {
|
Chris@16
|
122 std::stringstream stream;
|
Chris@16
|
123 stream << Exception::severity_text(code) << ": "
|
Chris@16
|
124 << Exception::error_text(code);
|
Chris@16
|
125 if (msg[0] != 0)
|
Chris@16
|
126 stream << ": " << msg;
|
Chris@16
|
127 stream << std::ends;
|
Chris@16
|
128 std::string throwmsg = stream.str();
|
Chris@16
|
129 boost::throw_exception(Exception(throwmsg.c_str(), code,
|
Chris@16
|
130 pos.get_line(), pos.get_column(), pos.get_file().c_str(), name));
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 template <typename Exception, typename Context, typename S1, typename Pos1,
|
Chris@16
|
134 typename S2>
|
Chris@16
|
135 void throw_(Context& ctx, typename Exception::error_code code,
|
Chris@16
|
136 S1 msg, Pos1 const& pos, S2 name)
|
Chris@16
|
137 {
|
Chris@16
|
138 std::stringstream stream;
|
Chris@16
|
139 stream << Exception::severity_text(code) << ": "
|
Chris@16
|
140 << Exception::error_text(code);
|
Chris@16
|
141 if (msg[0] != 0)
|
Chris@16
|
142 stream << ": " << msg;
|
Chris@16
|
143 stream << std::ends;
|
Chris@16
|
144 std::string throwmsg = stream.str();
|
Chris@16
|
145 ctx.get_hooks().throw_exception(ctx.derived(),
|
Chris@16
|
146 Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
|
Chris@16
|
147 pos.get_file().c_str(), name));
|
Chris@16
|
148 }
|
Chris@16
|
149 #endif
|
Chris@16
|
150 }}}
|
Chris@16
|
151
|
Chris@16
|
152 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
153 // helper macro for throwing exceptions
|
Chris@16
|
154 #if !defined(BOOST_WAVE_THROW)
|
Chris@16
|
155 #define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
|
Chris@16
|
156 boost::wave::util::throw_<cls>(cls::code, msg, act_pos) \
|
Chris@16
|
157 /**/
|
Chris@16
|
158
|
Chris@16
|
159 #define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \
|
Chris@16
|
160 boost::wave::util::throw_<cls>(ctx, cls::code, msg, act_pos) \
|
Chris@16
|
161 /**/
|
Chris@16
|
162 #endif // BOOST_WAVE_THROW
|
Chris@16
|
163
|
Chris@16
|
164 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
165 // helper macro for throwing exceptions with additional parameter
|
Chris@16
|
166 #if !defined(BOOST_WAVE_THROW_NAME_CTX)
|
Chris@16
|
167 #define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name) \
|
Chris@16
|
168 boost::wave::util::throw_<cls>(cls::code, msg, act_pos, name) \
|
Chris@16
|
169 /**/
|
Chris@16
|
170 #endif // BOOST_WAVE_THROW_NAME_CTX
|
Chris@16
|
171
|
Chris@16
|
172 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
173 // helper macro for throwing exceptions with additional parameter
|
Chris@16
|
174 #if !defined(BOOST_WAVE_THROW_VAR_CTX)
|
Chris@16
|
175 #define BOOST_WAVE_THROW_VAR_CTX(ctx, cls, code, msg, act_pos) \
|
Chris@16
|
176 boost::wave::util::throw_<cls>(ctx, code, msg, act_pos) \
|
Chris@16
|
177 /**/
|
Chris@16
|
178 #endif // BOOST_WAVE_THROW_VAR_CTX
|
Chris@16
|
179
|
Chris@16
|
180 #endif // !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)
|