diff --git a/SWIG/Examples/test-suite/lib_std_vector.i b/SWIG/Examples/test-suite/lib_std_vector.i index 58f5f3381..a494a2696 100644 --- a/SWIG/Examples/test-suite/lib_std_vector.i +++ b/SWIG/Examples/test-suite/lib_std_vector.i @@ -28,9 +28,9 @@ double average(std::vector v) { return std::accumulate(v.begin(),v.end(),0.0)/v.size(); } -std::vector half(const std::vector& v) { - std::vector w(v); - for (unsigned int i=0; i half(const std::vector& v) { + std::vector w(v); + for (std::vector::size_type i=0; i; +%template() std::vector; +%template() std::vector; +%template() std::pair; +%template() std::pair; +%template() std::pair; +#endif + %feature("director") Foo; %feature("director:except") { diff --git a/SWIG/Examples/test-suite/python/implicittest_runme.py b/SWIG/Examples/test-suite/python/implicittest_runme.py index a207a185a..5de43844f 100644 --- a/SWIG/Examples/test-suite/python/implicittest_runme.py +++ b/SWIG/Examples/test-suite/python/implicittest_runme.py @@ -4,9 +4,9 @@ ai = A(1) ad = A(2.0) ab = A(b) -print ai, get(ai) -print ad, get(ad) -print ab, get(ab) +ai, get(ai) +ad, get(ad) +ab, get(ab) if get(ai) != get(1): raise RuntimeError,"bad implicit type" diff --git a/SWIG/Examples/test-suite/python/lib_std_pair.i b/SWIG/Examples/test-suite/python/lib_std_pair.i index 98c6b5432..3b1579b68 100644 --- a/SWIG/Examples/test-suite/python/lib_std_pair.i +++ b/SWIG/Examples/test-suite/python/lib_std_pair.i @@ -1,6 +1,6 @@ %module lib_std_pair -%include "std_pair.i" +%include std_pair.i %{ struct A @@ -13,6 +13,7 @@ namespace std { + %template() pair; %template(IntPair) pair; %template(AIntPair) pair; @@ -20,6 +21,8 @@ namespace std { %template(IntAPair) pair; } +%apply std::pair *INOUT {std::pair *INOUT2}; + %inline %{ /* Test the "out" typemap for pair */ @@ -72,6 +75,44 @@ std::pair return p; } + +void +d_inout(double *INOUT) { + *INOUT += *INOUT; +} + +void +d_inout(int *INOUT) { + *INOUT += *INOUT; +} + +int +d_inout2(double *INOUT) { + *INOUT += *INOUT; + return 1; +} + +void +p_inout(std::pair *INOUT) { + std::swap(INOUT->first, INOUT->second); +} + +int +p_inout2(std::pair *INOUT) { + std::swap(INOUT->first, INOUT->second); + return 1; +} + +void + p_inout3(std::pair *INOUT, std::pair *INOUT2) { + std::swap(*INOUT, *INOUT2); +} + +void +p_inoutd(std::pair *INOUT) { + std::swap(INOUT->first, INOUT->second); +} + #if 0 std::pair p_ident(std::pair p, const std::pair& q) { @@ -100,6 +141,8 @@ std::pair p_ident(std::pair p, const std::pair& q) { return p; } + + #endif %} diff --git a/SWIG/Examples/test-suite/python/lib_std_string_runme.py b/SWIG/Examples/test-suite/python/lib_std_string_runme.py index d72b0ddcb..9adb227db 100644 --- a/SWIG/Examples/test-suite/python/lib_std_string_runme.py +++ b/SWIG/Examples/test-suite/python/lib_std_string_runme.py @@ -10,7 +10,15 @@ if lib_std_string.test_const_reference(x) != x: s = lib_std_string.string("he") -s.append("llo") +s += "ll" +s.append('o') + +if s != x: + print s, x + raise RuntimeError, "bad string mapping" + +if s[1:4] != x[1:4]: + raise RuntimeError, "bad string mapping" if lib_std_string.test_value(s) != x: raise RuntimeError, "bad string mapping" @@ -18,10 +26,11 @@ if lib_std_string.test_value(s) != x: if lib_std_string.test_const_reference(s) != x: raise RuntimeError, "bad string mapping" -a = lib_std_string.A("hello") +a = lib_std_string.A(s) if lib_std_string.test_value(a) != x: raise RuntimeError, "bad string mapping" if lib_std_string.test_const_reference(a) != x: raise RuntimeError, "bad string mapping" + diff --git a/SWIG/Examples/test-suite/python/lib_std_vectora.i b/SWIG/Examples/test-suite/python/lib_std_vectora.i index 164dcbbe3..17e8408a8 100644 --- a/SWIG/Examples/test-suite/python/lib_std_vectora.i +++ b/SWIG/Examples/test-suite/python/lib_std_vectora.i @@ -2,6 +2,7 @@ %include std_vectora.i + %{ #include #include @@ -20,7 +21,7 @@ std::allocator > > > imatrix; - std::vector vident(const std::vector& v) + std::vector vident(const std::vector >& v) { return v; } @@ -44,12 +45,13 @@ namespace std { %inline %{ -double average(std::vector v) { +double average(std::vector > v) { return std::accumulate(v.begin(),v.end(),0.0)/v.size(); } -std::vector half(const std::vector& v) { - std::vector w(v); +std::vector > +half(const std::vector >& v) { + std::vector w(v); for (unsigned int i=0; i; +%template() std::pair; +%template() std::pair; +#endif %template() std::vector< std::vector > ; %template(ccube) std::vector< std::vector< std::vector > >; @@ -28,6 +35,7 @@ %template(map_si) std::map; +%template(mmap_si) std::multimap; %template(set_i) std::set; %template(multiset_i) std::multiset; %template(list_i) std::list; @@ -40,6 +48,8 @@ %template(imatrix) std::vector >; %template(cmatrix) std::vector > >; +%apply std::vector *INOUT {std::vector *INOUT2}; + %inline { typedef std::vector > imatrix; @@ -58,6 +68,11 @@ return v; } + std::multimap mapident(const std::multimap& v) + { + return v; + } + std::vector vident(const std::vector& v) { return v; @@ -83,8 +98,17 @@ { return p; } - - + + void + v_inout(std::vector *INOUT) { + *INOUT = *INOUT; + } + + void + v_inout2(std::vector *INOUT, std::vector *INOUT2) { + std::swap(*INOUT, *INOUT2); + } + } @@ -114,11 +138,16 @@ template struct Param { struct A { + A(int aa = 0) : a(aa) + { + } + int a; }; } %template() std::pair; %template(pair_iA) std::pair; +%template(vector_piA) std::vector >; %inline { @@ -126,5 +155,12 @@ template struct Param { return std::pair(); } + + + std::vector > pia_vident(std::vector > a ) + { + return a; + } + } diff --git a/SWIG/Examples/test-suite/python/std_containers_runme.py b/SWIG/Examples/test-suite/python/std_containers_runme.py index a048088bc..f1b7f53ab 100644 --- a/SWIG/Examples/test-suite/python/std_containers_runme.py +++ b/SWIG/Examples/test-suite/python/std_containers_runme.py @@ -27,7 +27,8 @@ if vu[2] != std_containers.videntu(vu)[2]: raise RuntimeError, "bad videntu" -if v[0:3] != vu[0:3]: +if v[0:3][1] != vu[0:3][1]: + print v[0:3][1], vu[0:3][1] raise RuntimeError, "bad getslice" @@ -51,3 +52,30 @@ if map != std_containers.mapident(map): raise RuntimeError, "bad map" +vi = std_containers.vector_i((2,2,3,4)) + + +v = (1,2) +v1 = std_containers.v_inout(vi) +vi[1], v1[1] + +v1,v2 = ((1,2),(3,4)) +v1,v2 = std_containers.v_inout2(v1,v2) + +a1 = std_containers.A(1) +a2 = std_containers.A(2) + +p1 = (1,a1) +p2 = (2,a2) +v = (p1,p2) +v2= std_containers.pia_vident(v) + +v2[0][1].a +v2[1][1].a + +v3 = std_containers.vector_piA(v2) + +v3[0][1].a +v3[1][1].a + +