summaryrefslogtreecommitdiff
path: root/Examples/test-suite/cpp_namespace.i
blob: d7bf95e9f98e40c4374ffce32a163fc0f225b86a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// C++ namespace tests

%module cpp_namespace

%inline %{
  typedef int Bad;

  /* A very basic namespace */
  namespace example {
    typedef char *Bad;

    int fact(int n) {
      if (n <= 0) return 1;
      else return n*fact(n-1);
    }
    int Foo = 42;

    class Test {
    public:
      Test() { }
      ~Test() { }
      char *method() {
	return (char *) "Test::method";
      }
    };
    typedef Test *TestPtr;
    void weird(Bad x, ::Bad y) { }
  }

  char *do_method(example::TestPtr t) {
    return t->method();
  }

  namespace ex = example;

  char *do_method2(ex::TestPtr t) {
     return t->method();
  }

%}

// Some more complicated namespace examples

%inline %{
namespace Foo {
   typedef int Integer;
   class Test2 { 
   public:
       virtual ~Test2() { }
       virtual char *method() {	
	 return (char *) "Test2::method";
       }
   };
  typedef Test2 *Test2Ptr;
}

namespace Foo2 {
  using Foo::Integer;
  using Foo::Test2;
  class Test3 : public Test2 {
  public:
    virtual char *method() {	
      return (char *) "Test3::method";
    }
  };
  typedef Test3 *Test3Ptr;
  typedef Test3 Test3Alt;
}

namespace Foo3 {
  using namespace Foo2;
  class Test4 : public Test3 {
  public:
    virtual char *method() {	
      return (char *) "Test4::method";
    }
  };
  Integer foo3(Integer x) { return x; }
  typedef Test4 *Test4Ptr;
  
}
   
using Foo2::Test3Alt;
using Foo3::Integer;

class Test5 : public Test3Alt { 
public:
  virtual char *method() {	
    return (char *) "Test5::method";
  }
};

char *do_method3(Foo::Test2 *t, Integer x) {
  return t->method();
}

%}