Ignoring specific overloaded methods with Swig

swig

Solution

The solution is to not use quotes with the method signature.

%rename ("$ignore", fullname=1) ns3::SomeClass::someMethod(const ns2::ComplexData &);

I did put quotes in the first place because I always have and always worked for me, for example:

%rename ("renamedMethod", fullname=1) "ns3::SomeClass::anotherMethod";

The full .i file for reference:

%module libSomeClass

%{
    #include "../src/SomeClass.h"
%}

%pragma(java) jniclasscode=%{
  static {
    try {
        System.loadLibrary("SWIG_C++");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load. \n" + e);
      System.exit(1);
    }
  }
%}

// SimpleData
%include "../src/SimpleData.h"

%rename ("$ignore", fullname=1) ns3::SomeClass::someMethod(const ns2::ComplexData &);

%ignore ns3::SomeClass::someMethod(const int &);

%rename ("renamedMethod", fullname=1) "ns3::SomeClass::anotherMethod";

%include "../src/SomeClass.h"

Problem

I'm making a wrapper of a C++ library so it can be used from Java, I'm doing this with Swig. What I'm facing is that i have a Class `SomeClass`, which has some overloaded methods (`someMethod`). Of this overloaded methods some receive complex data that i don't want to export to the wrapper, and some simple ones which i do want then exported. I'm trying to use the `%rename("$ignore")` directive but either i get all methods exported or none. I have another two types of Classes `SimpleData` and `ComplexData`, one of them in namespace `ns1` and the other in `ns2`, `SomeClass` is in namespace ''ns3`. The class `SimpleData`: ``` #ifndef SIMPLEDATA_H_ #define SIMPLEDATA_H_ namespace ns1 { class SimpleData { public: SimpleData(){} virtual ~SimpleData(){} }; } /* namespace ns1 */ #endif /* SIMPLEDATA_H_ */ ``` The class ComplexData: ``` #ifndef COMPLEXDATA_H_ #define COMPLEXDATA_H_ namespace ns2 { class ComplexData { public: ComplexData(){} virtual ~ComplexData(){} }; } /* namespace ns2 */ #endif /* COMPLEXDATA_H_ */ ``` The class `SomeClass`: ``` #ifndef SOMECLASS_H_ #define SOMECLASS_H_ #include "SimpleData.h" #include "ComplexData.h" namespace ns3 { class SomeClass { public: SomeClass(){} bool someMethod(const ns1::SimpleData & data){return true;} bool someMethod(const ns2::ComplexData & data){return true;} bool someMethod(const int & data){return true;} bool anotherMethod(); virtual ~SomeClass(){} }; } /* namespace ns3 */ #endif /* SOMECLASS_H_ */ ``` The i file snippet looks like this: ``` %rename ("$ignore", fullname=1) "ns3::SomeClass::someMethod(const ns2::ComplexData&)"; ``` But that isn't working. Which one is the correct way of ignoring some specific overload of a method? The full .i file: ``` %module libSomeClass %{ #include "../src/SomeClass.h" %} %pragma(java) jniclasscode=%{ static { try { System.loadLibrary("SWIG_C++"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load. \n" + e); System.exit(1); } } %} // SimpleData %include "../src/SimpleData.h" //removes too much //%rename ("$ignore", fullname=1) "ns3::SomeClass::someMethod"; //does not work %rename ("$ignore", fullname=1) "ns3::SomeClass::someMethod(const ns2::ComplexData &)"; %rename ("renamedMethod", fullname=1) "ns3::SomeClass::anotherMethod"; %include "../src/SomeClass.h" ``` Note: I don't think it actually has nothing to do but just in case, those methods actually throw a exception. Note2: I also don't think is relevant, but the target language is Java and the source language is C++.

Original source