/tags/rel-1-3-26/SWIG/Examples/test-suite/reference_global_vars.i
Swig | 63 lines | 56 code | 7 blank | 0 comment | 0 complexity | bf83ca56d853465d4f93876bede3d1bc MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1// Tests global reference variables: 2// - all non const primitives 3// - const and non const class 4 5%module reference_global_vars 6 7%inline %{ 8class TestClass { 9public: 10 int num; 11 TestClass(int n = 0) : num(n) {} 12}; 13%} 14 15// const class reference variable 16%{ 17const TestClass& global_constTestClass = TestClass(33); 18%} 19%inline %{ 20TestClass getconstTC() { 21 return global_constTestClass; 22} 23%} 24 25// Macro to help define similar functions 26%define ref(type,name) 27%{ 28static type initial_value_##name; 29%} 30%inline %{ 31static type &var_##name = initial_value_##name; 32type setref_##name(type &x) { 33 var_##name = x; 34 return var_##name; 35} 36type& createref_##name(type x) { 37 return *new type(x); 38} 39type value_##name(type &x) { 40 return x; 41} 42%} 43%enddef 44 45// primitive reference variables 46ref(bool, bool); 47ref(char, char); 48ref(unsigned char, unsigned_char); 49ref(signed char, signed_char); 50ref(short, short); 51ref(unsigned short, unsigned_short); 52ref(int, int); 53ref(unsigned int, unsigned_int); 54ref(long, long); 55ref(unsigned long, unsigned_long); 56ref(float, float); 57ref(double, double); 58ref(long long, long_long); 59ref(unsigned long long, unsigned_long_long); 60 61// class reference variable 62ref(TestClass, TestClass); 63