knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
list.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_PY_CONVERTER_LIST_H
7 #define KNOWROB_PY_CONVERTER_LIST_H
8 
9 #include <boost/python.hpp>
10 #include <list>
11 #include "knowrob/DataSource.h"
12 
13 namespace knowrob::py {
15  template <typename T>
16  struct list_to_pylist
17  {
18  static PyObject* convert(const std::list<T>& list)
19  {
20  boost::python::list result;
21  for(const auto& elem : list)
22  {
23  result.append(boost::python::object(elem));
24  }
25  return boost::python::incref(result.ptr());
26  }
27  };
28 
30  boost::python::to_python_converter<std::list<std::shared_ptr<knowrob::DataSource>>, list_to_pylist<std::shared_ptr<knowrob::DataSource>>>();
31  }
32 }
33 
34 #endif //KNOWROB_PY_CONVERTER_LIST_H
void register_list_converter()
Definition: list.h:29
static PyObject * convert(const std::list< T > &list)
Definition: list.h:18