/tags/rel-1-3-29/SWIG/Examples/test-suite/template_inherit.i

# · Swig · 41 lines · 31 code · 8 blank · 2 comment · 0 complexity · f6f52c19e4cf995b0aded78a64d5d2f2 MD5 · raw file

  1. /* File : example.i */
  2. %module template_inherit
  3. /* This example tests template inheritance to see if it actually works */
  4. %inline %{
  5. template<class T> class Foo {
  6. public:
  7. virtual ~Foo() { }
  8. virtual char *blah() {
  9. return (char *) "Foo";
  10. }
  11. virtual char *foomethod() {
  12. return (char *) "foomethod";
  13. }
  14. };
  15. template<class T> class Bar : public Foo<T> {
  16. public:
  17. virtual char *blah() {
  18. return (char *) "Bar";
  19. }
  20. };
  21. template<class T> char *invoke_blah(Foo<T> *x) {
  22. return x->blah();
  23. }
  24. %}
  25. %template(FooInt) Foo<int>;
  26. %template(FooDouble) Foo<double>;
  27. %template(FooUInt) Foo<unsigned int>;
  28. %template(BarInt) Bar<int>;
  29. %template(BarDouble) Bar<double>;
  30. %template(BarUInt) Bar<unsigned>;
  31. %template(invoke_blah_int) invoke_blah<int>;
  32. %template(invoke_blah_double) invoke_blah<double>;
  33. %template(invoke_blah_uint) invoke_blah<int unsigned>;