2013-05-22 17:41:28 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <boost/python/list.hpp>
|
|
|
|
namespace python = boost::python;
|
|
|
|
|
|
|
|
namespace pykd {
|
|
|
|
|
|
|
|
template<typename T>
|
2013-09-11 16:09:27 +08:00
|
|
|
inline
|
2013-05-22 17:41:28 +08:00
|
|
|
python::list vectorToList( const std::vector<T> &v ) {
|
|
|
|
python::list lst;
|
|
|
|
for ( std::vector<T>::const_iterator it = v.begin(); it != v.end(); ++it )
|
|
|
|
lst.append( *it );
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2013-09-11 16:09:27 +08:00
|
|
|
inline
|
2013-05-22 17:41:28 +08:00
|
|
|
python::list vectorToList<char>( const std::vector<char> &v ) {
|
|
|
|
python::list lst;
|
|
|
|
for ( std::vector<char>::const_iterator it = v.begin(); it != v.end(); ++it )
|
|
|
|
lst.append( int(*it) );
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
2013-09-17 14:29:43 +08:00
|
|
|
|
2016-07-26 21:40:00 +08:00
|
|
|
template<typename T, typename TExtract=T>
|
2013-09-17 14:29:43 +08:00
|
|
|
inline
|
|
|
|
std::vector<T> listToVector( const python::list &lst )
|
|
|
|
{
|
|
|
|
std::vector<T> vec( python::len(lst) );
|
|
|
|
|
|
|
|
for ( long i = 0; i < python::len(lst); ++i )
|
|
|
|
{
|
2016-07-26 21:40:00 +08:00
|
|
|
T v = python::extract<TExtract>(lst[i]);
|
2013-09-17 14:29:43 +08:00
|
|
|
vec[i] =v;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2013-05-22 17:41:28 +08:00
|
|
|
} // end namespace pykd
|