From 8c4528713d907ee2cfd3bfcbbad272c749867f84 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 25 Jun 2013 22:59:01 +0000 Subject: Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2. --- libs/mpi/src/python/py_request.cpp | 102 +++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 libs/mpi/src/python/py_request.cpp (limited to 'libs/mpi/src/python/py_request.cpp') diff --git a/libs/mpi/src/python/py_request.cpp b/libs/mpi/src/python/py_request.cpp new file mode 100644 index 000000000..53aa4dedf --- /dev/null +++ b/libs/mpi/src/python/py_request.cpp @@ -0,0 +1,102 @@ +// (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 { + +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", &cl::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.1