%shared_ptr fixes when the type is a template using template parameters that are typedef'd to another type. Also fixed %shared_ptr when the template parameter has a default value.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12776 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
95cd530c8f
commit
d0081ebb82
5 changed files with 231 additions and 37 deletions
|
|
@ -227,6 +227,7 @@ CPP_TEST_CASES += \
|
|||
li_attribute \
|
||||
li_boost_shared_ptr \
|
||||
li_boost_shared_ptr_bits \
|
||||
li_boost_shared_ptr_template \
|
||||
li_carrays \
|
||||
li_cdata \
|
||||
li_cpointer \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
|
||||
import li_boost_shared_ptr_template.*;
|
||||
|
||||
public class li_boost_shared_ptr_template_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("li_boost_shared_ptr_template");
|
||||
} 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[]) {
|
||||
{
|
||||
BaseINTEGER b = new BaseINTEGER();
|
||||
DerivedINTEGER d = new DerivedINTEGER();
|
||||
if (b.bar() != 1)
|
||||
throw new RuntimeException("test 1");
|
||||
if (d.bar() != 2)
|
||||
throw new RuntimeException("test 2");
|
||||
if (li_boost_shared_ptr_template.bar_getter(b) != 1)
|
||||
throw new RuntimeException("test 3");
|
||||
if (li_boost_shared_ptr_template.bar_getter(d) != 2)
|
||||
throw new RuntimeException("test 4");
|
||||
}
|
||||
|
||||
{
|
||||
BaseDefaultInt b = new BaseDefaultInt();
|
||||
DerivedDefaultInt d = new DerivedDefaultInt();
|
||||
DerivedDefaultInt2 d2 = new DerivedDefaultInt2();
|
||||
if (b.bar2() != 3)
|
||||
throw new RuntimeException("test 5");
|
||||
if (d.bar2() != 4)
|
||||
throw new RuntimeException("test 6");
|
||||
if (d2.bar2() != 4)
|
||||
throw new RuntimeException("test 6");
|
||||
if (li_boost_shared_ptr_template.bar2_getter(b) != 3)
|
||||
throw new RuntimeException("test 7");
|
||||
if (li_boost_shared_ptr_template.bar2_getter(d) != 4)
|
||||
throw new RuntimeException("test 8");
|
||||
if (li_boost_shared_ptr_template.bar2_getter(d2) != 4)
|
||||
throw new RuntimeException("test 8");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
99
Examples/test-suite/li_boost_shared_ptr_template.i
Normal file
99
Examples/test-suite/li_boost_shared_ptr_template.i
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
%module li_boost_shared_ptr_template
|
||||
|
||||
// First test- Bug 3333549 - using INTEGER typedef in %shared_ptr before typedef defined
|
||||
%{
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
typedef int INTEGER;
|
||||
|
||||
template <class T>
|
||||
class Base {
|
||||
public:
|
||||
virtual T bar() {return 1;}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class Derived : public Base<T> {
|
||||
public:
|
||||
virtual T bar() {return 2;}
|
||||
};
|
||||
|
||||
INTEGER bar_getter(Base<INTEGER>& foo) {
|
||||
return foo.bar();
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD)
|
||||
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
|
||||
#endif
|
||||
|
||||
#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
|
||||
|
||||
%include <boost_shared_ptr.i>
|
||||
%shared_ptr(Base<INTEGER>)
|
||||
%shared_ptr(Derived<INTEGER>)
|
||||
|
||||
#endif
|
||||
|
||||
typedef int INTEGER;
|
||||
|
||||
template <class T>
|
||||
class Base {
|
||||
public:
|
||||
virtual T bar() {return 1;}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class Derived : public Base<T> {
|
||||
public:
|
||||
virtual T bar() {return 2;}
|
||||
};
|
||||
|
||||
INTEGER bar_getter(Base<INTEGER>& foo) {
|
||||
return foo.bar();
|
||||
}
|
||||
|
||||
%template(BaseINTEGER) Base<INTEGER>;
|
||||
%template(DerivedINTEGER) Derived<INTEGER>;
|
||||
|
||||
|
||||
// 2nd test - templates with default template parameters
|
||||
#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
|
||||
|
||||
%shared_ptr(Space::BaseDefault<short>)
|
||||
%shared_ptr(Space::DerivedDefault<short>)
|
||||
%shared_ptr(Space::DerivedDefault2<short>)
|
||||
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
namespace Space {
|
||||
typedef int INT_TYPEDEF;
|
||||
template <class X, class T = int>
|
||||
class BaseDefault {
|
||||
public:
|
||||
virtual T bar2() {return 3;}
|
||||
};
|
||||
|
||||
template <class X, class T = int>
|
||||
class DerivedDefault : public BaseDefault<X, T> {
|
||||
public:
|
||||
virtual T bar2() {return 4;}
|
||||
};
|
||||
template <class X>
|
||||
class DerivedDefault2 : public BaseDefault<X> {
|
||||
public:
|
||||
virtual int bar2() {return 4;}
|
||||
};
|
||||
|
||||
int bar2_getter(BaseDefault<short>& foo) {
|
||||
return foo.bar2();
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
%template(BaseDefaultInt) Space::BaseDefault<short>;
|
||||
%template(DerivedDefaultInt) Space::DerivedDefault<short>;
|
||||
%template(DerivedDefaultInt2) Space::DerivedDefault2<short>;
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
from li_boost_shared_ptr_template import *
|
||||
|
||||
b = BaseINTEGER()
|
||||
d = DerivedINTEGER()
|
||||
if b.bar() != 1:
|
||||
raise RuntimeError
|
||||
if d.bar() != 2:
|
||||
raise RuntimeError
|
||||
if bar_getter(b) != 1:
|
||||
raise RuntimeError
|
||||
if bar_getter(d) != 2:
|
||||
raise RuntimeError
|
||||
|
||||
b = BaseDefaultInt()
|
||||
d = DerivedDefaultInt()
|
||||
d2 = DerivedDefaultInt2()
|
||||
if b.bar2() != 3:
|
||||
raise RuntimeError
|
||||
if d.bar2() != 4:
|
||||
raise RuntimeError
|
||||
if d2.bar2() != 4:
|
||||
raise RuntimeError
|
||||
if bar2_getter(b) != 3:
|
||||
raise RuntimeError
|
||||
if bar2_getter(d) != 4:
|
||||
raise RuntimeError
|
||||
if bar2_getter(d2) != 4:
|
||||
raise RuntimeError
|
||||
Loading…
Add table
Add a link
Reference in a new issue