From: John B. <joh...@gm...> - 2011-01-27 16:14:22
|
Hello, I have a templated functions which i'm perfectly able to Swig for python. However I also have a function which has a boost::shared_ptr as a return value. The return value even constist of a template class. So in code: template<class PR> boost::shared_ptr<list<PR> > Application::GetList() { boost::shared_ptr<list<PR> > myList; return myList; } I can use and define the list<PR> in the application.i SWIG file. %template(recordlist) list<Record>; So I thought i might try to use the shared_ptr as following: %include "boost_shared_ptr.i" %shared_ptr(recordlist) Without any luck, I also tried the following: %shared_ptr(list<Record>) %shared_ptr(list<PR>) But it doesn't matter. Can someone tell me how to solve this issue ??? John |
From: William S F. <ws...@fu...> - 2011-01-29 16:41:23
|
On 27/01/11 16:14, John Beuving wrote: > Hello, > > I have a templated functions which i'm perfectly able to Swig for python. > However I also have a function which has a boost::shared_ptr as a return > value. > The return value even constist of a template class. > > So in code: > > template<class PR> > boost::shared_ptr<list<PR> > Application::GetList() > { > boost::shared_ptr<list<PR> > myList; > > return myList; > } > > > I can use and define the list<PR> in the application.i SWIG file. > %template(recordlist) list<Record>; > > So I thought i might try to use the shared_ptr as following: > %include "boost_shared_ptr.i" > %shared_ptr(recordlist) > > Without any luck, I also tried the following: > %shared_ptr(list<Record>) > %shared_ptr(list<PR>) > I'd expect this to work: %include "boost_shared_ptr.i" ... definition of list<> ... ... definition of Record ... %template(recordlist) list<Record>; %shared_ptr(list<Record>) template<class PR> boost::shared_ptr<list<PR> > Application::GetList() { boost::shared_ptr<list<PR> > myList; return myList; } Does this not work? William |
From: John B. <joh...@gm...> - 2011-01-31 16:01:07
|
Hi, As I mentioned before, this was one of my guesses. Unfortunatly none of them worked. I worked around it by spending some time to completely remove all boost::auto_ptr return values. This seemed like the only way. John Op 29-1-2011 17:41, William S Fulton schreef: > On 27/01/11 16:14, John Beuving wrote: >> Hello, >> >> I have a templated functions which i'm perfectly able to Swig for >> python. >> However I also have a function which has a boost::shared_ptr as a return >> value. >> The return value even constist of a template class. >> >> So in code: >> >> template<class PR> >> boost::shared_ptr<list<PR> > Application::GetList() >> { >> boost::shared_ptr<list<PR> > myList; >> >> return myList; >> } >> >> >> I can use and define the list<PR> in the application.i SWIG file. >> %template(recordlist) list<Record>; >> >> So I thought i might try to use the shared_ptr as following: >> %include "boost_shared_ptr.i" >> %shared_ptr(recordlist) >> >> Without any luck, I also tried the following: >> %shared_ptr(list<Record>) >> %shared_ptr(list<PR>) >> > > I'd expect this to work: > > %include "boost_shared_ptr.i" > > ... definition of list<> ... > ... definition of Record ... > %template(recordlist) list<Record>; > > %shared_ptr(list<Record>) > > template<class PR> > boost::shared_ptr<list<PR> > Application::GetList() > { > boost::shared_ptr<list<PR> > myList; > > return myList; > } > > Does this not work? > > William |
From: William S F. <ws...@fu...> - 2011-02-03 20:52:58
|
You really shouldn't have to remove shared_ptr from your code. Here is a working example... %module example %include "boost_shared_ptr.i" %inline %{ #include <boost/shared_ptr.hpp> template<typename T> class list { public: T singleElement; list(T t) : singleElement(t) {} }; struct Record { int value; Record(int val = 0) : value(val) {} }; %} %shared_ptr(list<Record>) %template(recordlist) list<Record>; %inline %{ namespace Application { template<class PR> boost::shared_ptr<list<PR> > GetList(); } template<class PR> boost::shared_ptr<list<PR> > Application::GetList() { boost::shared_ptr<list<PR> > myList(new list<Record>(Record(123))); return myList; } %} %template(GetListRecord) Application::GetList<Record>; Python code: from example import * print "starting" l = GetListRecord(); print l.singleElement.value print "finished" $ python runme.py starting 123 finished William On 31/01/11 16:01, John Beuving wrote: > Hi, > > As I mentioned before, this was one of my guesses. Unfortunatly none of > them worked. > I worked around it by spending some time to completely remove all > boost::auto_ptr return values. > This seemed like the only way. > > John > > Op 29-1-2011 17:41, William S Fulton schreef: >> On 27/01/11 16:14, John Beuving wrote: >>> Hello, >>> >>> I have a templated functions which i'm perfectly able to Swig for >>> python. >>> However I also have a function which has a boost::shared_ptr as a return >>> value. >>> The return value even constist of a template class. >>> >>> So in code: >>> >>> template<class PR> >>> boost::shared_ptr<list<PR> > Application::GetList() >>> { >>> boost::shared_ptr<list<PR> > myList; >>> >>> return myList; >>> } >>> >>> >>> I can use and define the list<PR> in the application.i SWIG file. >>> %template(recordlist) list<Record>; >>> >>> So I thought i might try to use the shared_ptr as following: >>> %include "boost_shared_ptr.i" >>> %shared_ptr(recordlist) >>> >>> Without any luck, I also tried the following: >>> %shared_ptr(list<Record>) >>> %shared_ptr(list<PR>) >>> >> >> I'd expect this to work: >> >> %include "boost_shared_ptr.i" >> >> ... definition of list<> ... >> ... definition of Record ... >> %template(recordlist) list<Record>; >> >> %shared_ptr(list<Record>) >> >> template<class PR> >> boost::shared_ptr<list<PR> > Application::GetList() >> { >> boost::shared_ptr<list<PR> > myList; >> >> return myList; >> } >> >> Does this not work? >> >> William > > |