PageRenderTime 41ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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