PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/virtual_derivation.i

#
Swig | 67 lines | 39 code | 15 blank | 13 comment | 0 complexity | ee25d4e333e17a5f8c4dddf98a80bfc3 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module virtual_derivation
  2. /*
  3. Try to add to your favorite language a runtime test like
  4. this:
  5. b = B(3)
  6. if (b.get_a() != b.get_b()):
  7. print "something is wrong"
  8. The test runs fine with python, but not with ruby.
  9. */
  10. %inline %{
  11. struct A
  12. {
  13. ~A()
  14. {
  15. }
  16. int m_a;
  17. A(int a) :m_a(a)
  18. {
  19. }
  20. int get_a()
  21. {
  22. return m_a;
  23. }
  24. };
  25. struct B : virtual A
  26. {
  27. B(int a): A(a)
  28. {
  29. }
  30. int get_b()
  31. {
  32. return get_a();
  33. }
  34. // in ruby, get_a() returns trash if called from b, unless is
  35. // wrapped with the previous get_b or using the 'using'
  36. // declaration:
  37. // using A::get_a;
  38. };
  39. class IndexReader{
  40. public:
  41. virtual void norms() = 0;
  42. };
  43. class MultiReader : public IndexReader {
  44. protected:
  45. MultiReader();
  46. };
  47. %}