PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
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. %module reference_global_vars
  5. %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */
  6. %inline %{
  7. class TestClass {
  8. public:
  9. int num;
  10. TestClass(int n = 0) : num(n) {}
  11. };
  12. %}
  13. // const class reference variable
  14. %{
  15. const TestClass& global_constTestClass = TestClass(33);
  16. %}
  17. %inline %{
  18. TestClass getconstTC() {
  19. return global_constTestClass;
  20. }
  21. %}
  22. // Macro to help define similar functions
  23. %define ref(type,name)
  24. %{
  25. static type initial_value_##name;
  26. %}
  27. %inline %{
  28. static type &var_##name = initial_value_##name;
  29. type setref_##name(type &x) {
  30. var_##name = x;
  31. return var_##name;
  32. }
  33. type& createref_##name(type x) {
  34. return *new type(x);
  35. }
  36. type value_##name(type &x) {
  37. return x;
  38. }
  39. %}
  40. %enddef
  41. // primitive reference variables
  42. ref(bool, bool);
  43. ref(char, char);
  44. ref(unsigned char, unsigned_char);
  45. ref(signed char, signed_char);
  46. ref(short, short);
  47. ref(unsigned short, unsigned_short);
  48. ref(int, int);
  49. ref(unsigned int, unsigned_int);
  50. ref(long, long);
  51. ref(unsigned long, unsigned_long);
  52. ref(float, float);
  53. ref(double, double);
  54. ref(long long, long_long);
  55. ref(unsigned long long, unsigned_long_long);
  56. // class reference variable
  57. ref(TestClass, TestClass);