/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Examples/test-suite/cpp_namespace.i

# · Swig · 104 lines · 77 code · 26 blank · 1 comment · 0 complexity · 690f1d7e579bb4b42d2f4fb82416ebbb MD5 · raw file

  1. // C++ namespace tests
  2. %module cpp_namespace
  3. %inline %{
  4. typedef int Bad;
  5. /* A very basic namespace */
  6. namespace example {
  7. typedef char *Bad;
  8. int fact(int n) {
  9. if (n <= 0) return 1;
  10. else return n*fact(n-1);
  11. }
  12. int Foo = 42;
  13. class Test {
  14. public:
  15. Test() { };
  16. ~Test() { };
  17. char *method() {
  18. return (char *) "Test::method";
  19. }
  20. };
  21. typedef Test *TestPtr;
  22. void weird(Bad x, ::Bad y) { };
  23. }
  24. char *do_method(example::TestPtr t) {
  25. return t->method();
  26. }
  27. namespace ex = example;
  28. char *do_method2(ex::TestPtr t) {
  29. return t->method();
  30. }
  31. %}
  32. // Some more complicated namespace examples
  33. %inline %{
  34. namespace Foo {
  35. typedef int Integer;
  36. class Test2 {
  37. public:
  38. virtual char *method() {
  39. return (char *) "Test2::method";
  40. }
  41. };
  42. typedef Test2 *Test2Ptr;
  43. }
  44. namespace Foo2 {
  45. using Foo::Integer;
  46. using Foo::Test2;
  47. class Test3 : public Test2 {
  48. public:
  49. virtual char *method() {
  50. return (char *) "Test3::method";
  51. }
  52. };
  53. typedef Test3 *Test3Ptr;
  54. typedef Test3 Test3Alt;
  55. }
  56. namespace Foo3 {
  57. using namespace Foo2;
  58. class Test4 : public Test3 {
  59. public:
  60. virtual char *method() {
  61. return (char *) "Test4::method";
  62. }
  63. };
  64. Integer foo3(Integer x) { return x; }
  65. typedef Test4 *Test4Ptr;
  66. }
  67. using Foo2::Test3Alt;
  68. using Foo3::Integer;
  69. class Test5 : public Test3Alt {
  70. public:
  71. virtual char *method() {
  72. return (char *) "Test5::method";
  73. }
  74. };
  75. char *do_method3(Foo::Test2 *t, Integer x) {
  76. return t->method();
  77. }
  78. %}