00001 #ifndef BOOST_ADAPTBX_TUPLE_CONVERSION_H
00002 #define BOOST_ADAPTBX_TUPLE_CONVERSION_H
00003
00004 #include <boost/python/tuple.hpp>
00005 #include <boost/python/module.hpp>
00006 #include <boost/python/refcount.hpp>
00007 #include <boost/python/to_python_converter.hpp>
00008 #include <boost/tuple/tuple.hpp>
00009
00010
00011
00012
00013
00014 namespace boost_adaptbx { namespace tuple_conversion {
00015
00016 namespace detail {
00017
00018
00019
00020
00021
00022
00023 template <class T>
00024 struct to_python
00025 {
00026 template <class Head, class Tail>
00027 static
00028 inline
00029 boost::python::tuple
00030 tuple_to_python(boost::tuples::cons<Head, Tail> const& x) {
00031 boost::python::tuple head = boost::python::make_tuple(x.get_head());
00032 boost::python::tuple tail = tuple_to_python(x.get_tail());
00033 return boost::python::tuple(head + tail);
00034 }
00035
00036 static
00037 inline
00038 boost::python::tuple
00039 tuple_to_python(boost::tuples::null_type) {
00040 return boost::python::tuple();
00041 }
00042
00043 static PyObject *
00044 convert(T const& x) {
00045 return boost::python::incref(tuple_to_python(x).ptr());
00046 }
00047 };
00048
00049 }
00050
00051 template<class T>
00052 struct to_python
00053 {
00054 to_python() {
00055 boost::python::to_python_converter<T, detail::to_python<T> >();
00056 }
00057 };
00058
00059
00060 }}
00061
00062 #endif // GUARD