logo       

Re: SWIG-PERL-Vector of pointers: msg#00126

programming.swig

Subject: Re: SWIG-PERL-Vector of pointers

On 2003.11.18 22:37, "Nair, Sanjay S" wrote:
Types generated by const and non const vectors are different

int ABC( std::vector<unsigned char>& pvReadArray,
const std::vector<unsigned char>& pvWriteArray);

Any idea why the type checking is different?

When a function takes a const vector&, it is possible to pass it either a wrapped std::vector or a Perl array. When it takes a vector&, it will probably want to modify it, therefore only a wrapped std::vector can be passed (conversion from Perl array to std::vector would pass a *copy* of the original array to the function.)

If you want to make them the same, just cheat and declare the function in your SWIG interface file as:

int ABC(std::vector<unsigned char>& pvReadArray,
std::vector<unsigned char>& pvWriteArray);

The generated wrappers won't break const-correctness for the compiler.

(incidentally, I was about to suggest you a better method of specifying which code to generate, but I just found out it doesn't work. I'll have to check with someone working with SWIG internals. But in the meantime, the above should work well enough.)

Cheers,
Luigi
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise