Farah
Farah

Reputation: 2621

How to apply a typemap only on one function's arguement?

I'm trying to create a wrapper in Java for a C++ solution.

Having 2 fonctions in this C++ project :

int func1(const void* b);
int func2(const void* b);

I need to apply this rule (typemap) only on int func2(const void* b); :

%apply char *BYTE { const void* b };

This is a constraint because const void * use is different from a function to another.

Remark : I have no right to rename fucn1's argument from b to something else.

Thanks you.

Upvotes: 4

Views: 474

Answers (1)

Oliver
Oliver

Reputation: 29543

Try %clear between the declaration of func1 and func2:

%{
#include "funcs.h"
%}

%apply char *BYTE { const void* b };
int func1(const void* b);
%clear const void* b;

int func2(const void* b);

Note also that the name of a variable in a declaration does not affect called code, i.e. you should be able to do

%{
#include "funcs.h"
%}

%apply char *BYTE { const void* b };
int func1(const void* b);
int func2(const void* c);

(although the header declares first arg as b, C++ args are all positional, the only place they matter is in the definition (not declaration) of a function body, which is not something that SWIG uses so above should work).

Upvotes: 3

Related Questions