i have c++ code returns boost::shared_ptr std::vector, unable swig wrap correctly make object iterable in python. without boost::shared_ptr works fine. know how wrap vector when it's inside shared_ptr?
here example demonstrating problem:
%module example %include <std_vector.i> %include <boost_shared_ptr.i> %shared_ptr(inner) %shared_ptr(innervector) %inline %{ #include <boost/shared_ptr.hpp> #include <vector> struct inner { int dummy; }; typedef std::vector< boost::shared_ptr<inner> > innervector; typedef boost::shared_ptr<innervector> innervectorptr; innervectorptr getvectorptr() { innervectorptr v(new innervector()); boost::shared_ptr<inner> i(new inner); i->dummy = 222; v->push_back(i); return v; } %} %template(innervector) ::std::vector< boost::shared_ptr<inner> >;
and example python script:
import example v = example.getvectorptr() print 'vector is:', v in v: print 'instance is:', print 'value is:', i.dummy
which me, says this:
vector is: <swig object of type 'innervectorptr *' @ 0x1127270> traceback (most recent call last): file "test.py", line 5, in <module> in v: typeerror: 'swigpyobject' object not iterable
any suggestions?
you might want try boost.python , py++. if using boost provides nice wrapping (and pretty automatic wrapping) of complex c++ constructs. have used in several projects.
also should take @ this question looks related not issue.
Comments
Post a Comment