python.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Douglas Gregor
  6. #ifndef BOOST_MPI_PYTHON_HPP
  7. #define BOOST_MPI_PYTHON_HPP
  8. #include <boost/python/object.hpp>
  9. /** @file python.hpp
  10. *
  11. * This header interacts with the Python bindings for Boost.MPI. The
  12. * routines in this header can be used to register user-defined and
  13. * library-defined data types with Boost.MPI for efficient
  14. * (de-)serialization and separate transmission of skeletons and
  15. * content.
  16. *
  17. */
  18. namespace boost { namespace mpi { namespace python {
  19. /**
  20. * @brief Register the type T for direct serialization within Boost.MPI
  21. *
  22. * The @c register_serialized function registers a C++ type for direct
  23. * serialization within Boost.MPI. Direct serialization elides the use
  24. * of the Python @c pickle package when serializing Python objects
  25. * that represent C++ values. Direct serialization can be beneficial
  26. * both to improve serialization performance (Python pickling can be
  27. * very inefficient) and to permit serialization for Python-wrapped
  28. * C++ objects that do not support pickling.
  29. *
  30. * @param value A sample value of the type @c T. This may be used
  31. * to compute the Python type associated with the C++ type @c T.
  32. *
  33. * @param type The Python type associated with the C++ type @c
  34. * T. If not provided, it will be computed from the same value @p
  35. * value.
  36. */
  37. template<typename T>
  38. void
  39. register_serialized(const T& value = T(), PyTypeObject* type = 0);
  40. /**
  41. * @brief Registers a type for use with the skeleton/content mechanism
  42. * in Python.
  43. *
  44. * The skeleton/content mechanism can only be used from Python with
  45. * C++ types that have previously been registered via a call to this
  46. * function. Both the sender and the transmitter must register the
  47. * type. It is permitted to call this function multiple times for the
  48. * same type @c T, but only one call per process per type is
  49. * required. The type @c T must be Serializable.
  50. *
  51. * @param value A sample object of type T that will be used to
  52. * determine the Python type associated with T, if @p type is not
  53. * specified.
  54. *
  55. * @param type The Python type associated with the C++ type @c
  56. * T. If not provided, it will be computed from the same value @p
  57. * value.
  58. */
  59. template<typename T>
  60. void
  61. register_skeleton_and_content(const T& value = T(), PyTypeObject* type = 0);
  62. } } } // end namespace boost::mpi::python
  63. #ifndef BOOST_MPI_PYTHON_FORWARD_ONLY
  64. # include <boost/mpi/python/serialize.hpp>
  65. # include <boost/mpi/python/skeleton_and_content.hpp>
  66. #else
  67. # undef BOOST_MPI_PYTHON_FORWARD_ONLY
  68. #endif
  69. #endif // BOOST_MPI_PYTHON_HPP