more cases
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5796 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
005067ec15
commit
2c5dc2113b
4 changed files with 79 additions and 1 deletions
|
|
@ -1,25 +1,38 @@
|
||||||
%module lib_std_pair
|
%module lib_std_pair
|
||||||
|
|
||||||
%include std_pair.i
|
%include std_pair.i
|
||||||
|
%include std_string.i
|
||||||
|
%include std_complex.i
|
||||||
|
|
||||||
|
%inline
|
||||||
%{
|
%{
|
||||||
struct A
|
struct A
|
||||||
{
|
{
|
||||||
|
int val;
|
||||||
|
|
||||||
|
A(int v = 0): val(v)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
struct B
|
struct B
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
%template() pair<double, double>;
|
%template() pair<double, double>;
|
||||||
|
%template(String) basic_string<char>;
|
||||||
%template(IntPair) pair<int, int>;
|
%template(IntPair) pair<int, int>;
|
||||||
|
%template(SIPair) pair<std::string, int>;
|
||||||
|
%template(CIPair) pair<std::complex<double>, int>;
|
||||||
|
%template(SIIPair) pair<std::pair<std::string, int>, int>;
|
||||||
%template(AIntPair) pair<A, int>;
|
%template(AIntPair) pair<A, int>;
|
||||||
|
|
||||||
%template(ABPair) pair<A, B>;
|
%template(ABPair) pair<A, B>;
|
||||||
%template(IntAPair) pair<int, A>;
|
%template(IntAPair) pair<int, A>;
|
||||||
}
|
}
|
||||||
|
%std_comp_methods(std::pair<std::pair<std::string, int>, int>);
|
||||||
|
|
||||||
%apply std::pair<int,int> *INOUT {std::pair<int,int> *INOUT2};
|
%apply std::pair<int,int> *INOUT {std::pair<int,int> *INOUT2};
|
||||||
|
|
||||||
|
|
@ -113,6 +126,11 @@ p_inoutd(std::pair<double, double> *INOUT) {
|
||||||
std::swap(INOUT->first, INOUT->second);
|
std::swap(INOUT->first, INOUT->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
s_ident(const std::string& s) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
std::pair<char, char>
|
std::pair<char, char>
|
||||||
p_ident(std::pair<char, char> p, const std::pair<char, char>& q) {
|
p_ident(std::pair<char, char> p, const std::pair<char, char>& q) {
|
||||||
|
|
@ -143,6 +161,7 @@ std::pair<int, int>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,28 @@ struct A : std::string
|
||||||
A(const std::string& s) : std::string(s)
|
A(const std::string& s) : std::string(s)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct B
|
||||||
|
{
|
||||||
|
B(const std::string& s) : cname(0), name(s), a(s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
char *cname;
|
||||||
|
std::string name;
|
||||||
|
A a;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const char* test_ccvalue(const char* x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* test_cvalue(char* x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string test_value(std::string x) {
|
std::string test_value(std::string x) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,14 @@ import lib_std_string
|
||||||
|
|
||||||
x="hello"
|
x="hello"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if lib_std_string.test_ccvalue(x) != x:
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
if lib_std_string.test_cvalue(x) != x:
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
if lib_std_string.test_value(x) != x:
|
if lib_std_string.test_value(x) != x:
|
||||||
raise RuntimeError, "bad string mapping"
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
|
@ -34,3 +42,32 @@ if lib_std_string.test_value(a) != x:
|
||||||
if lib_std_string.test_const_reference(a) != x:
|
if lib_std_string.test_const_reference(a) != x:
|
||||||
raise RuntimeError, "bad string mapping"
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
b = lib_std_string.string(" world")
|
||||||
|
|
||||||
|
if a + b != "hello world":
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
if a + " world" != "hello world":
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
if "hello" + b != "hello world":
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
c = "hello" + b
|
||||||
|
if c.find_last_of("l") != 9:
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
s = "hello world"
|
||||||
|
|
||||||
|
b = lib_std_string.B("hi")
|
||||||
|
|
||||||
|
b.name = "hello"
|
||||||
|
if b.name != "hello":
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
|
||||||
|
b.a = lib_std_string.A("hello")
|
||||||
|
if b.a != "hello":
|
||||||
|
raise RuntimeError, "bad string mapping"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,7 @@ if t.var_namet != 'hol\0\0':
|
||||||
|
|
||||||
|
|
||||||
if t.strlen('hile') != 4:
|
if t.strlen('hile') != 4:
|
||||||
|
print t.strlen('hile')
|
||||||
raise RuntimeError, "bad string typemap"
|
raise RuntimeError, "bad string typemap"
|
||||||
|
|
||||||
if t.strlen('hil\0') != 4:
|
if t.strlen('hil\0') != 4:
|
||||||
|
|
@ -224,6 +225,7 @@ if cvar.var_pchar != None:
|
||||||
|
|
||||||
cvar.var_pchar = ''
|
cvar.var_pchar = ''
|
||||||
if cvar.var_pchar != '':
|
if cvar.var_pchar != '':
|
||||||
|
print '%c' % (cvar.var_pchar[0],)
|
||||||
raise RuntimeError, "bad char empty case"
|
raise RuntimeError, "bad char empty case"
|
||||||
|
|
||||||
cvar.var_pcharc = None
|
cvar.var_pcharc = None
|
||||||
|
|
@ -251,6 +253,7 @@ if t.strlen(pc) != 4:
|
||||||
|
|
||||||
cvar.var_pchar = pc
|
cvar.var_pchar = pc
|
||||||
if cvar.var_pchar != "hola":
|
if cvar.var_pchar != "hola":
|
||||||
|
print cvar.var_pchar
|
||||||
raise RuntimeError, "bad pointer case"
|
raise RuntimeError, "bad pointer case"
|
||||||
|
|
||||||
cvar.var_namet = pc
|
cvar.var_namet = pc
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue