~ubuntu-branches/ubuntu/oneiric/swig1.3/oneiric

« back to all changes in this revision

Viewing changes to Examples/test-suite/li_std_vector_extra.i

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2009-11-15 14:00:28 UTC
  • mfrom: (1.2.9 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091115140028-me7amr2rie8zz1xn
Tags: 1.3.40-2ubuntu1
* Merge from Debian testing (LP: #356529), remaining changes:
  - Drop libchicken-dev from the build-depends (it's in universe)
  - Remove Pike from package description and from configure flags
  - drop "--without-mzscheme", we don't have it in our build-depends
  - use php-config5
  - Clean Runtime/ as well.
  - debian/rules (clean): Remove Lib/ocaml/swigp4.ml.
* debian/rules: Remove hardcoded python version.
* Remove upper limit for python from Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%module li_std_vector_extra
 
2
 
 
3
%warnfilter(509) overloaded1;
 
4
%warnfilter(509) overloaded2;
 
5
 
 
6
%include "std_string.i"
 
7
%include "std_vector.i"
 
8
%include "cpointer.i"
 
9
%include "carrays.i"
 
10
 
 
11
%{
 
12
#include <algorithm>
 
13
#include <functional>
 
14
#include <numeric>
 
15
%}
 
16
 
 
17
namespace std {
 
18
    %template() vector<short>;
 
19
    %template(IntVector) vector<int>;
 
20
    %template(BoolVector) vector<bool>;
 
21
    %template() vector<string>;
 
22
}
 
23
 
 
24
%template(DoubleVector) std::vector<double>;
 
25
 
 
26
 
 
27
%template(sizeVector) std::vector<size_t>;
 
28
%{
 
29
  template <class T>
 
30
  struct Param
 
31
  {
 
32
    T val;
 
33
 
 
34
    Param(T v = 0): val(v) {
 
35
    }
 
36
    
 
37
    operator T() const { return val; }
 
38
  };
 
39
%}
 
40
specialize_std_vector(Param<int>,PyInt_Check,PyInt_AsLong,PyInt_FromLong);
 
41
%template(PIntVector) std::vector<Param<int> >;
 
42
 
 
43
%inline %{
 
44
typedef float Real;
 
45
%}
 
46
 
 
47
namespace std {
 
48
    %template(RealVector) vector<Real>;
 
49
}
 
50
 
 
51
%inline %{
 
52
 
 
53
double average(std::vector<int> v) {
 
54
    return std::accumulate(v.begin(),v.end(),0.0)/v.size();
 
55
}
 
56
 
 
57
std::vector<Real> half(const std::vector<Real>& v) {
 
58
    std::vector<Real> w(v);
 
59
    for (std::vector<Real>::size_type i=0; i<w.size(); i++)
 
60
        w[i] /= 2.0;
 
61
    return w;
 
62
}
 
63
 
 
64
void halve_in_place(std::vector<double>& v) {
 
65
    std::transform(v.begin(),v.end(),v.begin(),
 
66
                   std::bind2nd(std::divides<double>(),2.0));
 
67
}
 
68
 
 
69
%}
 
70
 
 
71
%template(IntPtrVector) std::vector<int *>;
 
72
 
 
73
 
 
74
 
 
75
//
 
76
//
 
77
%{
 
78
#include <iostream>
 
79
%}
 
80
 
 
81
%inline %{
 
82
  
 
83
namespace Test {
 
84
struct A {
 
85
    virtual ~A() {}    
 
86
    virtual int f(const int i) const = 0;
 
87
};
 
88
 
 
89
struct B : public A {
 
90
  int val;
 
91
  
 
92
  B(int i = 0) : val(i)
 
93
  {
 
94
  }
 
95
  
 
96
  int f(const int i) const { return i + val; }
 
97
};
 
98
 
 
99
 
 
100
int vecAptr(const std::vector<A*>& v) {
 
101
    return v[0]->f(1);
 
102
}
 
103
 
 
104
 
105
 
 
106
std::vector<short> halfs(const std::vector<short>& v) {
 
107
    std::vector<short> w(v);
 
108
    for (std::vector<short>::size_type i=0; i<w.size(); i++)
 
109
        w[i] /= 2;
 
110
    return w;
 
111
}
 
112
 
 
113
 
 
114
std::vector<std::string>  vecStr(std::vector<std::string> v) {
 
115
  v[0] += v[1];
 
116
  return v;
 
117
}
 
118
 
 
119
%}
 
120
%template(VecB) std::vector<Test::B>; 
 
121
%template(VecA) std::vector<Test::A*>; 
 
122
 
 
123
%pointer_class(int,PtrInt)
 
124
%array_functions(int,ArrInt)
 
125
 
 
126
%inline %{
 
127
  int *makeIntPtr(int v) { return new int(v); }
 
128
  double *makeDoublePtr(double v) { return new double(v); }
 
129
  int extractInt(int *p) { return *p; }
 
130
%}
 
131
 
 
132
%template(pyvector) std::vector<swig::SwigPtr_PyObject>; 
 
133
 
 
134
namespace std {
 
135
   %template(ConstShortVector) vector<const short *>;
 
136
//   %template(ConstIntVector) vector<const int *>; // interferes with vector<int *>... see new testcase li_std_vector_ptr
 
137
}
 
138
 
 
139
%inline %{
 
140
std::string overloaded1(std::vector<double> vi) { return "vector<double>"; }
 
141
std::string overloaded1(std::vector<int> vi) { return "vector<int>"; }
 
142
std::string overloaded2(std::vector<int> vi) { return "vector<int>"; }
 
143
std::string overloaded2(std::vector<double> vi) { return "vector<double>"; }
 
144
std::string overloaded3(std::vector<int> *vi) { return "vector<int> *"; }
 
145
std::string overloaded3(int i) { return "int"; }
 
146
%}
 
147