1 // Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>
2 // Copyright (C) 2005 The Trustees of Indiana University.
3 
4 // Use, modification and distribution is subject to the Boost Software
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
8 //  Authors: Douglas Gregor
9 
10 /** @file exception.cpp
11  *
12  *  This file reflects the Boost.MPI @c mpi_error class into
13  *  Python.
14  */
15 #include <boost/python.hpp>
16 #include <boost/mpi/exception.hpp>
17 #include <string>
18 #include <boost/lexical_cast.hpp>
19 #include "utility.hpp"
20 
21 using namespace boost::python;
22 using namespace boost::mpi;
23 
24 namespace boost { namespace mpi { namespace python {
25 
26 extern const char* exception_docstring;
27 extern const char* exception_what_docstring;
28 extern const char* exception_routine_docstring;
29 extern const char* exception_result_code_docstring;
30 
exception_str(const exception & e)31 str exception_str(const exception& e)
32 {
33   return str(std::string(e.what()) +
34              " (code " + lexical_cast<std::string>(e.result_code())+")");
35 }
36 
export_exception()37 void export_exception()
38 {
39   using boost::python::arg;
40   using boost::python::object;
41 
42   object type =
43     class_<exception>
44       ("Exception", exception_docstring, no_init)
45       .add_property("what", &exception::what, exception_what_docstring)
46       .add_property("routine", &exception::what, exception_routine_docstring)
47       .add_property("result_code", &exception::result_code,
48                     exception_result_code_docstring)
49       .def("__str__", &exception_str)
50     ;
51   translate_exception<exception>::declare(type);
52 }
53 
54 } } } // end namespace boost::mpi::python
55