PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 2ms 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
 1/* This test a return by value constant SWIGTYPE.
 2It was reported in bug 899332 by Jermey Brown (jhbrown94) */
 3
 4%module return_const_value
 5
 6
 7%ignore Foo_ptr::operator=(const Foo_ptr&);
 8
 9%inline %{
10
11class Foo {
12public:
13    int _val;
14    Foo(int x): _val(x) {}
15    int getVal() const {
16        return _val;
17    }
18};
19
20class Foo_ptr {
21    Foo *_ptr;
22    mutable bool _own;
23  
24public:
25  Foo_ptr(Foo *p, bool own = false): _ptr(p), _own(own) {}
26  static Foo_ptr getPtr() {
27    return Foo_ptr(new Foo(17), true);
28  }
29  static const Foo_ptr getConstPtr() {
30    return Foo_ptr(new Foo(17), true);
31  }
32  const Foo *operator->() {
33    return _ptr;
34  }
35
36  Foo_ptr(const Foo_ptr& f) : _ptr(f._ptr), _own(f._own) 
37  {
38    f._own = 0;
39  }
40
41  Foo_ptr& operator=(const Foo_ptr& f) {
42    _ptr = f._ptr;
43    _own = f._own;
44    f._own = 0;
45    return *this;
46  }
47
48  ~Foo_ptr() {
49    if(_own) delete _ptr;
50  }  
51};
52
53%}