Add support for %typemap and member function pointers with qualifiers
This commit is contained in:
parent
45c161dfce
commit
c4e280024f
4 changed files with 137 additions and 2 deletions
|
|
@ -563,6 +563,7 @@ CPP11_TEST_CASES += \
|
|||
cpp11_raw_string_literals \
|
||||
cpp11_ref_qualifiers \
|
||||
cpp11_ref_qualifiers_rvalue_unignore \
|
||||
cpp11_ref_qualifiers_typemaps \
|
||||
cpp11_result_of \
|
||||
cpp11_rvalue_reference \
|
||||
cpp11_rvalue_reference2 \
|
||||
|
|
|
|||
74
Examples/test-suite/cpp11_ref_qualifiers_typemaps.i
Normal file
74
Examples/test-suite/cpp11_ref_qualifiers_typemaps.i
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
%module cpp11_ref_qualifiers_typemaps
|
||||
|
||||
%typemap(in) SWIGTYPE (CLASS::*) %{
|
||||
_this_will_fail_to_compile_if_used_
|
||||
%}
|
||||
|
||||
// typemaps to completely ignore the input parm and override it
|
||||
%typemap(in) short (Funcs::*ff)(bool) const %{ $1 = &Funcs::FF2; %}
|
||||
%typemap(in) short (Funcs::*cc)(bool) & %{ $1 = &Funcs::CC5; %}
|
||||
%typemap(in) short (Funcs::*gg)(bool) const & %{ $1 = &Funcs::GG8; %}
|
||||
%typemap(in) short (Funcs::*hh)(bool) && %{ $1 = &Funcs::HH11; %}
|
||||
|
||||
%typemap(in) short (Funcs::*)(bool) const %{ $1 = &Funcs::FF3; %}
|
||||
%typemap(in) short (Funcs::*)(bool) & %{ $1 = &Funcs::CC6; %}
|
||||
%typemap(in) short (Funcs::*)(bool) const & %{ $1 = &Funcs::GG9; %}
|
||||
%typemap(in) short (Funcs::*)(bool) && %{ $1 = &Funcs::HH12; %}
|
||||
|
||||
%inline %{
|
||||
struct Funcs {
|
||||
short FF1(bool) const { return 1; }
|
||||
short FF2(bool) const { return 2; }
|
||||
short FF3(bool) const { return 3; }
|
||||
short CC4(bool) & { return 4; }
|
||||
short CC5(bool) & { return 5; }
|
||||
short CC6(bool) & { return 6; }
|
||||
short GG7(bool) const & { return 7; }
|
||||
short GG8(bool) const & { return 8; }
|
||||
short GG9(bool) const & { return 9; }
|
||||
short HH10(bool) && { return 10; }
|
||||
short HH11(bool) && { return 11; }
|
||||
short HH12(bool) && { return 12; }
|
||||
};
|
||||
struct TypemapsNamedParms
|
||||
{
|
||||
short fff(short (Funcs::*ff)(bool) const) {
|
||||
Funcs funcs;
|
||||
return (funcs.*ff)(true);
|
||||
}
|
||||
short ccc(short (Funcs::*cc)(bool) &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*cc)(true);
|
||||
}
|
||||
short ggg(short (Funcs::*gg)(bool) const &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*gg)(true);
|
||||
}
|
||||
short hhh(short (Funcs::*hh)(bool) &&) {
|
||||
return (Funcs().*hh)(true);
|
||||
}
|
||||
};
|
||||
struct TypemapsUnnamedParms
|
||||
{
|
||||
short fff(short (Funcs::*f)(bool) const) {
|
||||
Funcs funcs;
|
||||
return (funcs.*f)(true);
|
||||
}
|
||||
short ccc(short (Funcs::*c)(bool) &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*c)(true);
|
||||
}
|
||||
short ggg(short (Funcs::*g)(bool) const &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*g)(true);
|
||||
}
|
||||
short hhh(short (Funcs::*h)(bool) &&) {
|
||||
return (Funcs().*h)(true);
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%constant short (Funcs::*FF1_MFP)(bool) const = &Funcs::FF1;
|
||||
%constant short (Funcs::*CC4_MFP)(bool) & = &Funcs::CC4;
|
||||
%constant short (Funcs::*GG7_MFP)(bool) const & = &Funcs::GG7;
|
||||
%constant short (Funcs::*HH10_MFP)(bool) && = &Funcs::HH10;
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import cpp11_ref_qualifiers_typemaps.*;
|
||||
|
||||
public class cpp11_ref_qualifiers_typemaps_runme {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("cpp11_ref_qualifiers_typemaps");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
{
|
||||
TypemapsNamedParms tm = new TypemapsNamedParms();
|
||||
if (tm.fff(cpp11_ref_qualifiers_typemaps.FF1_MFP) != 2)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.ccc(cpp11_ref_qualifiers_typemaps.CC4_MFP) != 5)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.ggg(cpp11_ref_qualifiers_typemaps.GG7_MFP) != 8)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.hhh(cpp11_ref_qualifiers_typemaps.HH10_MFP) != 11)
|
||||
throw new RuntimeException("failed");
|
||||
}
|
||||
{
|
||||
TypemapsUnnamedParms tm = new TypemapsUnnamedParms();
|
||||
if (tm.fff(cpp11_ref_qualifiers_typemaps.FF1_MFP) != 3)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.ccc(cpp11_ref_qualifiers_typemaps.CC4_MFP) != 6)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.ggg(cpp11_ref_qualifiers_typemaps.GG7_MFP) != 9)
|
||||
throw new RuntimeException("failed");
|
||||
if (tm.hhh(cpp11_ref_qualifiers_typemaps.HH10_MFP) != 12)
|
||||
throw new RuntimeException("failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue