PageRenderTime 29ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 53 lines | 40 code | 11 blank | 2 comment | 0 complexity | 5d9d24bdec08345fc02ca02d391a1716 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* This test a return by value constant SWIGTYPE.
  2. It was reported in bug 899332 by Jermey Brown (jhbrown94) */
  3. %module return_const_value
  4. %ignore Foo_ptr::operator=(const Foo_ptr&);
  5. %inline %{
  6. class Foo {
  7. public:
  8. int _val;
  9. Foo(int x): _val(x) {}
  10. int getVal() const {
  11. return _val;
  12. }
  13. };
  14. class Foo_ptr {
  15. Foo *_ptr;
  16. mutable bool _own;
  17. public:
  18. Foo_ptr(Foo *p, bool own = false): _ptr(p), _own(own) {}
  19. static Foo_ptr getPtr() {
  20. return Foo_ptr(new Foo(17), true);
  21. }
  22. static const Foo_ptr getConstPtr() {
  23. return Foo_ptr(new Foo(17), true);
  24. }
  25. const Foo *operator->() {
  26. return _ptr;
  27. }
  28. Foo_ptr(const Foo_ptr& f) : _ptr(f._ptr), _own(f._own)
  29. {
  30. f._own = 0;
  31. }
  32. Foo_ptr& operator=(const Foo_ptr& f) {
  33. _ptr = f._ptr;
  34. _own = f._own;
  35. f._own = 0;
  36. return *this;
  37. }
  38. ~Foo_ptr() {
  39. if(_own) delete _ptr;
  40. }
  41. };
  42. %}