Correct behaviour for templated methods used with %rename or %ignore and %template()

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9906 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2007-08-17 20:42:19 +00:00
commit 3fd28bf45c
7 changed files with 135 additions and 2 deletions

View file

@ -279,6 +279,7 @@ CPP_TEST_CASES += \
template_inherit \
template_inherit_abstract \
template_int_const \
template_method \
template_ns \
template_ns2 \
template_ns3 \

View file

@ -0,0 +1,37 @@
import template_methods.*;
public class template_methods_runme {
static {
try {
System.loadLibrary("template_methods");
} 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[]) {
float num = (float)1.1;
// Global templated functions
int i = template_methods.convolve1Bool();
template_methods.convolve1Bool(true);
i = template_methods.convolve2Float();
template_methods.convolve3FloatRenamed(num);
i = template_methods.convolve4Float();
template_methods.convolve4FloatRenamed(num);
i = template_methods.convolve5FloatRenamed();
template_methods.convolve5FloatRenamed(num);
// Static templated methods
Klass k = new Klass();
boolean b = k.KlassTMethodBoolRenamed(true);
k.KlassTMethodBool();
b = Klass.KlassStaticTMethodBoolRenamed(true);
Klass.KlassStaticTMethodBool();
}
}

View file

@ -0,0 +1,78 @@
// Test %ignore and %rename for templated methods
%module template_methods
%warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve1<float>();
%warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve3<float>();
///////////////////
%ignore convolve1<float>(float a);
%inline %{
template <typename ImageT> int convolve1() { ImageT t; return 0; }
template <typename ImageT> void convolve1(ImageT a) { ImageT t = a; }
%}
%template() convolve1<float>;
%template(convolve1Bool) convolve1<bool>;
///////////////////
%ignore convolve2<float>(float a);
%inline %{
template <typename ImageT> int convolve2() { ImageT t; return 0; }
template <typename ImageT> void convolve2(ImageT a) { ImageT t = a; }
%}
%template(convolve2Float) convolve2<float>;
///////////////////
%rename(convolve3FloatRenamed) convolve3<float>(float a);
%inline %{
template <typename ImageT> int convolve3() { ImageT t; return 0; }
template <typename ImageT> void convolve3(ImageT a) { ImageT t = a; }
%}
%template() convolve3<float>;
///////////////////
%rename(convolve4FloatRenamed) convolve4<float>(float a);
%inline %{
template <typename ImageT> int convolve4() { ImageT t; return 0; }
template <typename ImageT> void convolve4(ImageT a) { ImageT t = a; }
%}
%template(convolve4Float) convolve4<float>;
///////////////////
%rename(convolve5FloatRenamed) convolve5<float>;
%ignore convolve5<bool>;
%inline %{
template <typename ImageT> int convolve5() { ImageT t; return 0; }
template <typename ImageT> void convolve5(ImageT a) { ImageT t = a; }
%}
%template() convolve5<float>;
%template() convolve5<bool>;
////////////////////////////////////////////////////////////////////////////
%rename(KlassTMethodBoolRenamed) Klass::tmethod(bool);
%rename(KlassStaticTMethodBoolRenamed) Klass::statictmethod(bool);
%inline %{
struct Klass {
template<typename X> X tmethod(X x) { return x; }
template<typename X> void tmethod() {}
template<typename X> static X statictmethod(X x) { return x; }
template<typename X> static void statictmethod() {}
};
%}
%template(KlassTMethodBool) Klass::tmethod<bool>;
%template(KlassStaticTMethodBool) Klass::statictmethod<bool>;