PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 105 lines | 78 code | 26 blank | 1 comment | 0 complexity | 28c898dd9d97e95552060e3c4ab928b5 MD5 | raw file
  1// C++ namespace tests
  2
  3%module cpp_namespace
  4
  5%inline %{
  6  typedef int Bad;
  7
  8  /* A very basic namespace */
  9  namespace example {
 10    typedef char *Bad;
 11
 12    int fact(int n) {
 13      if (n <= 0) return 1;
 14      else return n*fact(n-1);
 15    }
 16    int Foo = 42;
 17
 18    class Test {
 19    public:
 20      Test() { }
 21      ~Test() { }
 22      char *method() {
 23	return (char *) "Test::method";
 24      }
 25    };
 26    typedef Test *TestPtr;
 27    void weird(Bad x, ::Bad y) { }
 28  }
 29
 30  char *do_method(example::TestPtr t) {
 31    return t->method();
 32  }
 33
 34  namespace ex = example;
 35
 36  char *do_method2(ex::TestPtr t) {
 37     return t->method();
 38  }
 39
 40%}
 41
 42// Some more complicated namespace examples
 43
 44%inline %{
 45namespace Foo {
 46   typedef int Integer;
 47   class Test2 { 
 48   public:
 49       virtual ~Test2() { }
 50       virtual char *method() {	
 51	 return (char *) "Test2::method";
 52       }
 53   };
 54  typedef Test2 *Test2Ptr;
 55}
 56
 57namespace Foo2 {
 58  using Foo::Integer;
 59  using Foo::Test2;
 60  class Test3 : public Test2 {
 61  public:
 62    virtual char *method() {	
 63      return (char *) "Test3::method";
 64    }
 65  };
 66  typedef Test3 *Test3Ptr;
 67  typedef Test3 Test3Alt;
 68}
 69
 70namespace Foo3 {
 71  using namespace Foo2;
 72  class Test4 : public Test3 {
 73  public:
 74    virtual char *method() {	
 75      return (char *) "Test4::method";
 76    }
 77  };
 78  Integer foo3(Integer x) { return x; }
 79  typedef Test4 *Test4Ptr;
 80  
 81}
 82   
 83using Foo2::Test3Alt;
 84using Foo3::Integer;
 85
 86class Test5 : public Test3Alt { 
 87public:
 88  virtual char *method() {	
 89    return (char *) "Test5::method";
 90  }
 91};
 92
 93char *do_method3(Foo::Test2 *t, Integer x) {
 94  return t->method();
 95}
 96
 97%}
 98
 99
100
101   
102
103
104      	
105