~ubuntu-branches/ubuntu/hardy/swig1.3/hardy

« back to all changes in this revision

Viewing changes to Examples/test-suite/ruby/track_objects.i

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%module track_objects
 
2
 
 
3
%include typemaps.i
 
4
 
 
5
%trackobjects Foo;
 
6
 
 
7
%newobject Bar::get_new_foo;
 
8
 
 
9
%typemap(in, numinputs=0) Foo** foo (Foo *temp) {
 
10
        /* %typemap(in, numinputs=0) Foo** foo */
 
11
        $1 = &temp;
 
12
}
 
13
 
 
14
%typemap(argout) Foo** foo {
 
15
        /* %typemap(argout) Foo** foo */
 
16
        $result = SWIG_NewPointerObj((void *) *$1, $*1_descriptor, 0);
 
17
}       
 
18
 
 
19
%apply SWIGTYPE *DISOWN {Foo* ownedFoo};
 
20
 
 
21
%inline %{
 
22
 
 
23
class Foo
 
24
{
 
25
public:
 
26
        Foo() {}
 
27
        ~Foo() {}
 
28
 
 
29
        /* Helper method that can be called from Ruby that checks
 
30
           that two Ruby objects are pointing to the same underlying
 
31
                C++ object */
 
32
        bool cpp_equal(const Foo* other)
 
33
        {
 
34
                return (this == other);
 
35
        }
 
36
 
 
37
        /* Just a simple method to call on Foo*/
 
38
        char* say_hello()
 
39
        {
 
40
                return "Hello";
 
41
        }
 
42
};
 
43
 
 
44
 
 
45
class Bar
 
46
{
 
47
private:
 
48
        Foo* owned_;
 
49
        Foo* unowned_;
 
50
public:
 
51
        Bar(): owned_(new Foo), unowned_(0)
 
52
        {
 
53
        }
 
54
 
 
55
        ~Bar()
 
56
        {
 
57
                delete owned_;
 
58
        }
 
59
 
 
60
        /* Test that track objects works with %newobject */
 
61
        static Foo* get_new_foo()
 
62
        {
 
63
                return new Foo;
 
64
        }
 
65
 
 
66
        /* Test the same foo Ruby object is created each time */
 
67
        Foo* get_owned_foo()
 
68
        {
 
69
                return owned_;
 
70
        }
 
71
 
 
72
        /* Test that track objects works with argout parameters.*/
 
73
        void get_owned_foo_by_argument(Foo** foo)
 
74
        {
 
75
                *foo = owned_;
 
76
        }
 
77
 
 
78
        /* Test that track objects works with the DISOWN typemap.*/
 
79
        void set_owned_foo(Foo* ownedFoo)
 
80
        {
 
81
                delete owned_;
 
82
                owned_ = ownedFoo;
 
83
        }
 
84
 
 
85
        Foo* get_unowned_foo()
 
86
        {
 
87
                return unowned_;
 
88
        }
 
89
 
 
90
        void set_unowned_foo(Foo* foo)
 
91
        {
 
92
                unowned_ = foo;
 
93
        }
 
94
};
 
95
%}