summaryrefslogtreecommitdiff
path: root/boost/wave/cpp_throw.hpp
blob: dbbd85865f7cb79d2c64f82c8645c2bd77a6e3d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*=============================================================================
    Boost.Wave: A Standard compliant C++ preprocessor library

    http://www.boost.org/

    Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
    Software License, Version 1.0. (See accompanying file
    LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#if !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)
#define BOOST_WAVE_CPP_THROW_HPP_INCLUDED

#include <string>
#include <boost/throw_exception.hpp>

#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>
#else
#include <sstream>
#endif

namespace boost { namespace wave { namespace util
{
#ifdef BOOST_NO_STRINGSTREAM
    template <typename Exception, typename S1, typename Pos>
    void throw_(typename Exception::error_code code, S1 msg, Pos const& pos)
    {
        std::strstream stream;
        stream << Exception::severity_text(code) << ": "
               << Exception::error_text(code);
        if (msg[0] != 0) 
            stream << ": " << msg;
        stream << std::ends;
        std::string throwmsg = stream.str(); stream.freeze(false);
        boost::throw_exception(Exception(throwmsg.c_str(), code,
            pos.get_line(), pos.get_column(), pos.get_file().c_str()));
    }

    template <typename Exception, typename Context, typename S1, typename Pos>
    void throw_(Context& ctx, typename Exception::error_code code, 
        S1 msg, Pos const& pos)
    {
        std::strstream stream;
        stream << Exception::severity_text(code) << ": "
               << Exception::error_text(code);
        if (msg[0] != 0) 
            stream << ": " << msg;
        stream << std::ends;
        std::string throwmsg = stream.str(); stream.freeze(false);
        ctx.get_hooks().throw_exception(ctx.derived(), 
            Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), 
                pos.get_file().c_str()));
    }

    template <typename Exception, typename S1, typename Pos, typename S2>
    void throw_(typename Exception::error_code code, S1 msg, Pos const& pos, 
        S2 name)
    {
        std::strstream stream;
        stream << Exception::severity_text(code) << ": "
               << Exception::error_text(code);
        if (msg[0] != 0) 
            stream << ": " << msg;
        stream << std::ends;
        std::string throwmsg = stream.str(); stream.freeze(false);
        boost::throw_exception(Exception(throwmsg.c_str(), code,
            pos.get_line(), pos.get_column(), pos.get_file().c_str(), name));
    }

    template <typename Exception, typename Context, typename S1, typename Pos, 
        typename S2>
    void throw_(Context& ctx, typename Exception::error_code code, 
        S1 msg, Pos const& pos, S2 name)
    {
        std::strstream stream;
        stream << Exception::severity_text(code) << ": "
               << Exception::error_text(code);
        if (msg[0] != 0) 
            stream << ": " << msg;
        stream << std::ends;
        std::string throwmsg = stream.str(); stream.freeze(false);
        ctx.get_hooks().throw_exception(ctx.derived(), 
            Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), 
                pos.get_file().c_str(), name));
    }
#else
    template <typename Exception, typename S1, typename Pos>
    void throw_(typename Exception::error_code code, S1 msg, Pos const& pos)
    {
        std::stringstream stream;
        stream << Exception::severity_text(code) << ": "
               << Exception::error_text(code);
        if (msg[0] != 0) 
            stream << ": " << msg;
        stream << std::ends;
        std::string throwmsg = stream.str(); 
        boost::throw_exception(Exception(throwmsg.c_str(), code,
            pos.get_line(), pos.get_column(), pos.get_file().c_str()));
    }

    template <typename Exception, typename Context, typename S1, typename Pos>
    void throw_(Context& ctx, typename Exception::error_code code, 
        S1 msg, Pos const& pos)
    {
        std::stringstream stream;
        stream << Exception::severity_text(code) << ": "
               << Exception::error_text(code);
        if (msg[0] != 0) 
            stream << ": " << msg;
        stream << std::ends;
        std::string throwmsg = stream.str(); 
        ctx.get_hooks().throw_exception(ctx.derived(), 
            Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), 
                pos.get_file().c_str()));
    }

    template <typename Exception, typename S1, typename Pos, typename S2>
    void throw_(typename Exception::error_code code, S1 msg, Pos const& pos, 
        S2 name)
    {
        std::stringstream stream;
        stream << Exception::severity_text(code) << ": "
               << Exception::error_text(code);
        if (msg[0] != 0) 
            stream << ": " << msg;
        stream << std::ends;
        std::string throwmsg = stream.str(); 
        boost::throw_exception(Exception(throwmsg.c_str(), code,
            pos.get_line(), pos.get_column(), pos.get_file().c_str(), name));
    }

    template <typename Exception, typename Context, typename S1, typename Pos1, 
        typename S2>
    void throw_(Context& ctx, typename Exception::error_code code, 
        S1 msg, Pos1 const& pos, S2 name)
    {
        std::stringstream stream;
        stream << Exception::severity_text(code) << ": "
               << Exception::error_text(code);
        if (msg[0] != 0) 
            stream << ": " << msg;
        stream << std::ends;
        std::string throwmsg = stream.str(); 
        ctx.get_hooks().throw_exception(ctx.derived(), 
            Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), 
                pos.get_file().c_str(), name));
    }
#endif
}}}

///////////////////////////////////////////////////////////////////////////////
// helper macro for throwing exceptions
#if !defined(BOOST_WAVE_THROW)
#define BOOST_WAVE_THROW(cls, code, msg, act_pos)                             \
    boost::wave::util::throw_<cls>(cls::code, msg, act_pos)                   \
    /**/

#define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos)                    \
    boost::wave::util::throw_<cls>(ctx, cls::code, msg, act_pos)              \
    /**/
#endif // BOOST_WAVE_THROW

///////////////////////////////////////////////////////////////////////////////
// helper macro for throwing exceptions with additional parameter
#if !defined(BOOST_WAVE_THROW_NAME_CTX)
#define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name)         \
    boost::wave::util::throw_<cls>(cls::code, msg, act_pos, name)             \
    /**/
#endif // BOOST_WAVE_THROW_NAME_CTX

///////////////////////////////////////////////////////////////////////////////
// helper macro for throwing exceptions with additional parameter
#if !defined(BOOST_WAVE_THROW_VAR_CTX)
#define BOOST_WAVE_THROW_VAR_CTX(ctx, cls, code, msg, act_pos)                \
    boost::wave::util::throw_<cls>(ctx, code, msg, act_pos)                   \
    /**/
#endif // BOOST_WAVE_THROW_VAR_CTX

#endif // !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)