summaryrefslogtreecommitdiff
path: root/Examples/test-suite/reference_global_vars.i
blob: 8c806599b71590b45896b6fe2835187211b3a80d (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
// Tests global reference variables:
//  - all non const primitives
//  - const and non const class

%module reference_global_vars

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

%inline %{
class TestClass {
public:
    int num;
    TestClass(int n = 0) : num(n) {}
};
%}

// const class reference variable
%{
const TestClass& global_constTestClass = TestClass(33);
%}
%inline %{
TestClass getconstTC() {
    return global_constTestClass;
}
%}

// Macro to help define similar functions
%define ref(type,name)
%{
static type initial_value_##name;
%}
%inline %{
static type &var_##name = initial_value_##name;
type setref_##name(type &x) {
    var_##name = x;
    return var_##name;
}
type& createref_##name(type x) {
    return *new type(x);
}
type value_##name(type &x) {
    return x;
}
%}
%enddef

// primitive reference variables
ref(bool,               bool);
ref(char,               char);
ref(unsigned char,      unsigned_char);
ref(signed char,        signed_char);
ref(short,              short);
ref(unsigned short,     unsigned_short);
ref(int,                int);
ref(unsigned int,       unsigned_int);
ref(long,               long);
ref(unsigned long,      unsigned_long);
ref(float,              float);
ref(double,             double);
ref(long long,          long_long);
ref(unsigned long long, unsigned_long_long);

// class reference variable
ref(TestClass,          TestClass);