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