]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright David Abrahams 2002. |
2 | // Distributed under the Boost Software License, Version 1.0. (See | |
3 | // accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | #ifndef TRANSLATE_EXCEPTION_TDS20091020_HPP | |
6 | # define TRANSLATE_EXCEPTION_TDS20091020_HPP | |
7 | ||
8 | # include <boost/python/detail/exception_handler.hpp> | |
9 | ||
10 | # include <boost/call_traits.hpp> | |
11 | # include <boost/type_traits/add_const.hpp> | |
12 | # include <boost/type_traits/add_reference.hpp> | |
13 | # include <boost/type_traits/remove_reference.hpp> | |
14 | ||
15 | # include <boost/function/function0.hpp> | |
16 | ||
17 | namespace boost { namespace python { namespace detail { | |
18 | ||
19 | // A ternary function object used to translate C++ exceptions of type | |
20 | // ExceptionType into Python exceptions by invoking an object of type | |
21 | // Translate. Typically the translate function will be curried with | |
22 | // boost::bind(). | |
23 | template <class ExceptionType, class Translate> | |
24 | struct translate_exception | |
25 | { | |
26 | // workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1 | |
27 | # if defined(__linux__) && defined(__GNUC__) \ | |
28 | && BOOST_WORKAROUND(__GNUC__, == 3) \ | |
29 | && BOOST_WORKAROUND(__GNUC_MINOR__, == 3) \ | |
30 | && (BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 1) \ | |
31 | || BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 3)) | |
32 | typedef typename remove_reference< | |
33 | typename add_const<ExceptionType>::type | |
34 | >::type exception_non_ref; | |
35 | # else | |
36 | typedef typename add_reference< | |
37 | typename add_const<ExceptionType>::type | |
38 | >::type exception_cref; | |
39 | # endif | |
40 | ||
41 | inline bool operator()( | |
42 | exception_handler const& handler | |
43 | , function0<void> const& f | |
44 | , typename call_traits<Translate>::param_type translate) const | |
45 | { | |
46 | try | |
47 | { | |
48 | return handler(f); | |
49 | } | |
50 | // workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1 | |
51 | # if defined(__linux__) && defined(__GNUC__) \ | |
52 | && BOOST_WORKAROUND(__GNUC__, == 3) \ | |
53 | && BOOST_WORKAROUND(__GNUC_MINOR__, == 3) \ | |
54 | && (BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 1) \ | |
55 | || BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 3)) | |
56 | catch(exception_non_ref& e) | |
57 | # else | |
58 | catch(exception_cref e) | |
59 | # endif | |
60 | { | |
61 | translate(e); | |
62 | return true; | |
63 | } | |
64 | } | |
65 | }; | |
66 | ||
67 | }}} // namespace boost::python::detail | |
68 | ||
69 | #endif // TRANSLATE_EXCEPTION_DWA2002810_HPP |