Swig C++ ->C# operator problem

View: New views
2 Messages — Rating Filter:   Alert me  

Swig C++ ->C# operator problem

by Giorgio S :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm porting a big C++ library to either Python and C#.
In Python the wrapping of C++ operators is just some lines of %rename.

But in C#, SWIG does not accept:
     %rename(operator =) *::operator =

(which is basically what I need).

What I do now is:
    %rename(some_dummy_name) *::operator =
and
    %typemap(cscode) ClassName %{ .... }%

for each class (and they are a lot!) and for each operator (=, ==, +,
+=, [], () etc etc).
I could have used SWIGTYPE (instead of ClassName) in %typemap, but
not all classes supports all operators (take for example std::vector).
Is there a better way to make this process automatic?
I'm looking for something which can replace all occurences of one
operator, possibily parameterized by class_name.
Thanks.



------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Swig C++ ->C# operator problem

by David Piepgrass :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I'm porting a big C++ library to either Python and C#.
> In Python the wrapping of C++ operators is just some lines of %rename.
>
> But in C#, SWIG does not accept:
>      %rename(operator =) *::operator =
>
> (which is basically what I need).
>
> What I do now is:
>     %rename(some_dummy_name) *::operator =
> and
>     %typemap(cscode) ClassName %{ .... }%
>
> for each class (and they are a lot!) and for each operator (=, ==, +,
> +=, [], () etc etc).
> I could have used SWIGTYPE (instead of ClassName) in %typemap, but
> not all classes supports all operators (take for example std::vector).
> Is there a better way to make this process automatic?

I don't think there is a better way. In Python it works because SWIG doesn't have to do anything special (e.g. SWIG is not aware what __add__ means), but in C# SWIG would have to transform a non-static member function into a static member function, and it is not programmed to know how to do so. Besides that, it might not understand that "operator =" is a valid C# identifier.

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user