Chris@16: /*============================================================================= Chris@16: Boost.Wave: A Standard compliant C++ preprocessor library Chris@16: Chris@16: http://www.boost.org/ Chris@16: Chris@16: Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost Chris@16: Software License, Version 1.0. (See accompanying file Chris@16: LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: Chris@16: #if !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED) Chris@16: #define BOOST_WAVE_CPP_THROW_HPP_INCLUDED Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_NO_STRINGSTREAM Chris@16: #include Chris@16: #else Chris@16: #include Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace wave { namespace util Chris@16: { Chris@16: #ifdef BOOST_NO_STRINGSTREAM Chris@16: template Chris@16: void throw_(typename Exception::error_code code, S1 msg, Pos const& pos) Chris@16: { Chris@16: std::strstream stream; Chris@16: stream << Exception::severity_text(code) << ": " Chris@16: << Exception::error_text(code); Chris@16: if (msg[0] != 0) Chris@16: stream << ": " << msg; Chris@16: stream << std::ends; Chris@16: std::string throwmsg = stream.str(); stream.freeze(false); Chris@16: boost::throw_exception(Exception(throwmsg.c_str(), code, Chris@16: pos.get_line(), pos.get_column(), pos.get_file().c_str())); Chris@16: } Chris@16: Chris@16: template Chris@16: void throw_(Context& ctx, typename Exception::error_code code, Chris@16: S1 msg, Pos const& pos) Chris@16: { Chris@16: std::strstream stream; Chris@16: stream << Exception::severity_text(code) << ": " Chris@16: << Exception::error_text(code); Chris@16: if (msg[0] != 0) Chris@16: stream << ": " << msg; Chris@16: stream << std::ends; Chris@16: std::string throwmsg = stream.str(); stream.freeze(false); Chris@16: ctx.get_hooks().throw_exception(ctx.derived(), Chris@16: Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), Chris@16: pos.get_file().c_str())); Chris@16: } Chris@16: Chris@16: template Chris@16: void throw_(typename Exception::error_code code, S1 msg, Pos const& pos, Chris@16: S2 name) Chris@16: { Chris@16: std::strstream stream; Chris@16: stream << Exception::severity_text(code) << ": " Chris@16: << Exception::error_text(code); Chris@16: if (msg[0] != 0) Chris@16: stream << ": " << msg; Chris@16: stream << std::ends; Chris@16: std::string throwmsg = stream.str(); stream.freeze(false); Chris@16: boost::throw_exception(Exception(throwmsg.c_str(), code, Chris@16: pos.get_line(), pos.get_column(), pos.get_file().c_str(), name)); Chris@16: } Chris@16: Chris@16: template Chris@16: void throw_(Context& ctx, typename Exception::error_code code, Chris@16: S1 msg, Pos const& pos, S2 name) Chris@16: { Chris@16: std::strstream stream; Chris@16: stream << Exception::severity_text(code) << ": " Chris@16: << Exception::error_text(code); Chris@16: if (msg[0] != 0) Chris@16: stream << ": " << msg; Chris@16: stream << std::ends; Chris@16: std::string throwmsg = stream.str(); stream.freeze(false); Chris@16: ctx.get_hooks().throw_exception(ctx.derived(), Chris@16: Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), Chris@16: pos.get_file().c_str(), name)); Chris@16: } Chris@16: #else Chris@16: template Chris@16: void throw_(typename Exception::error_code code, S1 msg, Pos const& pos) Chris@16: { Chris@16: std::stringstream stream; Chris@16: stream << Exception::severity_text(code) << ": " Chris@16: << Exception::error_text(code); Chris@16: if (msg[0] != 0) Chris@16: stream << ": " << msg; Chris@16: stream << std::ends; Chris@16: std::string throwmsg = stream.str(); Chris@16: boost::throw_exception(Exception(throwmsg.c_str(), code, Chris@16: pos.get_line(), pos.get_column(), pos.get_file().c_str())); Chris@16: } Chris@16: Chris@16: template Chris@16: void throw_(Context& ctx, typename Exception::error_code code, Chris@16: S1 msg, Pos const& pos) Chris@16: { Chris@16: std::stringstream stream; Chris@16: stream << Exception::severity_text(code) << ": " Chris@16: << Exception::error_text(code); Chris@16: if (msg[0] != 0) Chris@16: stream << ": " << msg; Chris@16: stream << std::ends; Chris@16: std::string throwmsg = stream.str(); Chris@16: ctx.get_hooks().throw_exception(ctx.derived(), Chris@16: Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), Chris@16: pos.get_file().c_str())); Chris@16: } Chris@16: Chris@16: template Chris@16: void throw_(typename Exception::error_code code, S1 msg, Pos const& pos, Chris@16: S2 name) Chris@16: { Chris@16: std::stringstream stream; Chris@16: stream << Exception::severity_text(code) << ": " Chris@16: << Exception::error_text(code); Chris@16: if (msg[0] != 0) Chris@16: stream << ": " << msg; Chris@16: stream << std::ends; Chris@16: std::string throwmsg = stream.str(); Chris@16: boost::throw_exception(Exception(throwmsg.c_str(), code, Chris@16: pos.get_line(), pos.get_column(), pos.get_file().c_str(), name)); Chris@16: } Chris@16: Chris@16: template Chris@16: void throw_(Context& ctx, typename Exception::error_code code, Chris@16: S1 msg, Pos1 const& pos, S2 name) Chris@16: { Chris@16: std::stringstream stream; Chris@16: stream << Exception::severity_text(code) << ": " Chris@16: << Exception::error_text(code); Chris@16: if (msg[0] != 0) Chris@16: stream << ": " << msg; Chris@16: stream << std::ends; Chris@16: std::string throwmsg = stream.str(); Chris@16: ctx.get_hooks().throw_exception(ctx.derived(), Chris@16: Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), Chris@16: pos.get_file().c_str(), name)); Chris@16: } Chris@16: #endif Chris@16: }}} Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // helper macro for throwing exceptions Chris@16: #if !defined(BOOST_WAVE_THROW) Chris@16: #define BOOST_WAVE_THROW(cls, code, msg, act_pos) \ Chris@16: boost::wave::util::throw_(cls::code, msg, act_pos) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \ Chris@16: boost::wave::util::throw_(ctx, cls::code, msg, act_pos) \ Chris@16: /**/ Chris@16: #endif // BOOST_WAVE_THROW Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // helper macro for throwing exceptions with additional parameter Chris@16: #if !defined(BOOST_WAVE_THROW_NAME_CTX) Chris@16: #define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name) \ Chris@16: boost::wave::util::throw_(cls::code, msg, act_pos, name) \ Chris@16: /**/ Chris@16: #endif // BOOST_WAVE_THROW_NAME_CTX Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // helper macro for throwing exceptions with additional parameter Chris@16: #if !defined(BOOST_WAVE_THROW_VAR_CTX) Chris@16: #define BOOST_WAVE_THROW_VAR_CTX(ctx, cls, code, msg, act_pos) \ Chris@16: boost::wave::util::throw_(ctx, code, msg, act_pos) \ Chris@16: /**/ Chris@16: #endif // BOOST_WAVE_THROW_VAR_CTX Chris@16: Chris@16: #endif // !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)