From: William S F. <ws...@fu...> - 2005-11-10 22:17:48
|
Wes Hodges wrote: > hey all: > > i have a question about std_vector.i and, unfortunately, time is of the > essence. here's my situation: > > in C++, i've have a function MyFunc defined in MyFile.h that takes > vector of MyClass* pointers as a parameter (MyClass is also defined in > MyFile.h). i.e.: > > void MyFunc(const std::vector<MyClass*>& objects) > > now, here's the generated C# function i get when i SWIG MyFunc: > > public void MyFunc(SWIGTYPE_P_std__vectorTMyClass_p_t objects) > > seems to make sense. MyClass_p i guess means a pointer to a MyClass > object, and the other _P_ probably means it treats the vector as a > pointer so it can handle it as an int. ok. now, i'm also using > std_vector.i, which, so far, looks like a fantastic piece of work. i've > set up my SWIG .i file to use it as follows: > > %module MyModule > > %{ > #include "MyFile.h" > %} > > %include "std_string.i" // I'm using this, not sure if it matters > %include "std_vector.i" > > namespace std { > %template(MyClassVector) vector<MyClass>; // I guess this is right, > since vector<MyClass*> fails to build. So, I'm assuming this is asking > for the C# version of MyClass. > } > > %include "MyFile.h" > > in my C# code, i'm now free to use MyClassVector objects and interact > with them exactly as if they were ArrayList objects, and that's great. > but, if i try to do this in C#: > > MyClassVector v = new MyClassVector( ); > MyClass o = new MyClass( ); > > v.Add(o); > > MyFunc(v); // Compile error - expecting > SWIGTYPE_P_std__vectorTMyClass_p_t, not MyClassVector > > this also makes sense to me, because i guess i haven't told SWIG that > MyClassVector can be substituted for SWIGTYPE_P_std__vectorTMyClass_p_t, > and how it should do that substitution. i was hoping that i was maybe > living in magic happy land where it was just done automatically for me. > :) so, my question: how do i tell SWIG to do that? how do i get > MyFunc to take a MyClassVector object as a parameter? typemaps? again, > i'll take any reply i can get, as soon as i can get it. i've got 12 > hours before i have to go away for the next couple days... > > The pointer reference typemaps you need still have to be added to SWIG. Meanwhile, you can get them from here: http://mailman.cs.uchicago.edu/pipermail/swig/2004-November/010861.html You might want to try using SWIGTYPE*& instead of the macro with CTYPE. This means it will work without using the macro, ie these typemaps will apply to all pointer references. William |