SWIG C++/Java Director - assume override for method defined using javaout?

Viewed 215

I want to repeat some methods among various SWIG director-enabled classes, where those methods can be called from C++ and have a Java implementation (the same in all cases). I have done that successfully by introducing a superclass:

#ifdef SWIG
%feature("director", assumeoverride=1) Frobbable;
%typemap(javaout) int frob() {
    return my.package.Foo.frob(this);
}
#endif
class Frobbable {
public:
    virtual ~Frobbable() {}
    virtual int frob() = 0;
};

#ifdef SWIG
%feature("director", assumeoverride=1) Child;
#endif
class Child : public Frobbable {
    ...
};

The problem is my javaout implementation is not considered an override by the director init code, and trying to call frob() from C++ inside Child results in an exception for trying to invoke a virtual method. By using assumeoverride=1 it will call my Java method, which is okay but feels a bit brittle/hacky.

Is there a better way to share Java implementations across multiple SWIG classes, callable from C++? I am trying to avoid declaring/defining these methods on every Child class.

0 Answers
Related