Upstream version 1.3.40
[profile/ivi/swig.git] / Examples / ruby / functor / example.i
1 /* File : example.i */
2 %module example
3
4 %inline %{
5 // From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
6 template<class T> class Sum {
7    T res;
8 public:
9    Sum(T i = 0) : res(i) { }
10    void operator() (T x) { res += x; }
11    T result() const { return res; }
12 };
13
14 %}
15
16 /**
17  * Rename the application operator to call() for Ruby.
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
24 // Instantiate a few versions
25 %template(IntSum) Sum<int>;
26 %template(DoubleSum) Sum<double>;