1 // (C) Copyright 2006 Douglas Gregor <doug.gregor -at- gmail.com> 2 3 // Use, modification and distribution is subject to the Boost Software 4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 // Authors: Douglas Gregor 8 #ifndef BOOST_MPI_PYTHON_UTILITY_HPP 9 #define BOOST_MPI_PYTHON_UTILITY_HPP 10 11 /** @file utility.hpp 12 * 13 * This file is a utility header for the Boost.MPI Python bindings. 14 */ 15 #include <boost/python.hpp> 16 17 namespace boost { namespace mpi { namespace python { 18 19 template<typename E> 20 class translate_exception 21 { translate_exception(boost::python::object type)22 explicit translate_exception(boost::python::object type) : type(type) { } 23 24 public: declare(boost::python::object type)25 static void declare(boost::python::object type) 26 { 27 using boost::python::register_exception_translator; 28 register_exception_translator<E>(translate_exception(type)); 29 } 30 operator ()(const E & e) const31 void operator()(const E& e) const 32 { 33 using boost::python::object; 34 PyErr_SetObject(type.ptr(), object(e).ptr()); 35 } 36 37 private: 38 boost::python::object type; 39 }; 40 41 } } } // end namespace boost::mpi::python 42 43 #endif // BOOST_MPI_PYTHON_UTILITY_HPP 44