PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 103 lines | 83 code | 20 blank | 0 comment | 0 complexity | f852310808e2628699bb97203e356321 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module extend_variable
  2. // Tests %extend for variables
  3. %inline %{
  4. class ExtendMe {
  5. double var;
  6. public:
  7. ExtendMe() : var(0.0) {}
  8. bool get(double &d) {
  9. d = var;
  10. return true;
  11. }
  12. bool set(const double &d) {
  13. var = d;
  14. return true;
  15. }
  16. };
  17. %}
  18. %extend ExtendMe {
  19. double ExtendVar;
  20. };
  21. %{
  22. // If possible, all language modules should use this naming format for consistency
  23. void ExtendMe_ExtendVar_set(ExtendMe *thisptr, double value) {
  24. thisptr->set(value);
  25. }
  26. double ExtendMe_ExtendVar_get(ExtendMe *thisptr) {
  27. double value = 0;
  28. thisptr->get(value);
  29. return value;
  30. }
  31. %}
  32. %{
  33. class Foo
  34. {
  35. };
  36. %}
  37. #if SWIGJAVA
  38. %javaconst(1) AllBarOne;
  39. #elif SWIGCSHARP
  40. %csconst(1) AllBarOne;
  41. #endif
  42. class Foo {
  43. public:
  44. %extend {
  45. static const int Bar = 42;
  46. static const int AllBarOne = 4422;
  47. static const int StaticConstInt;
  48. static int StaticInt;
  49. }
  50. };
  51. %{
  52. int globalVariable = 1111;
  53. void Foo_StaticInt_set(int value) {
  54. globalVariable = value;
  55. }
  56. int Foo_StaticInt_get() {
  57. return globalVariable;
  58. }
  59. int Foo_StaticConstInt_get() {
  60. static int var = 2222;
  61. return var;
  62. }
  63. %}
  64. %inline {
  65. namespace ns1
  66. {
  67. struct Bar
  68. {
  69. }
  70. ;
  71. }
  72. }
  73. %{
  74. int ns1_Bar_x_get(ns1::Bar *self) {
  75. return 1;
  76. }
  77. void ns1_Bar_x_set(ns1::Bar *self, int x) {
  78. }
  79. %}
  80. %extend ns1::Bar
  81. {
  82. int x;
  83. }