PageRenderTime 26ms CodeModel.GetById 21ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/python/functor/example.i

#
Swig | 29 lines | 19 code | 9 blank | 1 comment | 0 complexity | b66702553b0954370abef23b5d098791 MD5 | raw file
 1/* File : example.i */
 2%module example
 3
 4
 5%inline %{
 6// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
 7template<class T> class Sum {
 8   T res;
 9public:
10   Sum(T i = 0) : res(i) { }
11   void operator() (T x) { res += x; }
12   T result() const { return res; }
13};
14
15%}
16
17// Rename the application operator to __call__ for python.
18// Note: this is normally automatic, but if you had to do it yourself
19// you would use this directive:
20//
21// %rename(__call__) *::operator();
22
23// Instantiate a few versions
24%template(intSum) Sum<int>;
25%template(doubleSum) Sum<double>;
26
27
28
29