PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

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