PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/ruby/functor/example.i

#
Swig | 26 lines | 14 code | 4 blank | 8 comment | 0 complexity | e213861e4bd8bdd93407786b3082a507 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* File : example.i */
  2. %module example
  3. %inline %{
  4. // From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
  5. template<class T> class Sum {
  6. T res;
  7. public:
  8. Sum(T i = 0) : res(i) { }
  9. void operator() (T x) { res += x; }
  10. T result() const { return res; }
  11. };
  12. %}
  13. /**
  14. * Rename the application operator to call() for Ruby.
  15. * Note: this is normally automatic, but if you had to do it yourself
  16. * you would use this directive:
  17. *
  18. * %rename(call) *::operator();
  19. */
  20. // Instantiate a few versions
  21. %template(IntSum) Sum<int>;
  22. %template(DoubleSum) Sum<double>;