PageRenderTime 30ms CodeModel.GetById 18ms app.highlight 10ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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 char *method() {	
 50	 return (char *) "Test2::method";
 51       }
 52   };
 53  typedef Test2 *Test2Ptr;
 54}
 55
 56namespace Foo2 {
 57  using Foo::Integer;
 58  using Foo::Test2;
 59  class Test3 : public Test2 {
 60  public:
 61    virtual char *method() {	
 62      return (char *) "Test3::method";
 63    }
 64  };
 65  typedef Test3 *Test3Ptr;
 66  typedef Test3 Test3Alt;
 67}
 68
 69namespace Foo3 {
 70  using namespace Foo2;
 71  class Test4 : public Test3 {
 72  public:
 73    virtual char *method() {	
 74      return (char *) "Test4::method";
 75    }
 76  };
 77  Integer foo3(Integer x) { return x; }
 78  typedef Test4 *Test4Ptr;
 79  
 80}
 81   
 82using Foo2::Test3Alt;
 83using Foo3::Integer;
 84
 85class Test5 : public Test3Alt { 
 86public:
 87  virtual char *method() {	
 88    return (char *) "Test5::method";
 89  }
 90};
 91
 92char *do_method3(Foo::Test2 *t, Integer x) {
 93  return t->method();
 94}
 95
 96%}
 97
 98
 99
100   
101
102
103      	
104