From: Marcelo M. <mm...@ac...> - 2006-02-01 23:07:03
|
Template use refers to something like %extend Foo { %typemap(out, fragment=SWIGTraits{_Type}) iterator { return swig::traits_from<_Type>::from(*$1); } } template <class _Type> struct Foo { _Type get_value(); }; %template(Foo_A) Foo<A>; here, to output iterator, swig will call PyObject * _wrap_Foo_A_get_value() { ... result = swig::traits_from<_Type>::from(*$1); ... } where 'swig::traits_from' can be a default struct or rewrite by using %fragment(SWIGTraits{A},"header") { template<> struct traits_from<A> { PyObject *from(const A& a) {....} }; } Marcelo William S Fulton wrote: > I don't follow. If a fragment is needed, template or not, it must be > generated. Do you have an example. Below is my template example... > > William > > %fragment("testfragment","header") { > void testfragment() {} > } > > %typemap(in, fragment="testfragment") Foo<double> & { > testfragment(); > $1 = *(Foo<double> **)(void *)&$input; > } > > > %inline %{ > template <typename T> struct Foo { T* t; }; > void method(Foo<double> &f) {} > %} > > Marcelo Matus wrote: > >> Not necessary, if a template request a fragment, it could not exist, >> and the >> the 'code' by default will be used. This is similar to the typemaps, >> if a typemap >> doesn't exist, the SWIGTYPE type is used. >> >> Marcelo >> >> >> William S Fulton wrote: >> >>> Marcelo Matus wrote: >>> >>>> Update of /cvsroot/swig/SWIG/Source/Include >>>> In directory >>>> sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19105/Source/Include >>>> >>>> Modified Files: >>>> swigwarn.h Log Message: >>>> add fragment warning and fixes >>>> >>> >>> Great. Shouldn't it be an error rather than a warning though? If a >>> frament is missing, it is pretty serious as the generated code is >>> highly unlikely to compile then. >>> >>> William >> >> >> >> > |