5 #ifndef __eigenpy_utils_std_pair_hpp__
6 #define __eigenpy_utils_std_pair_hpp__
8 #include <boost/python.hpp>
13 template <
typename pair_type>
15 typedef typename pair_type::first_type
T1;
16 typedef typename pair_type::second_type
T2;
18 static PyObject*
convert(
const pair_type& pair) {
19 return boost::python::incref(
20 boost::python::make_tuple(pair.first, pair.second).ptr());
24 if (!PyTuple_CheckExact(obj))
return 0;
25 if (PyTuple_Size(obj) != 2)
return 0;
27 boost::python::tuple tuple(boost::python::borrowed(obj));
28 boost::python::extract<T1> elt1(tuple[0]);
29 if (!elt1.check())
return 0;
30 boost::python::extract<T2> elt2(tuple[1]);
31 if (!elt2.check())
return 0;
38 boost::python::converter::rvalue_from_python_stage1_data* memory) {
39 boost::python::tuple tuple(boost::python::borrowed(obj));
42 boost::python::converter::rvalue_from_python_storage<pair_type>*
>(
43 reinterpret_cast<void*
>(memory))
45 new (storage) pair_type(boost::python::extract<T1>(tuple[0]),
46 boost::python::extract<T2>(tuple[1]));
47 memory->convertible = storage;
51 PyTypeObject
const* py_type = &PyTuple_Type;
56 boost::python::converter::registry::push_back(
58 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
63 boost::python::to_python_converter<pair_type, StdPairConverter, true>();
69 #endif // ifndef __eigenpy_utils_std_pair_hpp__