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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-06 10:27:08 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071206102708-t37t62i45n595w0e
Tags: 1.3.33-2ubuntu1
* Merge with Debian; remaining changes:
  - Drop support for pike.
  - Use python2.5 instead of python2.4.
  - Clean Runtime/ as well.
  - Force a few environment variables.
* debian/Rules (clean): Remove Lib/ocaml/swigp4.ml.

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
 
 
22
 
%trackobjects ItemA;
23
 
%trackobjects ItemB;
24
 
 
25
 
%inline %{
26
 
 
27
 
class Foo
28
 
{
29
 
public:
30
 
        Foo() {}
31
 
        ~Foo() {}
32
 
 
33
 
        /* Helper method that can be called from Ruby that checks
34
 
           that two Ruby objects are pointing to the same underlying
35
 
                C++ object */
36
 
        bool cpp_equal(const Foo* other)
37
 
        {
38
 
                return (this == other);
39
 
        }
40
 
 
41
 
        /* Just a simple method to call on Foo*/
42
 
        char* say_hello()
43
 
        {
44
 
                return "Hello";
45
 
        }
46
 
};
47
 
 
48
 
 
49
 
class Bar
50
 
{
51
 
private:
52
 
        Foo* owned_;
53
 
        Foo* unowned_;
54
 
public:
55
 
        Bar(): owned_(new Foo), unowned_(0)
56
 
        {
57
 
        }
58
 
 
59
 
        ~Bar()
60
 
        {
61
 
                delete owned_;
62
 
        }
63
 
 
64
 
        /* Test that track objects works with %newobject */
65
 
        static Foo* get_new_foo()
66
 
        {
67
 
                return new Foo;
68
 
        }
69
 
 
70
 
        /* Test the same foo Ruby object is created each time */
71
 
        Foo* get_owned_foo()
72
 
        {
73
 
                return owned_;
74
 
        }
75
 
 
76
 
        /* Test that track objects works with argout parameters.*/
77
 
        void get_owned_foo_by_argument(Foo** foo)
78
 
        {
79
 
                *foo = owned_;
80
 
        }
81
 
 
82
 
        /* Test that track objects works with the DISOWN typemap.*/
83
 
        void set_owned_foo(Foo* ownedFoo)
84
 
        {
85
 
                delete owned_;
86
 
                owned_ = ownedFoo;
87
 
        }
88
 
 
89
 
        Foo* get_unowned_foo()
90
 
        {
91
 
                return unowned_;
92
 
        }
93
 
 
94
 
        void set_unowned_foo(Foo* foo)
95
 
        {
96
 
                unowned_ = foo;
97
 
        }
98
 
};
99
 
 
100
 
class ItemA
101
 
{
102
 
};
103
 
 
104
 
class ItemB: public ItemA
105
 
{
106
 
public:
107
 
};
108
 
 
109
 
ItemB* downcast(ItemA* item)
110
 
{
111
 
        return static_cast<ItemB*>(item);
112
 
}
113
 
 
114
 
class Factory
115
 
{
116
 
public:
117
 
        Factory() {}
118
 
 
119
 
        ItemA* createItem()
120
 
        {
121
 
                return new ItemB;
122
 
        }
123
 
};
124
 
 
125
 
%}
 
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
 
 
22
%trackobjects ItemA;
 
23
%trackobjects ItemB;
 
24
 
 
25
%inline %{
 
26
 
 
27
class Foo
 
28
{
 
29
public:
 
30
        Foo() {}
 
31
        ~Foo() {}
 
32
 
 
33
        /* Helper method that can be called from Ruby that checks
 
34
           that two Ruby objects are pointing to the same underlying
 
35
                C++ object */
 
36
        bool cpp_equal(const Foo* other)
 
37
        {
 
38
                return (this == other);
 
39
        }
 
40
 
 
41
        /* Just a simple method to call on Foo*/
 
42
        const char* say_hello()
 
43
        {
 
44
                return "Hello";
 
45
        }
 
46
};
 
47
 
 
48
 
 
49
class Bar
 
50
{
 
51
private:
 
52
        Foo* owned_;
 
53
        Foo* unowned_;
 
54
public:
 
55
        Bar(): owned_(new Foo), unowned_(0)
 
56
        {
 
57
        }
 
58
 
 
59
        ~Bar()
 
60
        {
 
61
                delete owned_;
 
62
        }
 
63
 
 
64
        /* Test that track objects works with %newobject */
 
65
        static Foo* get_new_foo()
 
66
        {
 
67
                return new Foo;
 
68
        }
 
69
 
 
70
        /* Test the same foo Ruby object is created each time */
 
71
        Foo* get_owned_foo()
 
72
        {
 
73
                return owned_;
 
74
        }
 
75
 
 
76
        /* Test that track objects works with argout parameters.*/
 
77
        void get_owned_foo_by_argument(Foo** foo)
 
78
        {
 
79
                *foo = owned_;
 
80
        }
 
81
 
 
82
        /* Test that track objects works with the DISOWN typemap.*/
 
83
        void set_owned_foo(Foo* ownedFoo)
 
84
        {
 
85
                delete owned_;
 
86
                owned_ = ownedFoo;
 
87
        }
 
88
 
 
89
        Foo* get_unowned_foo()
 
90
        {
 
91
                return unowned_;
 
92
        }
 
93
 
 
94
        void set_unowned_foo(Foo* foo)
 
95
        {
 
96
                unowned_ = foo;
 
97
        }
 
98
};
 
99
 
 
100
class ItemA
 
101
{
 
102
};
 
103
 
 
104
class ItemB: public ItemA
 
105
{
 
106
public:
 
107
};
 
108
 
 
109
ItemB* downcast(ItemA* item)
 
110
{
 
111
        return static_cast<ItemB*>(item);
 
112
}
 
113
 
 
114
class Factory
 
115
{
 
116
public:
 
117
        Factory() {}
 
118
 
 
119
        ItemA* createItem()
 
120
        {
 
121
                return new ItemB;
 
122
        }
 
123
};
 
124
 
 
125
%}