/trunk/Examples/ruby/functor/example.i
Swig | 26 lines | 14 code | 4 blank | 8 comment | 0 complexity | e213861e4bd8bdd93407786b3082a507 MD5 | raw file
1/* File : example.i */ 2%module example 3 4%inline %{ 5// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514 6template<class T> class Sum { 7 T res; 8public: 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>;