Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:38

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef TRANSLATE_EXCEPTION_TDS20091020_HPP
0006 # define TRANSLATE_EXCEPTION_TDS20091020_HPP
0007 
0008 # include <boost/python/detail/exception_handler.hpp>
0009 # include <boost/python/detail/type_traits.hpp>
0010 
0011 # include <boost/call_traits.hpp>
0012 
0013 # include <boost/function/function0.hpp>
0014 
0015 namespace boost { namespace python { namespace detail { 
0016 
0017 // A ternary function object used to translate C++ exceptions of type
0018 // ExceptionType into Python exceptions by invoking an object of type
0019 // Translate. Typically the translate function will be curried with
0020 // boost::bind().
0021 template <class ExceptionType, class Translate>
0022 struct translate_exception
0023 {
0024 // workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1
0025 # if defined(__linux__) && defined(__GNUC__) \
0026     && BOOST_WORKAROUND(__GNUC__, == 3) \
0027     && BOOST_WORKAROUND(__GNUC_MINOR__, == 3) \
0028     && (BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 1) \
0029         || BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 3))
0030     typedef typename remove_reference<
0031         typename add_const<ExceptionType>::type
0032     >::type exception_non_ref;
0033 # else
0034     typedef typename add_lvalue_reference<
0035         typename add_const<ExceptionType>::type
0036     >::type exception_cref;
0037 # endif
0038     
0039     inline bool operator()(
0040         exception_handler const& handler
0041       , function0<void> const& f
0042       , typename call_traits<Translate>::param_type translate) const
0043     {
0044         try
0045         {
0046             return handler(f);
0047         }
0048 // workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1
0049 # if defined(__linux__) && defined(__GNUC__) \
0050     && BOOST_WORKAROUND(__GNUC__, == 3) \
0051     && BOOST_WORKAROUND(__GNUC_MINOR__, == 3) \
0052     && (BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 1) \
0053         || BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 3))
0054         catch(exception_non_ref& e)
0055 # else
0056         catch(exception_cref e)
0057 # endif
0058         {
0059             translate(e);
0060             return true;
0061         }
0062     }
0063 };
0064 
0065 }}} // namespace boost::python::detail
0066 
0067 #endif // TRANSLATE_EXCEPTION_DWA2002810_HPP