~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): Benjamin Drung
  • Date: 2009-11-15 14:00:28 UTC
  • mfrom: (1.2.9 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091115140028-me7amr2rie8zz1xn
Tags: 1.3.40-2ubuntu1
* Merge from Debian testing (LP: #356529), remaining changes:
  - Drop libchicken-dev from the build-depends (it's in universe)
  - Remove Pike from package description and from configure flags
  - drop "--without-mzscheme", we don't have it in our build-depends
  - use php-config5
  - Clean Runtime/ as well.
  - debian/rules (clean): Remove Lib/ocaml/swigp4.ml.
* debian/rules: Remove hardcoded python version.
* Remove upper limit for python from Build-Depends.

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
 
        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
 
%}