|
From: Eileen W. <ew...@Fe...> - 2011-04-20 20:34:16
|
I want SWIG to generate wrapper for me for most of the declarations in my "header.h" (C++) file, so I do %include "header.h", but I also need to change some of the default behaviour of SWIG on some of the functions defined in the header file, like using typemap and %rename, how can I tell SWIG to apply the changes ``ONLY`` on certain functions?
-----Original Message-----
From: Eileen Wei
Sent: April-20-11 11:57 AM
To: Alan W. Irwin
Cc: swi...@li...
Subject: Re: [Swig-user] How to use typemap only on a specified function?
I thought it might be clearer to put the whole interface file here:
// interface.i ////////////////////
%apply double& OUTPUT { double& result1 };
%rename(result1_input) result1;
%apply double& OUTPUT { double& result2 };
extern static bool foo2(const double& result1, double& result2 );
%include "header.h"
//////////////////////////////////
As I have the %include "header.h" at the end of the interface file, I am not sure how %rename work on other functions in the header.h file including foo1?
Thanks,
Eileen
-----Original Message-----
From: Eileen Wei
Sent: April-20-11 11:39 AM
To: Alan W. Irwin
Cc: swi...@li...
Subject: Re: [Swig-user] How to use typemap only on a specified function?
Hi Alan,
Since "%rename applies a renaming operation to all future occurrences of a name", if in the .i file I do this:
// interface.i ////////////////////
%rename(result1_input) result1;
%apply double& OUTPUT { double& result2 };
extern static bool foo2(const double& result1, double& result2 );
%include "header.h"
//////////////////////////////////
Would this change foo1 as well? How can I make sure that the rename only applies to foo2 and not other functions?
Thanks,
Eileen
-----Original Message-----
From: Alan W. Irwin [mailto:ir...@be...]
Sent: April-19-11 3:16 PM
To: Eileen Wei
Cc: swi...@li...
Subject: Re: [Swig-user] How to use typemap only on a specified function?
On 2011-04-19 13:49-0600 Eileen Wei wrote:
>
> Hi,
>
>
>
> I am wrapping a C++ header file to Python.
>
>
>
> In my .h file I have two functions defined like this:
>
>
>
> static bool foo1(
>
> const double& parm1,
>
> double& result1 );
>
> static bool foo2(
>
> const double& result1,
>
> double& result2 );
>
>
>
> So result1 is a return value in function foo1, but an input parameter in function foo2.
>
>
>
> If I do
>
> %apply double& OUTPUT { double& result1 };
>
>
>
> It will not only change the behaviour of foo1 to return 2 values, but it will also affect foo2, which I don’t want.
>
>
>
> My question is how can I specify that this typemap only applies to foo1 and not other functions in the .h file?
Hi Eileen:
Rename result1 to something else in the foo2 argument list so the two
qualitatively different kinds of arguments in your API that need
different swig treatments have different signatures.
For our project (PLplot), we take this approach to an extreme. We have
a special plplotcapi.i file which pretty much follows our principal
*.h header file for the PLplot library. But plplotcapi.i renames
arguments so that each specific kind of argument (there are not that
many of them) that we have in our API has a unique argument signature.
We then include the plplotcapi.i file for each of our swig-generated
language interfaces (Python, Java, Lua, and Octave), and for each
language specify appropriate typemaps (when necessary) for each
specific kind of argument signature that is mentioned in the
plplotcapi.i file.
Alan
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________
Linux-powered Science
__________________________
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Swig-user mailing list
Swi...@li...
https://lists.sourceforge.net/lists/listinfo/swig-user
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Swig-user mailing list
Swi...@li...
https://lists.sourceforge.net/lists/listinfo/swig-user
|