PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 65 lines | 57 code | 8 blank | 0 comment | 0 complexity | 369a6171dd7b1afba290a11135d7da28 MD5 | raw file
 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 %{
10class TestClass {
11public:
12    int num;
13    TestClass(int n = 0) : num(n) {}
14};
15%}
16
17// const class reference variable
18%{
19const TestClass& global_constTestClass = TestClass(33);
20%}
21%inline %{
22TestClass getconstTC() {
23    return global_constTestClass;
24}
25%}
26
27// Macro to help define similar functions
28%define ref(type,name)
29%{
30static type initial_value_##name;
31%}
32%inline %{
33static type &var_##name = initial_value_##name;
34type setref_##name(type &x) {
35    var_##name = x;
36    return var_##name;
37}
38type& createref_##name(type x) {
39    return *new type(x);
40}
41type value_##name(type &x) {
42    return x;
43}
44%}
45%enddef
46
47// primitive reference variables
48ref(bool,               bool);
49ref(char,               char);
50ref(unsigned char,      unsigned_char);
51ref(signed char,        signed_char);
52ref(short,              short);
53ref(unsigned short,     unsigned_short);
54ref(int,                int);
55ref(unsigned int,       unsigned_int);
56ref(long,               long);
57ref(unsigned long,      unsigned_long);
58ref(float,              float);
59ref(double,             double);
60ref(long long,          long_long);
61ref(unsigned long long, unsigned_long_long);
62
63// class reference variable
64ref(TestClass,          TestClass);
65