From: Éric C. <eri...@vi...> - 2012-08-28 16:25:51
|
> Context: porting C++ code to C# > > > > Say I have many C++ classes with some member methods returning the type MyType: > > > > class Class1 > > { > > public: > > virtual MyType foo1(); > > virtual MyType foo2(); > > }; > > > > Say I have 100 classes like this. > > > > I am using the directorout typemap on this type like in the following: > > > > %typemap(directorout) MyType %{ > > $result = something... > > %} > > > > But I found a few cases where I would like to handle it differently. > > > > So in some of the 100 classes I would like the typemap to be the following instead: > > > > %typemap(directorout) MyType %{ > > $result = something else .... > > %} > > > > How can I do this ? > > > > i.e.: I would like to tell swig to apply a given %typemap(directorout) to some class methods but to use another %typemap(directorout) to other class methods, all for the same type (e.g.: MyType). > > > > The only thing I found is to use the $symname variable and do something ugly like this: > > > > %typemap(directorout) MyType %{ > > if( strcmp( "$symname", "foo1" ) == 0 ) > > $result = something... > > else > > $result = something else .... > > %} > > > > This is far from being perfect because two classes can have the method foo1 but different handling may be desired and calling strcmp all the time is slow. > > > > I wish there was a way to do something like: > > > > %typemap(directorout) MyType Class1::*, Class2::foo1, Class2::foo3 %{ > > $result = something... > > %} > > > > %typemap(directorout) MyType Class2::foo2, Class3::* %{ > > $result = something else... > > %} > > > > Thanks ! |
From: William S F. <ws...@fu...> - 2012-08-31 20:08:22
|
On 28/08/12 16:50, Éric Cabot wrote: >> Context: porting C++ code to C# >> >> Say I have many C++ classes with some member methods returning the >> type MyType: >> >> class Class1 >> >> { >> >> public: >> >> virtual MyType foo1(); >> >> virtual MyType foo2(); >> >> }; >> >> Say I have 100 classes like this. >> >> I am using the directorout typemap on this type like in the following: >> >> %typemap(directorout) MyType %{ >> >> $result = something... >> >> %} >> >> But I found a few cases where I would like to handle it differently. >> >> So in some of the 100 classes I would like the typemap to be the >> following instead: >> >> %typemap(directorout) MyType %{ >> >> $result = something *else* .... >> >> %} >> >> How can I do this ? >> >> i.e.: I would like to tell swig to apply a given %typemap(directorout) >> to some class methods but to use another %typemap(directorout) to >> other class methods, all for the same type (e.g.: MyType). >> >> The only thing I found is to use the $symname variable and do >> something ugly like this: >> >> %typemap(directorout) MyType %{ >> >> if( strcmp( "$symname", "foo1" ) == 0 ) >> >> $result = something... >> >> else >> >> $result = something else .... >> >> %} >> >> This is far from being perfect because two classes can have the method >> foo1 but different handling may be desired and calling strcmp all the >> time is slow. >> >> I wish there was a way to do something like: >> >> %typemap(directorout) MyType *Class1::*, Class2::foo1, Class2::foo3* %{ >> >> $result = something... >> >> %} >> >> %typemap(directorout) MyType *Class2::foo2, Class3::** %{ >> >> $result = something else... >> >> %} There is. Read about the typemap pattern matching rules in http://www.swig.org/Doc2.0/Typemaps.html. Hint -debug-tmsearch will help. William |
From: Marvin G. <pub...@gm...> - 2012-09-04 11:57:22
|
On 12/Aug/31 4:08 PM, William S Fulton wrote: > On 28/08/12 16:50, Éric Cabot wrote: > There is. Read about the typemap pattern matching rules in > http://www.swig.org/Doc2.0/Typemaps.html. Hint -debug-tmsearch will help. > But see my post. It seems like something in what is being passed for directorout does not include the method name when doing the search. Marvin |
From: <eri...@vi...> - 2012-09-05 15:52:17
|
Thank you guys for your feedback. You are right Marvin the %typemap(out) seems to support a signature like "MyType MyClass::MyFunction" but effectively the %typemap(directorout) seems not. But even if it did there are still other cases where I don't know how to specify the method name. For instance consider the following two methods of the same class. int foo1( Type value ); int foo2( Type value ); Say I want to apply a different "%typemap(in) Type" to each method how can I do this with the argument name being the same ? BTW in my case I cannot write an interface file so I'm stuck with doing a %include of the original C++ .h file that has those two methods. William I did look at the typemap pattern matching rules in http://www.swig.org/Doc2.0/Typemaps.html but I found nothing about specifying method names in there. Did I just miss it? Thanks ----- Message d'origine ----- De: Marvin Greenberg <pub...@gm...> Date: Mardi, 4 Septembre 2012, 7:57 am Objet: Re: [Swig-user] How can I specify different typemaps depending on the method being wrapped ? À: William S Fulton <ws...@fu...> Cc: Éric Cabot <eri...@vi...>, "swi...@li..." <swi...@li...> > On 12/Aug/31 4:08 PM, William S Fulton wrote: > >On 28/08/12 16:50, Éric Cabot wrote: > >There is. Read about the typemap pattern matching rules in > >http://www.swig.org/Doc2.0/Typemaps.html. Hint -debug-tmsearch > will help. > > > But see my post. It seems like something in what is being > passed for directorout does not include the method name when > doing the search. > > Marvin |
From: Marvin G. <pub...@gm...> - 2012-09-05 16:39:07
|
On 12/Sep/5 11:52 AM, eri...@vi... wrote: > Thank you guys for your feedback. > You are right Marvin the %typemap(out) seems to support a signature like > "MyType MyClass::MyFunction" but effectively the %typemap(directorout) seems not. > But even if it did there are still other cases where I don't know how to > specify the method name. > For instance consider the following two methods of the same class. > int foo1( Type value ); > int foo2( Type value ); > Say I want to apply a different "%typemap(in) Type" to each method how can I > do this with the argument name being the same ? > BTW in my case I cannot write an interface file so I'm stuck with doing a > %include of the original C++ .h file that has those two methods. > Hmm. Although you say you are stuck including the original .h file, obviously you are not. You could copy it, run it through sed, apply patches, etc. If you look at the documentation section "5.7 An interface building strategy", and especially "5.7.3 Why use separate interface files" it recommends that you write separate interface files. We're doing fairly complicated stuff with swig, wrapping static and generated c++ APIs, and we use separate interface files to give us control over exactly how parts of the wrappers get generated. So you COULD rename, from your example, int foo1(Type special_arg); int foo2(Type special_arg); int foo3(Type plain_arg); And then "in" typemaps to apply differently would be possible. Note my extension of the example -- by rewriting the argument names, the interface itself now is self-documenting at when you are using the different typemaps. |
From: <eri...@vi...> - 2012-09-05 17:07:02
|
The "copy, sed, patches" strategy is actually the strategy that I was about to deploy after all in my environment so I'm really happy to see it's in line with the recommended strategy. But being able to specify the method name in the %typemap would just have been much simpler to deploy in my situation so I wanted to see first if this was possible. But if it's not possible then I will go with the full solution. Thanks ! ----- Message d'origine ----- De: Marvin Greenberg <pub...@gm...> Date: Mercredi, 5 Septembre 2012, 12:38 pm Objet: Re: Re : Re: [Swig-user] How can I specify different typemaps depending on the method being wrapped ? À: eri...@vi... Cc: William S Fulton <ws...@fu...>, "swi...@li..." <swi...@li...> > On 12/Sep/5 11:52 AM, eri...@vi... wrote: > >Thank you guys for your feedback. > >You are right Marvin the %typemap(out) seems to support a > signature like "MyType MyClass::MyFunction" but effectively the > %typemap(directorout) seems not. > >But even if it did there are still other cases where I don't > know how to specify the method name. > >For instance consider the following two methods of the same class. > >int foo1( Type value ); > >int foo2( Type value ); > >Say I want to apply a different "%typemap(in) Type" to each > method how can I do this with the argument name being the same ? > >BTW in my case I cannot write an interface file so I'm stuck > with doing a %include of the original C++ .h file that has those > two methods. > > > Hmm. Although you say you are stuck including the original > .h file, obviously you are not. You could copy it, run it > through sed, apply patches, etc. > > If you look at the documentation section "5.7 An interface > building strategy", and especially "5.7.3 Why use separate > interface files" it recommends that you write separate interface > files. We're doing fairly complicated stuff with swig, > wrapping static and generated c++ APIs, and we use separate > interface files to give us control over exactly how parts of the > wrappers get generated. So you COULD rename, from your example, > > int foo1(Type special_arg); > int foo2(Type special_arg); > int foo3(Type plain_arg); > > And then "in" typemaps to apply differently would be possible. > Note my extension of the example -- by rewriting the argument > names, the interface itself now is self-documenting at when you > are using the different typemaps. > |
From: William S F. <ws...@fu...> - 2012-10-27 19:44:31
|
Post processing the wrappers isn't really the recommended strategy as it indicates something wrong in SWIG. In this case it is a bug and I have fixed it for swig-2.0.9 so that named 'directorout' typemaps are found during the typemap search. Hence they now behave the same as named 'out' typemaps. William On 05/09/12 18:06, eri...@vi... wrote: > The "copy, sed, patches" strategy is actually the strategy that I was > about to deploy after all in my environment so I'm really happy to see > it's in line with the recommended strategy. > But being able to specify the method name in the %typemap would just > have been much simpler to deploy in my situation so I wanted to see > first if this was possible. > But if it's not possible then I will go with the full solution. > Thanks ! > ----- Message d'origine ----- > De: Marvin Greenberg <pub...@gm...> > Date: Mercredi, 5 Septembre 2012, 12:38 pm > Objet: Re: Re : Re: [Swig-user] How can I specify different typemaps > depending on the method being wrapped ? > À: eri...@vi... > Cc: William S Fulton <ws...@fu...>, > "swi...@li..." <swi...@li...> > > > On 12/Sep/5 11:52 AM, eri...@vi... wrote: > > >Thank you guys for your feedback. > > >You are right Marvin the %typemap(out) seems to support a > > signature like "MyType MyClass::MyFunction" but effectively the > > %typemap(directorout) seems not. > > >But even if it did there are still other cases where I don't > > know how to specify the method name. > > >For instance consider the following two methods of the same class. > > >int foo1( Type value ); > > >int foo2( Type value ); > > >Say I want to apply a different "%typemap(in) Type" to each > > method how can I do this with the argument name being the same ? > > >BTW in my case I cannot write an interface file so I'm stuck > > with doing a %include of the original C++ .h file that has those > > two methods. > > > > > Hmm. Although you say you are stuck including the original > > .h file, obviously you are not. You could copy it, run it > > through sed, apply patches, etc. > > > > If you look at the documentation section "5.7 An interface > > building strategy", and especially "5.7.3 Why use separate > > interface files" it recommends that you write separate interface > > files. We're doing fairly complicated stuff with swig, > > wrapping static and generated c++ APIs, and we use separate > > interface files to give us control over exactly how parts of the > > wrappers get generated. So you COULD rename, from your example, > > > > int foo1(Type special_arg); > > int foo2(Type special_arg); > > int foo3(Type plain_arg); > > > > And then "in" typemaps to apply differently would be possible. > > Note my extension of the example -- by rewriting the argument > > names, the interface itself now is self-documenting at when you > > are using the different typemaps. > > |
From: Eric C. <Eri...@au...> - 2012-10-29 21:01:18
|
Oh that's great ! Just today I found a need for this named %typemap(directorout) ! Do you think I could have the code/patch so I can start using it ? Thanks a lot William ! ÉC -----Original Message----- From: William S Fulton [mailto:ws...@fu...] Sent: Saturday, October 27, 2012 3:44 PM To: eri...@vi... Cc: swi...@li... Subject: Re: [Swig-user] Re : Re: Re : Re: How can I specify different typemaps depending on the method being wrapped ? Post processing the wrappers isn't really the recommended strategy as it indicates something wrong in SWIG. In this case it is a bug and I have fixed it for swig-2.0.9 so that named 'directorout' typemaps are found during the typemap search. Hence they now behave the same as named 'out' typemaps. William On 05/09/12 18:06, eri...@vi... wrote: > The "copy, sed, patches" strategy is actually the strategy that I was > about to deploy after all in my environment so I'm really happy to see > it's in line with the recommended strategy. > But being able to specify the method name in the %typemap would just > have been much simpler to deploy in my situation so I wanted to see > first if this was possible. > But if it's not possible then I will go with the full solution. > Thanks ! > ----- Message d'origine ----- > De: Marvin Greenberg <pub...@gm...> > Date: Mercredi, 5 Septembre 2012, 12:38 pm > Objet: Re: Re : Re: [Swig-user] How can I specify different typemaps > depending on the method being wrapped ? > À: eri...@vi... > Cc: William S Fulton <ws...@fu...>, > "swi...@li..." <swi...@li...> > > > On 12/Sep/5 11:52 AM, eri...@vi... wrote: > > >Thank you guys for your feedback. > > >You are right Marvin the %typemap(out) seems to support a > > signature like "MyType MyClass::MyFunction" but effectively the > > %typemap(directorout) seems not. > > >But even if it did there are still other cases where I don't > > know how to specify the method name. > > >For instance consider the following two methods of the same class. > > >int foo1( Type value ); > > >int foo2( Type value ); > > >Say I want to apply a different "%typemap(in) Type" to each > > method how can I do this with the argument name being the same ? > > >BTW in my case I cannot write an interface file so I'm stuck > > with doing a %include of the original C++ .h file that has those > > two methods. > > > > > Hmm. Although you say you are stuck including the original > .h > file, obviously you are not. You could copy it, run it > through sed, > apply patches, etc. > > > > If you look at the documentation section "5.7 An interface > > building strategy", and especially "5.7.3 Why use separate > > interface files" it recommends that you write separate interface > > files. We're doing fairly complicated stuff with swig, > wrapping > static and generated c++ APIs, and we use separate > interface files > to give us control over exactly how parts of the > wrappers get > generated. So you COULD rename, from your example, > > int foo1(Type > special_arg); > int foo2(Type special_arg); > int foo3(Type > plain_arg); > > And then "in" typemaps to apply differently would be > possible. > > Note my extension of the example -- by rewriting the argument > > names, the interface itself now is self-documenting at when you > are > using the different typemaps. > > ------------------------------------------------------------------------------ WINDOWS 8 is here. Millions of people. Your app in 30 days. Visit The Windows 8 Center at Sourceforge for all your go to resources. http://windows8center.sourceforge.net/ join-generation-app-and-make-money-coding-fast/ _______________________________________________ Swig-user mailing list Swi...@li... https://lists.sourceforge.net/lists/listinfo/swig-user |
From: William S F. <ws...@fu...> - 2012-10-30 19:31:20
|
It is checked in on trunk in a very recent commit, just check the logs. William On 29/10/12 21:01, Eric Cabot wrote: > Oh that's great ! > > Just today I found a need for this named %typemap(directorout) ! > > Do you think I could have the code/patch so I can start using it ? > > Thanks a lot William ! > > ÉC > -----Original Message----- > From: William S Fulton [mailto:ws...@fu...] > Sent: Saturday, October 27, 2012 3:44 PM > To: eri...@vi... > Cc: swi...@li... > Subject: Re: [Swig-user] Re : Re: Re : Re: How can I specify different typemaps depending on the method being wrapped ? > > Post processing the wrappers isn't really the recommended strategy as it indicates something wrong in SWIG. In this case it is a bug and I have fixed it for swig-2.0.9 so that named 'directorout' typemaps are found during the typemap search. Hence they now behave the same as named 'out' > typemaps. > > William > > On 05/09/12 18:06, eri...@vi... wrote: >> The "copy, sed, patches" strategy is actually the strategy that I was >> about to deploy after all in my environment so I'm really happy to see >> it's in line with the recommended strategy. >> But being able to specify the method name in the %typemap would just >> have been much simpler to deploy in my situation so I wanted to see >> first if this was possible. >> But if it's not possible then I will go with the full solution. >> Thanks ! >> ----- Message d'origine ----- >> De: Marvin Greenberg <pub...@gm...> >> Date: Mercredi, 5 Septembre 2012, 12:38 pm >> Objet: Re: Re : Re: [Swig-user] How can I specify different typemaps >> depending on the method being wrapped ? >> À: eri...@vi... >> Cc: William S Fulton <ws...@fu...>, >> "swi...@li..." <swi...@li...> >> >> > On 12/Sep/5 11:52 AM, eri...@vi... wrote: >> > >Thank you guys for your feedback. >> > >You are right Marvin the %typemap(out) seems to support a > >> signature like "MyType MyClass::MyFunction" but effectively the > >> %typemap(directorout) seems not. >> > >But even if it did there are still other cases where I don't > >> know how to specify the method name. >> > >For instance consider the following two methods of the same class. >> > >int foo1( Type value ); >> > >int foo2( Type value ); >> > >Say I want to apply a different "%typemap(in) Type" to each > >> method how can I do this with the argument name being the same ? >> > >BTW in my case I cannot write an interface file so I'm stuck > >> with doing a %include of the original C++ .h file that has those > >> two methods. >> > > >> > Hmm. Although you say you are stuck including the original > .h >> file, obviously you are not. You could copy it, run it > through sed, >> apply patches, etc. >> > >> > If you look at the documentation section "5.7 An interface > >> building strategy", and especially "5.7.3 Why use separate > >> interface files" it recommends that you write separate interface > >> files. We're doing fairly complicated stuff with swig, > wrapping >> static and generated c++ APIs, and we use separate > interface files >> to give us control over exactly how parts of the > wrappers get >> generated. So you COULD rename, from your example, > > int foo1(Type >> special_arg); > int foo2(Type special_arg); > int foo3(Type >> plain_arg); > > And then "in" typemaps to apply differently would be >> possible. >> > Note my extension of the example -- by rewriting the argument > >> names, the interface itself now is self-documenting at when you > are >> using the different typemaps. >> > > > > ------------------------------------------------------------------------------ > WINDOWS 8 is here. > Millions of people. Your app in 30 days. > Visit The Windows 8 Center at Sourceforge for all your go to resources. > http://windows8center.sourceforge.net/ > join-generation-app-and-make-money-coding-fast/ > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > |
From: Marvin G. <pub...@gm...> - 2012-08-31 18:42:39
|
On 12/Aug/28 11:50 AM, Éric Cabot wrote: >> >> Context: porting C++ code to C# >> >> Say I have many C++ classes with some member methods returning the type MyType: >> >> class Class1 >> >> { >> >> public: >> >> virtual MyType foo1(); >> >> virtual MyType foo2(); >> >> }; >> >> Say I have 100 classes like this. >> >> I am using the directorout typemap on this type like in the following: >> >> %typemap(directorout) MyType %{ >> >> $result = something... >> >> %} >> >> But I found a few cases where I would like to handle it differently. >> >> So in some of the 100 classes I would like the typemap to be the following >> instead: >> >> %typemap(directorout) MyType %{ >> >> $result = something *else* .... >> >> %} >> >> How can I do this ? >> >> i.e.: I would like to tell swig to apply a given %typemap(directorout) to >> some class methods but to use another %typemap(directorout) to other class >> methods, all for the same type (e.g.: MyType). >> >> The only thing I found is to use the $symname variable and do something ugly >> like this: >> >> %typemap(directorout) MyType %{ >> >> if( strcmp( "$symname", "foo1" ) == 0 ) >> >> $result = something... >> >> else >> >> $result = something else .... >> >> %} >> >> This is far from being perfect because two classes can have the method foo1 >> but different handling may be desired and calling strcmp all the time is slow. >> >> I wish there was a way to do something like: >> >> %typemap(directorout) MyType *Class1::*, Class2::foo1, Class2::foo3* %{ >> >> $result = something... >> >> %} >> >> %typemap(directorout) MyType *Class2::foo2, Class3::** %{ >> >> $result = something else... >> >> %} >> >> Thanks ! >> > Hmm. I assumed you can mostly do what you want, but looking at the debug output, I see it works for "out" and "javaout" (and presumably csout), but not "directorout". I ran swig with -debug-tmsearch on one of our interface files and see pages of output like... > RemoteMethodsInterface.i:66: Searching for a suitable 'out' typemap for: > Example::AreaOfEffect::ImmutableLocalClassPtr const > Example::Tank::RemoteMethodsInterface::fireGun > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr const > Example::Tank::RemoteMethodsInterface::fireGun > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr const fireGun > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr const > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr > Example::Tank::RemoteMethodsInterface::fireGun > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr fireGun > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr ... Note that it is proving the method name and the class-qualified name to search. I get similar results for 'javaout' typemap searches, but the directorout typemap searches look like: > RemoteMethodsInterface.i:66: Searching for a suitable 'directorout' typemap > for: Example::AreaOfEffect::ImmutableLocalClassPtr const c_result > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr const c_result > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr const > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr c_result > Looking for: Example::AreaOfEffect::ImmutableLocalClassPtr ... So, except for directorout, you COULD do (for example) %typemap(out) MyType Class2::foo2, MyType foo, MyType Class3::foo4 %{ special; } %typemap(out) MyType %{ everything else; } I don't know why the directorout typemap doesn't provide the context of the method name. The c_result bit must be something coming from the code generating the director wrapper code -- it isn't in my interface. It may just be a bug or artifact of something that causes swig to lose the method name context. marvin |