PageRenderTime 219ms CodeModel.GetById 23ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
Swig | 74 lines | 64 code | 10 blank | 0 comment | 0 complexity | fb1e769945ad02171ace5071eca49fb5 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module smart_pointer_const_overload
  2. %warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar::operator->; // Overloaded method Bar::operator ->() ignored
  3. %warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar2::operator->; // Overloaded method Bar2::operator ->() ignored
  4. %inline %{
  5. int CONST_ACCESS = 1;
  6. int MUTABLE_ACCESS = 2;
  7. int *new_int(int ivalue) {
  8. int *i = (int *) malloc(sizeof(ivalue));
  9. *i = ivalue;
  10. return i;
  11. }
  12. int get_int(int *i) {
  13. return *i;
  14. }
  15. void set_int(int *i, int ivalue) {
  16. *i = ivalue;
  17. }
  18. void delete_int(int *i) {
  19. free(i);
  20. }
  21. struct Foo {
  22. int x;
  23. int * const xp;
  24. const int y;
  25. const int *yp;
  26. int access;
  27. Foo() : x(0), xp(&x), y(0), yp(&y), access(0) { }
  28. int getx() const { return x; }
  29. void setx(int x_) { x = x_; }
  30. static void stat() {}
  31. };
  32. %}
  33. %extend Foo {
  34. int getx2() const { return self->x; }
  35. void setx2(int x_) { self->x = x_; }
  36. };
  37. %inline %{
  38. class Bar {
  39. Foo *f;
  40. public:
  41. Bar(Foo *f) : f(f) { }
  42. const Foo *operator->() const {
  43. f->access = CONST_ACCESS;
  44. return f;
  45. }
  46. Foo *operator->() {
  47. f->access = MUTABLE_ACCESS;
  48. return f;
  49. }
  50. };
  51. class Bar2 {
  52. Foo *f;
  53. public:
  54. Bar2(Foo *f) : f(f) { }
  55. Foo *operator->() {
  56. f->access = MUTABLE_ACCESS;
  57. return f;
  58. }
  59. const Foo *operator->() const {
  60. f->access = CONST_ACCESS;
  61. return f;
  62. }
  63. };
  64. %}