|
From: William S F. <ws...@fu...> - 2009-11-25 00:26:47
|
Anton Lauridsen wrote:
> Hi
>
> I'm trying to redefine the base class of a wrapped class in c#, using:
>
> %typemap(csbase, replace="1") osgViewer::View "Osg.View";
>
> which works great, except I'm having issues mapping the corresponding
> "Dispose" methods, when replacing the base, the "derived" flag in
> csharp.cxx (line 1540) is assigned "false", which causes the code for
> generating the "csdestruct" method to insert a "virtual" keyword.
> Wouldn't it be better to have the "derived" flag remain true when "%
> typemap(csbase, replace="1")" is specified, which would not remove the
> issue with the inserted "derived" flag but also reduce the complexity of
> specifying a new base class, since most of the "_derived" typemaps will
> often match what is needed when overriding the base class. I.e.
> instead of:
>
> ----
> if (purebase_replace) {
> wanted_base = pure_baseclass;
> derived = false;
> Delete(baseclass);
> baseclass = NULL;
> if (purebase_notderived)
> Swig_error(input_file, line_number, "The csbase typemap for
> proxy %s must contain just one of the 'replace' or 'notderived'
> attributes.\n", typemap_lookup_type);
> } else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) {
> Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file,
> line_number,
> "Warning for %s proxy: Base %s ignored. Multiple inheritance is not
> supported in C#. "
> "Perhaps you need one of the 'replace' or 'notderived' attributes
> in the csbase typemap?\n", typemap_lookup_type, pure_baseclass);
> }
> ----
> use:
> ----
> if (purebase_replace) {
> wanted_base = pure_baseclass;
> Delete(baseclass);
> baseclass = NULL;
> if (purebase_notderived)
> Swig_error(input_file, line_number, "The csbase typemap for
> proxy %s must contain just one of the 'replace' or 'notderived'
> attributes.\n", typemap_lookup_type);
> else
> derived = false;
> } else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) {
> Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file,
> line_number,
> "Warning for %s proxy: Base %s ignored. Multiple inheritance is not
> supported in C#. "
> "Perhaps you need one of the 'replace' or 'notderived' attributes
> in the csbase typemap?\n", typemap_lookup_type, pure_baseclass);
> }
> ----
>
The only difference I can see above is that derived is set to false (as
before) under an error condition, so I don't get what the difference is
really unless there is an error condition... but then SWIG errors out,
so the wrappers fail. BTW, a patch generated from diff is a lot easier
to follow when submitting code suggestions.
> That way the typemap will still operate as if it the class was
> inherited, except when the "notderived" derived flag has been specified.
>
If the replace resulted in a 'override' rather than 'virtual' Dispose
method, then the base class class would have to implement the Dispose
method plus the swigCMemOwn flag. Seems more sensible to leave all this
kerfuffle to the SWIG generated classes. Also if you want you can remove
the csdestruct typemaps and put Dispose methods into the cscode typemap.
If I've missed something, I suggest you post a cut down use case of what
you want, so I can see what is c++ and what is c#.
William
|