skeleton_content_test.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // (C) Copyright 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. #include <boost/parallel/mpi/python.hpp>
  7. #include <boost/python.hpp>
  8. #include <boost/serialization/list.hpp>
  9. using namespace boost::python;
  10. template<typename T>
  11. boost::python::list list_to_python(const std::list<T>& value) {
  12. boost::python::list result;
  13. for (typename std::list<T>::const_iterator i = value.begin();
  14. i != value.end(); ++i)
  15. result.append(*i);
  16. return result;
  17. }
  18. BOOST_PYTHON_MODULE(skeleton_content)
  19. {
  20. using boost::python::arg;
  21. class_<std::list<int> >("list_int")
  22. .def("push_back", &std::list<int>::push_back, arg("value"))
  23. .def("pop_back", &std::list<int>::pop_back)
  24. .def("reverse", &std::list<int>::reverse)
  25. .def(boost::python::self == boost::python::self)
  26. .def(boost::python::self != boost::python::self)
  27. .add_property("size", &std::list<int>::size)
  28. .def("to_python", &list_to_python<int>);
  29. boost::parallel::mpi::python::register_skeleton_and_content<std::list<int> >();
  30. }