import source from 1.3.40
[external/swig.git] / Examples / test-suite / reference_global_vars.i
1 // Tests global reference variables:
2 //  - all non const primitives
3 //  - const and non const class
4
5 %module reference_global_vars
6
7 %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK);      /* memory leak when setting a ptr/ref variable */
8
9 %inline %{
10 class TestClass {
11 public:
12     int num;
13     TestClass(int n = 0) : num(n) {}
14 };
15 %}
16
17 // const class reference variable
18 %{
19 const TestClass& global_constTestClass = TestClass(33);
20 %}
21 %inline %{
22 TestClass getconstTC() {
23     return global_constTestClass;
24 }
25 %}
26
27 // Macro to help define similar functions
28 %define ref(type,name)
29 %{
30 static type initial_value_##name;
31 %}
32 %inline %{
33 static type &var_##name = initial_value_##name;
34 type setref_##name(type &x) {
35     var_##name = x;
36     return var_##name;
37 }
38 type& createref_##name(type x) {
39     return *new type(x);
40 }
41 type value_##name(type &x) {
42     return x;
43 }
44 %}
45 %enddef
46
47 // primitive reference variables
48 ref(bool,               bool);
49 ref(char,               char);
50 ref(unsigned char,      unsigned_char);
51 ref(signed char,        signed_char);
52 ref(short,              short);
53 ref(unsigned short,     unsigned_short);
54 ref(int,                int);
55 ref(unsigned int,       unsigned_int);
56 ref(long,               long);
57 ref(unsigned long,      unsigned_long);
58 ref(float,              float);
59 ref(double,             double);
60 ref(long long,          long_long);
61 ref(unsigned long long, unsigned_long_long);
62
63 // class reference variable
64 ref(TestClass,          TestClass);
65