6 #ifndef KNOWROB_PY_CONVERTER_VECTOR_H
7 #define KNOWROB_PY_CONVERTER_VECTOR_H
11 template<
typename containedType>
12 struct custom_vector_from_seq {
14 boost::python::converter::registry::push_back(&
convertible,
16 boost::python::type_id<std::vector<containedType> >());
22 if (!PySequence_Check(obj_ptr) || !PyObject_HasAttrString(obj_ptr,
"__len__"))
return nullptr;
26 static void construct(PyObject *obj_ptr, boost::python::converter::rvalue_from_python_stage1_data *data) {
27 void *storage = ((boost::python::converter::rvalue_from_python_storage<std::vector<containedType> > *) (data))->storage.bytes;
28 new(storage) std::vector<containedType>();
29 auto v = (std::vector<containedType> *) (storage);
30 auto l = PySequence_Size(obj_ptr);
33 for (
int i = 0; i < l; i++) {
34 v->push_back(boost::python::extract<containedType>(PySequence_GetItem(obj_ptr, i)));
36 data->convertible = storage;
static void construct(PyObject *obj_ptr, boost::python::converter::rvalue_from_python_stage1_data *data)
static void * convertible(PyObject *obj_ptr)