/trunk/Examples/test-suite/cpp_basic.i
Swig | 113 lines | 82 code | 29 blank | 2 comment | 0 complexity | 7611d910e7253d5ecb68bc7450b59501 MD5 | raw file
1/* This is a basic test of proxy classes, used by chicken */ 2 3%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */ 4 5%warnfilter(SWIGWARN_RUBY_WRONG_NAME) global_cint; /* Ruby, wrong constant name */ 6 7%module cpp_basic 8 9%newobject Bar::testFoo; 10 11%{ 12#if defined(__SUNPRO_CC) 13#pragma error_messages (off, wbadasg) /* Assigning extern "C" ... */ 14#endif 15%} 16 17%inline %{ 18 19class Foo { 20 public: 21 Foo(int a) : num(a) {} 22 int num; 23 24 int func1(int a) { 25 return 2*a*num; 26 } 27 28 int func2(int a) { 29 return -a*num; 30 } 31 32 int (Foo::*func_ptr)(int); 33}; 34 35%} 36 37%{ 38static Foo init_ref = Foo(-4); 39%} 40 41%inline %{ 42class Bar { 43 public: 44 Bar() : fptr(0), fref(init_ref), fval(15) , cint(3) {} 45 46 Foo *fptr; 47 Foo &fref; 48 Foo fval; 49 50 const int cint; 51 static const int global_cint = -4; 52 53 static Foo *global_fptr; 54 static Foo &global_fref; 55 static Foo global_fval; 56 57 int test(int a, Foo *f) { 58 return a + (f ? f->num : 0) + fval.num; 59 } 60 61 Foo *testFoo(int a, Foo *f) { 62 return new Foo(2 * a + (f ? f->num : 0) + fval.num); 63 } 64private: 65 Bar& operator=(const Bar&); 66}; 67 68%} 69 70%{ 71Foo *Bar::global_fptr = NULL; 72Foo &Bar::global_fref = init_ref; 73Foo Bar::global_fval = Foo(3); 74%} 75 76/* member function tests */ 77%inline %{ 78int (Foo::*get_func1_ptr())(int) { 79 return &Foo::func1; 80} 81 82int (Foo::*get_func2_ptr())(int) { 83 return &Foo::func2; 84} 85 86int test_func_ptr(Foo *f, int a) { 87 return (f->*(f->func_ptr))(a); 88} 89 90%} 91 92 93#ifdef __cplusplus 94%define MACRO_WINDOW_SHOW 95void show(void *count = 0, void *data = 0) 96{ 97 return; 98} 99%enddef 100 101%inline %{ 102 class Fl_Window { 103 public: 104 Fl_Window() {}; 105 ~Fl_Window() {}; 106 }; 107%} 108 109%extend Fl_Window { 110 MACRO_WINDOW_SHOW 111} 112 113#endif