fixes for SwigValueWrapper
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6444 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a75d2b0a4c
commit
faa9419662
3 changed files with 130 additions and 1 deletions
|
|
@ -19,3 +19,17 @@
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SWIGPYTHON
|
||||||
|
|
||||||
|
// This case only works in python
|
||||||
|
%inline %{
|
||||||
|
struct Bar : Foo
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
Bar bar;
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@
|
||||||
/*
|
/*
|
||||||
* Opaque types
|
* Opaque types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
%feature("valuewrapper") C;
|
||||||
|
class C;
|
||||||
|
|
||||||
%{
|
%{
|
||||||
template<typename T> class TemplateClass {
|
template<typename T> class TemplateClass {
|
||||||
public:
|
public:
|
||||||
|
|
@ -38,6 +42,17 @@ class B;
|
||||||
class D;
|
class D;
|
||||||
|
|
||||||
|
|
||||||
|
%feature("valuewrapper") A;
|
||||||
|
class A;
|
||||||
|
|
||||||
|
%feature("valuewrapper") TemplateClass<A>;
|
||||||
|
%feature("valuewrapper") TemplateClass<C>;
|
||||||
|
template<class A> class TemplateClass;
|
||||||
|
|
||||||
|
%feature("valuewrapper") BB;
|
||||||
|
class BB;
|
||||||
|
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
||||||
class A
|
class A
|
||||||
|
|
@ -134,3 +149,103 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%{
|
||||||
|
class Foobar
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Foobar()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
char *foo_method()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class Quux
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Quux()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Foobar method()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
%feature("novaluewrapper") Foobar;
|
||||||
|
class Foobar;
|
||||||
|
|
||||||
|
|
||||||
|
class Quux {
|
||||||
|
public:
|
||||||
|
Quux();
|
||||||
|
|
||||||
|
Foobar method();
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(SWIGPYTHON)
|
||||||
|
|
||||||
|
/*
|
||||||
|
This case can't be fixed by using the valuewrapper feature and the
|
||||||
|
old mechanismbut it works fine with the new mechanism
|
||||||
|
*/
|
||||||
|
|
||||||
|
%{
|
||||||
|
|
||||||
|
// Template primitive type, only visible in C++
|
||||||
|
template <class T>
|
||||||
|
struct Param
|
||||||
|
{
|
||||||
|
T val;
|
||||||
|
|
||||||
|
|
||||||
|
Param(T v): val(v) {
|
||||||
|
}
|
||||||
|
|
||||||
|
operator T() const { return val; }
|
||||||
|
};
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Several languages have 'not 100% safe' typemaps,
|
||||||
|
where the following %applies don't work.
|
||||||
|
*/
|
||||||
|
%apply int { Param<int> };
|
||||||
|
%apply const int& { const Param<int>& };
|
||||||
|
|
||||||
|
%apply double { Param<double> };
|
||||||
|
%apply const double& { const Param<double>& };
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
T getv(const Param<T>& p)
|
||||||
|
{
|
||||||
|
return p.val;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Param<T> getp(const T& v)
|
||||||
|
{
|
||||||
|
return Param<T>(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
%template(getv_i) getv<int>;
|
||||||
|
%template(getp_i) getp<int>;
|
||||||
|
|
||||||
|
%template(getv_d) getv<double>;
|
||||||
|
%template(getp_d) getp<double>;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue