knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::py::custom_vector_from_seq< containedType > Struct Template Reference

#include <vector.h>

Public Member Functions

 custom_vector_from_seq ()
 
 custom_vector_from_seq ()
 

Static Public Member Functions

static void * convertible (PyObject *obj_ptr)
 
static void construct (PyObject *obj_ptr, boost::python::converter::rvalue_from_python_stage1_data *data)
 
static void * convertible (PyObject *obj_ptr)
 
static void construct (PyObject *obj_ptr, boost::python::converter::rvalue_from_python_stage1_data *data)
 

Detailed Description

template<typename containedType>
struct knowrob::py::custom_vector_from_seq< containedType >

Definition at line 12 of file vector.h.

Constructor & Destructor Documentation

◆ custom_vector_from_seq() [1/2]

template<typename containedType >
knowrob::py::custom_vector_from_seq< containedType >::custom_vector_from_seq ( )
inline

Definition at line 13 of file vector.h.

13  {
14  boost::python::converter::registry::push_back(&convertible,
15  &construct,
16  boost::python::type_id<std::vector<containedType> >());
17  }
static void construct(PyObject *obj_ptr, boost::python::converter::rvalue_from_python_stage1_data *data)
Definition: vector.h:26
static void * convertible(PyObject *obj_ptr)
Definition: vector.h:19

◆ custom_vector_from_seq() [2/2]

template<typename containedType >
knowrob::py::custom_vector_from_seq< containedType >::custom_vector_from_seq ( )
inline

Definition at line 13 of file vector.h.

13  {
14  boost::python::converter::registry::push_back(&convertible,
15  &construct,
16  boost::python::type_id<std::vector<containedType> >());
17  }

Member Function Documentation

◆ construct() [1/2]

template<typename containedType >
static void knowrob::py::custom_vector_from_seq< containedType >::construct ( PyObject *  obj_ptr,
boost::python::converter::rvalue_from_python_stage1_data *  data 
)
inlinestatic

Definition at line 26 of file vector.h.

26  {
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);
31  if (l < 0) abort();
32  v->reserve(l);
33  for (int i = 0; i < l; i++) {
34  v->push_back(boost::python::extract<containedType>(PySequence_GetItem(obj_ptr, i)));
35  }
36  data->convertible = storage;
37  }

◆ construct() [2/2]

template<typename containedType >
static void knowrob::py::custom_vector_from_seq< containedType >::construct ( PyObject *  obj_ptr,
boost::python::converter::rvalue_from_python_stage1_data *  data 
)
inlinestatic

Definition at line 26 of file vector.h.

26  {
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);
31  if (l < 0) abort();
32  v->reserve(l);
33  for (int i = 0; i < l; i++) {
34  v->push_back(boost::python::extract<containedType>(PySequence_GetItem(obj_ptr, i)));
35  }
36  data->convertible = storage;
37  }

◆ convertible() [1/2]

template<typename containedType >
static void* knowrob::py::custom_vector_from_seq< containedType >::convertible ( PyObject *  obj_ptr)
inlinestatic

Definition at line 19 of file vector.h.

19  {
20  // the second condition is important, for some reason otherwise there were attempted conversions
21  // of Body to list which failed afterwards.
22  if (!PySequence_Check(obj_ptr) || !PyObject_HasAttrString(obj_ptr, "__len__")) return nullptr;
23  return obj_ptr;
24  }

◆ convertible() [2/2]

template<typename containedType >
static void* knowrob::py::custom_vector_from_seq< containedType >::convertible ( PyObject *  obj_ptr)
inlinestatic

Definition at line 19 of file vector.h.

19  {
20  // the second condition is important, for some reason otherwise there were attempted conversions
21  // of Body to list which failed afterwards.
22  if (!PySequence_Check(obj_ptr) || !PyObject_HasAttrString(obj_ptr, "__len__")) return nullptr;
23  return obj_ptr;
24  }

The documentation for this struct was generated from the following file: