1 // (C) Copyright 2006 Douglas Gregor <doug.gregor -at- gmail.com>
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)
7 // Authors: Douglas Gregor
11 * This file reflects the Boost.MPI @c request class into
14 #include <boost/python.hpp>
15 #include <boost/mpi.hpp>
16 #include "request_with_value.hpp"
18 using namespace boost::python
;
19 using namespace boost::mpi
;
21 const object
python::request_with_value::get_value() const
23 if (m_internal_value
.get())
24 return *m_internal_value
;
25 else if (m_external_value
)
26 return *m_external_value
;
29 PyErr_SetString(PyExc_ValueError
, "request value not available");
30 throw boost::python::error_already_set();
34 const object
python::request_with_value::get_value_or_none() const
36 if (m_internal_value
.get())
37 return *m_internal_value
;
38 else if (m_external_value
)
39 return *m_external_value
;
44 const object
python::request_with_value::wrap_wait()
46 status stat
= request::wait();
47 if (m_internal_value
.get() || m_external_value
)
48 return boost::python::make_tuple(get_value(), stat
);
53 const object
python::request_with_value::wrap_test()
55 ::boost::optional
<status
> stat
= request::test();
58 if (m_internal_value
.get() || m_external_value
)
59 return boost::python::make_tuple(get_value(), *stat
);
68 namespace boost
{ namespace mpi
{ namespace python
{
70 const object
request_test(request
&req
)
72 ::boost::optional
<status
> stat
= req
.test();
79 extern const char* request_docstring
;
80 extern const char* request_with_value_docstring
;
81 extern const char* request_wait_docstring
;
82 extern const char* request_test_docstring
;
83 extern const char* request_cancel_docstring
;
84 extern const char* request_value_docstring
;
88 using boost::python::arg
;
89 using boost::python::object
;
93 class_
<cl
>("Request", request_docstring
, no_init
)
94 .def("wait", &cl::wait
, request_wait_docstring
)
95 .def("test", &request_test
, request_test_docstring
)
96 .def("cancel", &cl::cancel
, request_cancel_docstring
)
100 typedef request_with_value cl
;
101 class_
<cl
, bases
<request
> >(
102 "RequestWithValue", request_with_value_docstring
, no_init
)
103 .def("wait", &cl::wrap_wait
, request_wait_docstring
)
104 .def("test", &cl::wrap_test
, request_test_docstring
)
108 implicitly_convertible
<request
, request_with_value
>();
111 } } } // end namespace boost::mpi::python