std-pair.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2023 INRIA
3 //
4 
5 #ifndef COAL_PYTHON_UTILS_STD_PAIR_H
6 #define COAL_PYTHON_UTILS_STD_PAIR_H
7 
8 #include <boost/python.hpp>
9 #include <utility>
10 
11 template <typename pair_type>
13  typedef typename pair_type::first_type T1;
14  typedef typename pair_type::second_type T2;
15 
16  static PyObject* convert(const pair_type& pair) {
17  return boost::python::incref(
18  boost::python::make_tuple(pair.first, pair.second).ptr());
19  }
20 
21  static void* convertible(PyObject* obj) {
22  if (!PyTuple_CheckExact(obj)) return 0;
23  if (PyTuple_Size(obj) != 2) return 0;
24  {
25  boost::python::tuple tuple(boost::python::borrowed(obj));
26  boost::python::extract<T1> elt1(tuple[0]);
27  if (!elt1.check()) return 0;
28  boost::python::extract<T2> elt2(tuple[1]);
29  if (!elt2.check()) return 0;
30  }
31  return obj;
32  }
33 
34  static void construct(
35  PyObject* obj,
36  boost::python::converter::rvalue_from_python_stage1_data* memory) {
37  boost::python::tuple tuple(boost::python::borrowed(obj));
38  void* storage =
39  reinterpret_cast<
40  boost::python::converter::rvalue_from_python_storage<pair_type>*>(
41  reinterpret_cast<void*>(memory))
42  ->storage.bytes;
43  new (storage) pair_type(boost::python::extract<T1>(tuple[0]),
44  boost::python::extract<T2>(tuple[1]));
45  memory->convertible = storage;
46  }
47 
48  static PyTypeObject const* get_pytype() {
49  PyTypeObject const* py_type = &PyTuple_Type;
50  return py_type;
51  }
52 
53  static void registration() {
54  boost::python::converter::registry::push_back(
55  reinterpret_cast<void* (*)(_object*)>(&convertible), &construct,
56  boost::python::type_id<pair_type>()
57 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
58  ,
60 #endif
61  );
62  }
63 };
64 
65 #endif // ifndef COAL_PYTHON_UTILS_STD_PAIR_H
StdPairConverter::registration
static void registration()
Definition: std-pair.hh:53
StdPairConverter::get_pytype
static PyTypeObject const * get_pytype()
Definition: std-pair.hh:48
StdPairConverter::construct
static void construct(PyObject *obj, boost::python::converter::rvalue_from_python_stage1_data *memory)
Definition: std-pair.hh:34
StdPairConverter::T2
pair_type::second_type T2
Definition: std-pair.hh:14
StdPairConverter::convertible
static void * convertible(PyObject *obj)
Definition: std-pair.hh:21
StdPairConverter
Definition: std-pair.hh:12
StdPairConverter::T1
pair_type::first_type T1
Definition: std-pair.hh:13
StdPairConverter::convert
static PyObject * convert(const pair_type &pair)
Definition: std-pair.hh:16


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:59