summaryrefslogtreecommitdiff
path: root/Examples/test-suite/li_std_vector_extra.i
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2008-11-26 23:04:18 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2008-11-26 23:04:18 +0000
commit3041db155db096a39c826deb73ccf44485a38529 (patch)
tree262aaa03bf7bb71616f6fb387af7b6f7b2756f35 /Examples/test-suite/li_std_vector_extra.i
parentb266e1f68cedf1601e386ecedca3cce324803661 (diff)
downloadswig-3041db155db096a39c826deb73ccf44485a38529.tar.gz
modifying build system not to rely on the -I path to find the input files avoiding warning 125: merge .i files that are common between python and the main version
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10954 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/test-suite/li_std_vector_extra.i')
-rw-r--r--Examples/test-suite/li_std_vector_extra.i141
1 files changed, 141 insertions, 0 deletions
diff --git a/Examples/test-suite/li_std_vector_extra.i b/Examples/test-suite/li_std_vector_extra.i
new file mode 100644
index 000000000..17baffe04
--- /dev/null
+++ b/Examples/test-suite/li_std_vector_extra.i
@@ -0,0 +1,141 @@
+%module li_std_vector_extra
+
+%warnfilter(509) overloaded1;
+%warnfilter(509) overloaded2;
+
+%include "std_string.i"
+%include "std_vector.i"
+%include "cpointer.i"
+%include "carrays.i"
+
+%{
+#include <algorithm>
+#include <functional>
+#include <numeric>
+%}
+
+namespace std {
+ %template() vector<short>;
+ %template(IntVector) vector<int>;
+ %template(BoolVector) vector<bool>;
+ %template() vector<string>;
+}
+
+%template(DoubleVector) std::vector<double>;
+
+
+%template(sizeVector) std::vector<size_t>;
+%{
+ template <class T>
+ struct Param
+ {
+ T val;
+
+ Param(T v = 0): val(v) {
+ }
+
+ operator T() const { return val; }
+ };
+%}
+specialize_std_vector(Param<int>,PyInt_Check,PyInt_AsLong,PyInt_FromLong);
+%template(PIntVector) std::vector<Param<int> >;
+
+%inline %{
+typedef float Real;
+%}
+
+namespace std {
+ %template(RealVector) vector<Real>;
+}
+
+%inline %{
+
+double average(std::vector<int> v) {
+ return std::accumulate(v.begin(),v.end(),0.0)/v.size();
+}
+
+std::vector<Real> half(const std::vector<Real>& v) {
+ std::vector<Real> w(v);
+ for (std::vector<Real>::size_type i=0; i<w.size(); i++)
+ w[i] /= 2.0;
+ return w;
+}
+
+void halve_in_place(std::vector<double>& v) {
+ std::transform(v.begin(),v.end(),v.begin(),
+ std::bind2nd(std::divides<double>(),2.0));
+}
+
+%}
+
+%template(IntPtrVector) std::vector<int *>;
+
+
+
+//
+//
+%{
+#include <iostream>
+%}
+
+%inline %{
+
+namespace Test {
+struct A {
+ virtual ~A() {}
+ virtual int f(const int i) const = 0;
+};
+
+struct B : public A {
+ int val;
+
+ B(int i = 0) : val(i)
+ {
+ }
+
+ int f(const int i) const { return i + val; }
+};
+
+
+int vecAptr(const std::vector<A*>& v) {
+ return v[0]->f(1);
+}
+
+}
+
+std::vector<short> halfs(const std::vector<short>& v) {
+ std::vector<short> w(v);
+ for (std::vector<short>::size_type i=0; i<w.size(); i++)
+ w[i] /= 2;
+ return w;
+}
+
+
+std::vector<std::string> vecStr(std::vector<std::string> v) {
+ v[0] += v[1];
+ return v;
+}
+
+%}
+%template(VecB) std::vector<Test::B>;
+%template(VecA) std::vector<Test::A*>;
+
+%pointer_class(int,PtrInt)
+%array_functions(int,ArrInt)
+
+
+%template(pyvector) std::vector<swig::PyObject_ptr>;
+
+namespace std {
+ %template(ConstIntVector) vector<const int *>;
+}
+
+%inline %{
+std::string overloaded1(std::vector<double> vi) { return "vector<double>"; }
+std::string overloaded1(std::vector<int> vi) { return "vector<int>"; }
+std::string overloaded2(std::vector<int> vi) { return "vector<int>"; }
+std::string overloaded2(std::vector<double> vi) { return "vector<double>"; }
+std::string overloaded3(std::vector<int> *vi) { return "vector<int> *"; }
+std::string overloaded3(int i) { return "int"; }
+%}
+