From e0737c56c1e384e05064a0c6e1ac46979371041b Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 19 Dec 2018 22:58:32 +0100 Subject: New upstream version 2.0.0+repack --- boost/libs/mpi/src/python/py_request.cpp | 111 +++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 boost/libs/mpi/src/python/py_request.cpp (limited to 'boost/libs/mpi/src/python/py_request.cpp') diff --git a/boost/libs/mpi/src/python/py_request.cpp b/boost/libs/mpi/src/python/py_request.cpp new file mode 100644 index 00000000..55b2b5ae --- /dev/null +++ b/boost/libs/mpi/src/python/py_request.cpp @@ -0,0 +1,111 @@ +// (C) Copyright 2006 Douglas Gregor + +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Douglas Gregor + +/** @file request.cpp + * + * This file reflects the Boost.MPI @c request class into + * Python. + */ +#include +#include +#include "request_with_value.hpp" + +using namespace boost::python; +using namespace boost::mpi; + +const object python::request_with_value::get_value() const +{ + if (m_internal_value.get()) + return *m_internal_value; + else if (m_external_value) + return *m_external_value; + else + { + PyErr_SetString(PyExc_ValueError, "request value not available"); + throw boost::python::error_already_set(); + } +} + +const object python::request_with_value::get_value_or_none() const +{ + if (m_internal_value.get()) + return *m_internal_value; + else if (m_external_value) + return *m_external_value; + else + return object(); +} + +const object python::request_with_value::wrap_wait() +{ + status stat = request::wait(); + if (m_internal_value.get() || m_external_value) + return boost::python::make_tuple(get_value(), stat); + else + return object(stat); +} + +const object python::request_with_value::wrap_test() +{ + ::boost::optional stat = request::test(); + if (stat) + { + if (m_internal_value.get() || m_external_value) + return boost::python::make_tuple(get_value(), *stat); + else + return object(*stat); + } + else + return object(); +} + + +namespace boost { namespace mpi { namespace python { + +const object request_test(request &req) +{ + ::boost::optional stat = req.test(); + if (stat) + return object(*stat); + else + return object(); +} + +extern const char* request_docstring; +extern const char* request_with_value_docstring; +extern const char* request_wait_docstring; +extern const char* request_test_docstring; +extern const char* request_cancel_docstring; +extern const char* request_value_docstring; + +void export_request() +{ + using boost::python::arg; + using boost::python::object; + + { + typedef request cl; + class_("Request", request_docstring, no_init) + .def("wait", &cl::wait, request_wait_docstring) + .def("test", &request_test, request_test_docstring) + .def("cancel", &cl::cancel, request_cancel_docstring) + ; + } + { + typedef request_with_value cl; + class_ >( + "RequestWithValue", request_with_value_docstring, no_init) + .def("wait", &cl::wrap_wait, request_wait_docstring) + .def("test", &cl::wrap_test, request_test_docstring) + ; + } + + implicitly_convertible(); +} + +} } } // end namespace boost::mpi::python -- cgit v1.2.3