1
%module li_std_vector_extra
3
%warnfilter(509) overloaded1;
4
%warnfilter(509) overloaded2;
6
%include "std_string.i"
7
%include "std_vector.i"
18
%template() vector<short>;
19
%template(IntVector) vector<int>;
20
%template(BoolVector) vector<bool>;
21
%template() vector<string>;
24
%template(DoubleVector) std::vector<double>;
27
%template(sizeVector) std::vector<size_t>;
34
Param(T v = 0): val(v) {
37
operator T() const { return val; }
40
specialize_std_vector(Param<int>,PyInt_Check,PyInt_AsLong,PyInt_FromLong);
41
%template(PIntVector) std::vector<Param<int> >;
48
%template(RealVector) vector<Real>;
53
double average(std::vector<int> v) {
54
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
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++)
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));
71
%template(IntPtrVector) std::vector<int *>;
86
virtual int f(const int i) const = 0;
96
int f(const int i) const { return i + val; }
100
int vecAptr(const std::vector<A*>& v) {
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++)
114
std::vector<std::string> vecStr(std::vector<std::string> v) {
120
%template(VecB) std::vector<Test::B>;
121
%template(VecA) std::vector<Test::A*>;
123
%pointer_class(int,PtrInt)
124
%array_functions(int,ArrInt)
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; }
132
%template(pyvector) std::vector<swig::SwigPtr_PyObject>;
135
%template(ConstShortVector) vector<const short *>;
136
// %template(ConstIntVector) vector<const int *>; // interferes with vector<int *>... see new testcase li_std_vector_ptr
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"; }