mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00

kdlib commit (functions + tests) git-svn-id: https://pykd.svn.codeplex.com/svn@91016 9b283d60-5439-405e-af05-b73fd8c4d996
45 lines
960 B
C++
45 lines
960 B
C++
#pragma once
|
|
|
|
#include <vector>
|
|
|
|
#include <boost/python/list.hpp>
|
|
namespace python = boost::python;
|
|
|
|
namespace pykd {
|
|
|
|
template<typename T>
|
|
inline
|
|
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<>
|
|
inline
|
|
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;
|
|
}
|
|
|
|
|
|
template<typename T, typename TExtract=T>
|
|
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 )
|
|
{
|
|
T v = python::extract<TExtract>(lst[i]);
|
|
vec[i] =v;
|
|
}
|
|
|
|
return vec;
|
|
}
|
|
|
|
} // end namespace pykd
|