• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  // (C) Copyright 2006 Douglas Gregor <doug.gregor -at- gmail.com>
2  
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)
6  
7  //  Authors: Douglas Gregor
8  
9  #include <boost/parallel/mpi/python.hpp>
10  #include <boost/python.hpp>
11  #include <boost/serialization/list.hpp>
12  using namespace boost::python;
13  
14  template<typename T>
list_to_python(const std::list<T> & value)15  boost::python::list list_to_python(const std::list<T>& value) {
16    boost::python::list result;
17    for (typename std::list<T>::const_iterator i = value.begin();
18         i != value.end(); ++i)
19      result.append(*i);
20    return result;
21  }
22  
BOOST_PYTHON_MODULE(skeleton_content)23  BOOST_PYTHON_MODULE(skeleton_content)
24  {
25    using boost::python::arg;
26  
27    class_<std::list<int> >("list_int")
28      .def("push_back", &std::list<int>::push_back, arg("value"))
29      .def("pop_back", &std::list<int>::pop_back)
30      .def("reverse", &std::list<int>::reverse)
31      .def(boost::python::self == boost::python::self)
32      .def(boost::python::self != boost::python::self)
33      .add_property("size", &std::list<int>::size)
34      .def("to_python", &list_to_python<int>);
35  
36    boost::parallel::mpi::python::register_skeleton_and_content<std::list<int> >();
37  }
38