osdir.com
mailing list archive

Subject: Newbie: Passing pointer arguments to C++ class member functions - msg#00028

List: programming.swig

Date: Prev Next Index Thread: Prev Next Index
hi,    I just started using SWIG. This might be a very simple problem but please bear with me. I have some C++ code that I need to use from C#. I have some member functions that take an unsigned int * and unsigned int & as parameters. Swig is creating a clas called SWIGTYPE_p_unit to represent these types. I cannot create an object of this SWIGTYPE_p_unit as it does not have a public constructor. Also even if I can create an object of SWIGTYPE_p_unit, it does not have a constructor that takes an unsigned  int. I read typemaps help out in some way, but not sure how to use them in C++ classes.   Example: C++ Class: class Test {    Test(){}    public:       int get_fetch_size(int &size); }   After running swig I get public void get_fetch_size(SWIGTYPE_p_int t) {    examplePINVOKE.Test_get_fetch_size(swigCPtr, SWIGTYPE_p_int.getCPtr(t)); }   thanx in advance, Satya.

Do you Yahoo!?
Check out the new Yahoo! Front Page. www.yahoo.com

Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

RE: default values in cvs version

>-----Original Message----- >From: swig-admin@xxxxxxxxxxxxxxx [mailto:swig-admin@xxxxxxxxxxxxxxx]On >Behalf Of Colin Smith >Sent: 03 November 2004 10:02 >To: swig@xxxxxxxxxxxxxxx >Subject: RE: [Swig] default values in cvs version > > > > >>-----Original Message----- >>From: William.Fulton@xxxxxxx [mailto:William.Fulton@xxxxxxx] >>Sent: Tuesday, November 02, 2004 5:32 PM >>To: Colin Smith; swig@xxxxxxxxxxxxxxx >>Subject: RE: [Swig] default values in cvs version >> >> >> >> >>>-----Original Message----- >>>From: swig-admin@xxxxxxxxxxxxxxx >[mailto:swig-admin@xxxxxxxxxxxxxxx]On >>>Behalf Of Colin Smith >>>Sent: 02 November 2004 17:27 >>>To: swig@xxxxxxxxxxxxxxx >>>Subject: [Swig] default values in cvs version >>> >>> >>>In versions of SWIG up to and including 1.3.22 the following >will work >>> >>> >>>%module test1 >>>%inline >>>%{ >>> extern "C" double func(double x,double p = 1) >>> { >>> return(x+p); >>> } >>>%} >>> >>>I.e. you can create a c++ wrapper and give defaults to the >>>wrapping of a c style function. However this does not work in >>>the CVS version (we have to remove the extern "C"). I have made >>>heavy use of this feature. When 1.3.23 is finished will the >>>feature work, or should I start thinking of other ways to do >what I do. >>> >>>By the way SWIG is a fanatstic tool and has saved me many hours... >>> > >>You can use the compact default arguments feature to get the >old behaviour: > >>%feature("compactdefaultargs"); // sets for all functions >>%feature("compactdefaultargs") func; // sets for just func > >>or you can use the the "default" typemap. > >>William > >Thanks William, your suggestion works in that simple example >which is a great relief, but with the very latest CVS version >I now get a core dump with my interface whether I add the >feature directive or not. I'll try and reproduce a small >example if I can; my interface has grown quite huge! > It looks as though Marcelo fixed this, if you can try again. William Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig

Next Message by Date: click to view message preview

Re: getting mangled string, not object, as return value

Marcelo Matus wrote, On 03/11/04 20:00: > I am not sure, but maybe with the last fixes in CVS, your case > will also get fixed. nope, unfortunately. i get a similar result, but now with SWIG_COBJECT_TYPES being defined the result of the cast_Base() is a PyCObject. same result as earlier if i undefine it. i'm attempting to produce a test-case, but my short version works, dammit. i'll keep working on it. cheers, /lib -- /lib BillClarke PostdoctoralFellow CompSci ANU cs.anu.edu.au/CC-NUMA http://llib.cjb.net llib@xxxxxxxxxxxx tel:+61-2-6125x5687 fax:x0010 PGPid:B381EE7DB7D3E58F17248C672E2DA124ADADF444 GNU unix LaTeX XPilot Buffy DrWho Goodies StarTrek XFiles Origami SML SMP MPI mozilla tcsh Asimov Bear Clarke Donaldson Volleyball Ultimate Cricket emacs C++ X Jordan Kay Lackey Martin Stasheff DeepPurple H&C KLF Queen PinkFloyd _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig

Previous Message by Thread: click to view message preview

Nested Modules in Python

Hello All, I have created some SWIG wrappers for different components in a library I am writing and would like to use nested modules to organize the python code. For example I am creating Vector.py and would like it to be in lib.math.Vector. I am running SWIG to generate the .py file in the lib\math directory and have setup a __init__.py file to include the Vector.py module. In other python code I import the module using import lib.math.Vector This all works great until I try to use this module (or object in the module like Vector4) in another SWIG module. In order to get it to work correctly I have to use the %import command in the .i file to import the Vector.i but since the module name is %module Vector in Vector.i the generated python imports Vector and not lib.math.Vector and will fail. And now to the question: Is there a way to support nested python modules in SWIG so that in Vector.i I can use %module lib.math.Vector (which doesn't compile) or in my %import force it to use lib.math.Vector instead of just vector? Thanks _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig

Next Message by Thread: click to view message preview

RE: Newbie: Passing pointer arguments to C++ class member functions

You've got to decide how you want to use the reference, either as an input only or output parameter. Use the typemaps in typemaps.i (CVS version or release candidate due out today or tomorrow is better). Read the documentation on pointer handling, especially in Java.html. William -----Original Message----- From: swig-admin@xxxxxxxxxxxxxxx [mailto:swig-admin@xxxxxxxxxxxxxxx]On Behalf Of satya gosula Sent: 04 November 2004 00:03 To: swig@xxxxxxxxxxxxxxx Subject: [Swig] Newbie: Passing pointer arguments to C++ class member functions hi, I just started using SWIG. This might be a very simple problem but please bear with me. I have some C++ code that I need to use from C#. I have some member functions that take an unsigned int * and unsigned int & as parameters. Swig is creating a clas called SWIGTYPE_p_unit to represent these types. I cannot create an object of this SWIGTYPE_p_unit as it does not have a public constructor. Also even if I can create an object of SWIGTYPE_p_unit, it does not have a constructor that takes an unsigned int. I read typemaps help out in some way, but not sure how to use them in C++ classes. Example: C++ Class: class Test { Test(){} public: int get_fetch_size(int &size); } After running swig I get public void get_fetch_size(SWIGTYPE_p_int t) { examplePINVOKE.Test_get_fetch_size(swigCPtr, SWIGTYPE_p_int.getCPtr(t)); } thanx in advance, Satya. Do you Yahoo!? Check out the new Yahoo! Front Page. www.yahoo.com</a Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by