aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/cpp_basic.i
blob: 4c7dfae1ef241983eaaabfcab74b60008edbdb84 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* This is a basic test of proxy classes */

%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK);                   /* memory leak when setting a ptr/ref variable */

%warnfilter(SWIGWARN_RUBY_WRONG_NAME) global_cint;       /* Ruby, wrong constant name */

%feature("php:allowdynamicproperties", 1) Foo; /* Allow PHP-specific custom property testing in _runme.php */
%feature("php:allowdynamicproperties", 0) Bar; /* and that this doesn't allow custom properties. */

%module cpp_basic

%newobject Bar::testFoo;

%{
#if defined(__SUNPRO_CC)
#pragma error_messages (off, wbadasg) /* Assigning extern "C" ... */
#endif
%}

%inline %{

class Foo {
  public:
    Foo(int a) : num(a) {}
    int num;

    int func1(int a) {
      return 2*a*num;
    }
    
    int func2(int a) {
      return -a*num;
    }
    
    int (Foo::*func_ptr)(int);

    const char* __str__() const { return "Foo"; }
};

class FooSub : public Foo {
  public:
    FooSub() :Foo(42) {}
};

class FooSubSub : public FooSub {
  public:
    FooSubSub() : FooSub() {}
    const char* __str__() const { return "FooSubSub"; }
};

Foo& get_reference(Foo& other) { return other; }
const Foo& get_const_reference(const Foo& other) { return other; }

%}

%{
static Foo init_ref = Foo(-4);
%}

%inline %{
class Bar {
  public:
    Bar() : fptr(0), fref(init_ref), fval(15) , cint(3) {}
  
    Foo *fptr;
    Foo &fref;
    Foo fval;

    const int cint;
    static const int global_cint = -4;

    static Foo *global_fptr;
    static Foo &global_fref;
    static Foo global_fval;

    int test(int a, Foo *f) {
      return a + (f ? f->num : 0) + fval.num;
    }

    Foo *testFoo(int a, Foo *f) {
      return new Foo(2 * a + (f ? f->num : 0) + fval.num);
    }
/* Const member data and references mean this class can't be assigned. */
private:
    Bar& operator=(const Bar&);
};

// This class is valid C++ but cannot be assigned to because it has const member data.
struct JustConst {
explicit JustConst(int i_inp) : i(i_inp) {}
const int i;
};

%}

%{
Foo *Bar::global_fptr = NULL;
Foo &Bar::global_fref = init_ref;
Foo Bar::global_fval = Foo(3);
%}

/* member function tests */
%inline %{
int (Foo::*get_func1_ptr())(int) {
  return &Foo::func1;
}

int (Foo::*get_func2_ptr())(int) {
  return &Foo::func2;
}

int test_func_ptr(Foo *f, int a) {
  return (f->*(f->func_ptr))(a);
}

%}


#ifdef __cplusplus
%define MACRO_WINDOW_SHOW
void show(void *count = 0, void *data = 0)
{
  return;
}
%enddef

%inline %{
  class Fl_Window {
  public:
    Fl_Window() {};
    ~Fl_Window() {};
  };
%}

%extend Fl_Window {
  MACRO_WINDOW_SHOW
}

#endif