1 // Tests global reference variables:
2 // - all non const primitives
3 // - const and non const class
5 %module reference_global_vars
7 %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */
13 TestClass(int n = 0) : num(n) {}
17 // const class reference variable
19 const TestClass& global_constTestClass = TestClass(33);
22 TestClass getconstTC() {
23 return global_constTestClass;
27 // Macro to help define similar functions
28 %define ref(type,name)
30 static type initial_value_##name;
33 static type &var_##name = initial_value_##name;
34 type setref_##name(type &x) {
38 type& createref_##name(type x) {
41 type value_##name(type &x) {
47 // primitive reference variables
50 ref(unsigned char, unsigned_char);
51 ref(signed char, signed_char);
53 ref(unsigned short, unsigned_short);
55 ref(unsigned int, unsigned_int);
57 ref(unsigned long, unsigned_long);
60 ref(long long, long_long);
61 ref(unsigned long long, unsigned_long_long);
63 // class reference variable
64 ref(TestClass, TestClass);