diff --git a/SWIG/Examples/test-suite/python/implicittest.i b/SWIG/Examples/test-suite/python/implicittest.i new file mode 100644 index 000000000..617fa0a27 --- /dev/null +++ b/SWIG/Examples/test-suite/python/implicittest.i @@ -0,0 +1,22 @@ +%module implicittest +%include implicit.i + +%inline +{ + struct B { }; +} + +%implicit(A, int, double, B); + +%inline +{ + struct A + { + int ii; + A(int i) { ii = 1; } + A(double d) { ii = 2; } + A(const B& b) { ii = 3; } + }; + + int get(const A& a) { return a.ii; } +} diff --git a/SWIG/Examples/test-suite/python/implicittest_runme.py b/SWIG/Examples/test-suite/python/implicittest_runme.py new file mode 100644 index 000000000..a207a185a --- /dev/null +++ b/SWIG/Examples/test-suite/python/implicittest_runme.py @@ -0,0 +1,17 @@ +from implicittest import * +b = B() +ai = A(1) +ad = A(2.0) +ab = A(b) + +print ai, get(ai) +print ad, get(ad) +print ab, get(ab) + +if get(ai) != get(1): + raise RuntimeError,"bad implicit type" +if get(ad) != get(2.0): + raise RuntimeError,"bad implicit type" +if get(ab) != get(b): + 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 new file mode 100644 index 000000000..98c6b5432 --- /dev/null +++ b/SWIG/Examples/test-suite/python/lib_std_pair.i @@ -0,0 +1,105 @@ +%module lib_std_pair + +%include "std_pair.i" + +%{ + struct A + { + }; + struct B + { + }; +%} + + +namespace std { + %template(IntPair) pair; + %template(AIntPair) pair; + + %template(ABPair) pair; + %template(IntAPair) pair; +} + +%inline %{ + +/* Test the "out" typemap for pair */ +std::pair makeIntPair(int a, int b) { + return std::make_pair(a, b); +} + +/** + * There is no "out" typemap for a pointer to a pair, so + * this should return a wrapped instance of a std::pair + * instead of the native "array" type for the target language. + */ +std::pair * makeIntPairPtr(int a, int b) { + static std::pair p = std::make_pair(a, b); + return &p; +} + +/** + * There is no "out" typemap for a non-const reference to a pair, so + * this should return a wrapped instance of a std::pair instead of + * the native "array" type for the target language. + */ +std::pair& makeIntPairRef(int a, int b) { + static std::pair p = std::make_pair(a, b); + return p; +} + +/** + * There is no "out" typemap for a const reference to a pair, so + * this should return a wrapped instance of a std::pair + * instead of the native "array" type for the target language. + */ +const std::pair & makeIntPairConstRef(int a, int b) { + static std::pair p = std::make_pair(a, b); + return p; +} + +/* Test the "in" typemap for pair */ +int product1(std::pair p) { + return p.first*p.second; +} + +/* Test the "in" typemap for const pair& */ +int product2(const std::pair& p) { + return p.first*p.second; +} + +std::pair + p_ident(std::pair p, const std::pair& q) { + return p; +} + +#if 0 +std::pair + p_ident(std::pair p, const std::pair& q) { + return p; +} + +/* Test the "in" typemap for const pair* */ +std::pair + p_ident(std::pair p, const std::pair& q) { + return q; +} + +/* Test the "in" typemap for const pair* */ +std::pair + p_ident(std::pair p, const std::pair& q) { + return p; +} + + +std::pair + p_ident(std::pair p, const std::pair& q) { + return p; +} + +std::pair + p_ident(std::pair p, const std::pair& q) { + return p; +} +#endif +%} + diff --git a/SWIG/Examples/test-suite/python/lib_std_vectora.i b/SWIG/Examples/test-suite/python/lib_std_vectora.i new file mode 100644 index 000000000..164dcbbe3 --- /dev/null +++ b/SWIG/Examples/test-suite/python/lib_std_vectora.i @@ -0,0 +1,63 @@ +%module lib_std_vectora + +%include std_vectora.i + +%{ +#include +#include +#include +%} + + +%template(vector_i) std::vector >; + +%template(matrix_i) std::vector >,std::allocator > > >; + +%inline +{ + typedef + std::vector >, + std::allocator > > > + imatrix; + + std::vector vident(const std::vector& v) + { + return v; + } + + imatrix mident(const imatrix& v) + { + return v; + } +} + + +%template(DoubleVector) std::vector >; + +%inline %{ +typedef float Real; +%} + +namespace std { + %template(RealVector) vector >; +} + +%inline %{ + +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 >; + + + diff --git a/SWIG/Examples/test-suite/python/std_containers.i b/SWIG/Examples/test-suite/python/std_containers.i new file mode 100644 index 000000000..86ec31d6f --- /dev/null +++ b/SWIG/Examples/test-suite/python/std_containers.i @@ -0,0 +1,130 @@ +%module std_containers + +%include std_vector.i +%include std_string.i +%include std_deque.i +%include std_list.i +%include std_set.i +%include std_pair.i +%include std_map.i +%include std_complex.i + + +%template() std::vector< std::vector > ; +%template(ccube) std::vector< std::vector< std::vector > >; + +%inline +{ + typedef + std::vector > > + ccube; + + ccube cident(const ccube& c) + { + return c; + } + +} + + +%template(map_si) std::map; +%template(set_i) std::set; +%template(multiset_i) std::multiset; +%template(list_i) std::list; +%template(deque_i) std::deque; + +%template(vector_i) std::vector; +%template(vector_c) std::vector >; +%template(vector_ui) std::vector; + +%template(imatrix) std::vector >; +%template(cmatrix) std::vector > >; + +%inline +{ + typedef std::vector > imatrix; + imatrix mident(const imatrix& v) + { + return v; + } + + std::map mapidenti(const std::map& v) + { + return v; + } + + std::map mapident(const std::map& v) + { + return v; + } + + std::vector vident(const std::vector& v) + { + return v; + } + + std::set sident(const std::set& v) + { + return v; + } + + std::vector videntu(const std::vector& v) + { + return v; + } + + + int get_elem(const std::vector& v, int index) + { + return v[index]; + } + + std::pair pident(const std::pair& p) + { + return p; + } + + +} + + +%{ + + template struct Param + { + }; +%} + + +template struct Param +{ +}; + + +%template(Param_c) Param >; +%inline +{ + int hello(Param > c) + { + return 0; + } +} + +%inline +{ + struct A + { + }; +} + +%template() std::pair; +%template(pair_iA) std::pair; + + +%inline { + std::pair ident(std::pair a, const std::pair& b) + { + return std::pair(); + } +} + diff --git a/SWIG/Examples/test-suite/python/std_containers_runme.py b/SWIG/Examples/test-suite/python/std_containers_runme.py new file mode 100644 index 000000000..a048088bc --- /dev/null +++ b/SWIG/Examples/test-suite/python/std_containers_runme.py @@ -0,0 +1,53 @@ +import sys +import std_containers + + +cube = (((1, 2), (3, 4)), ((5, 6), (7, 8))) + + +if cube != std_containers.cident(cube): + raise RuntimeError, "bad cident" + + +p = (1,2) +if p != std_containers.pident(p): + raise RuntimeError, "bad pident" + +v = (1,2,3,4,5,6) + +if v != std_containers.vident(v): + raise RuntimeError, "bad pident" + + +if v != std_containers.videntu(v): + raise RuntimeError, "bad videntu" + +vu = std_containers.vector_ui(v) +if vu[2] != std_containers.videntu(vu)[2]: + raise RuntimeError, "bad videntu" + + +if v[0:3] != vu[0:3]: + raise RuntimeError, "bad getslice" + + +m = ((1,2,3),(2,3),(3,4)) +if m != std_containers.mident(m): + raise RuntimeError, "bad getslice" + + +mi = std_containers.imatrix(m) +mc = std_containers.cmatrix(m) +if mi[0][1] != mc[0][1]: + raise RuntimeError, "bad matrix" + + +map ={} +map['hello'] = 1 +map['hi'] = 2 +map['3'] = 2 + +if map != std_containers.mapident(map): + raise RuntimeError, "bad map" + +