High Performance Plasticity  0.5.0
python.h
Go to the documentation of this file.
1 #ifndef HPP_PYTHON_H
2 #define HPP_PYTHON_H
3 
4 #include <boost/python.hpp>
5 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
6 
7 namespace hpp
8 {
9 
10 template <class T>
11 boost::python::list toPythonList(const std::vector<T>& vec) {
12  boost::python::list list;
13  for (const auto& v : vec) {
14  list.append(v);
15  }
16  return list;
17 }
18 
19 template <class T>
20 std::vector<T> toStdVector(const boost::python::list& list) {
21  int length = boost::python::len(list);
22  std::vector<T> vec(length);
23  for (int i=0; i<length; i++) {
24  vec[i] = boost::python::extract<T>(list[i]);
25  }
26  return vec;
27 }
28 
29 } //END NAMESPACE HPP
30 
31 #endif /* HPP_PYTHON_H */
boost::python::list toPythonList(const std::vector< T > &vec)
Definition: python.h:11
Definition: casesUtils.cpp:4
std::vector< T > toStdVector(const boost::python::list &list)
Definition: python.h:20