Commit e210c39c authored by Justin Carpentier's avatar Justin Carpentier

python/list: change function signature and throw when necessary

parent a2bf3a88
......@@ -121,7 +121,7 @@ namespace pinocchio
const GeometryType type
)
{
std::vector<std::string> package_dirs_ = extractList<std::string>(package_dirs);
std::vector<std::string> package_dirs_ = extract<std::string>(package_dirs);
return buildGeomFromUrdf(model,filename,package_dirs_,type);
}
......@@ -175,7 +175,7 @@ namespace pinocchio
const fcl::MeshLoaderPtr& meshLoader
)
{
std::vector<std::string> package_dirs_ = extractList<std::string>(package_dirs);
std::vector<std::string> package_dirs_ = extract<std::string>(package_dirs);
return buildGeomFromUrdf(model,filename,package_dirs_,type,meshLoader);
}
......
......@@ -7,27 +7,57 @@
#include "pinocchio/bindings/python/fwd.hpp"
#include <eigenpy/exception.hpp>
#include <boost/python.hpp>
#include <boost/python/type_id.hpp>
#include <vector>
#include <sstream>
#include <string>
namespace pinocchio
{
namespace python
{
namespace bp = boost::python;
template<typename T>
std::vector<T> extractList(const bp::list & input_list)
template<typename T, class Allocator>
void extract(const boost::python::list & list, std::vector<T,Allocator> & vec)
{
long size_list = bp::len(input_list);
std::vector<T> res((size_t)size_list);
for(long i = 0; i < size_list; ++i)
namespace bp = boost::python;
size_t size_list = (size_t)bp::len(list);
vec.resize(size_list);
for(size_t i = 0; i < size_list; ++i)
{
res.push_back(bp::extract<T>(input_list[i]));
bp::extract<T> input_T(list[i]);
if(input_T.check())
vec[i] = input_T();
else
{
const std::string classname
= bp::extract<std::string>(list[i].attr("__class__").attr("__name__"));
std::stringstream ss;
ss << "The conversion from " << classname << " to "
<< bp::type_id<T>().name() << " has failed." << std::endl;
throw eigenpy::Exception(ss.str());
}
}
return res;
}
template<typename T>
std::vector<T,std::allocator<T> > extract(const boost::python::list & list)
{
std::vector<T,std::allocator<T> > vec;
extract(list,vec);
return vec;
}
template<typename T, class Allocator>
std::vector<T,Allocator> extract(const boost::python::list & list)
{
std::vector<T,Allocator> vec;
extract(list,vec);
return vec;
}
} // namespace python
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment