annotate lib/swig/swigwin-2.0.11/Lib/cpointer.i @ 2194:d0e321190c86

Merge
author Grumpy7
date Thu, 30 Jan 2014 22:11:28 +0100
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 * cpointer.i
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 * SWIG library file containing macros that can be used to manipulate simple
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 * pointer objects.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 * %pointer_class(type,name)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 * Places a simple proxy around a simple type like 'int', 'float', or whatever.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 * The proxy provides this interface:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 * class type {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15 * public:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 * type();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 * ~type();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 * type value();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 * void assign(type value);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 * };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 * Example:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 * %pointer_class(int, intp);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 * int add(int *x, int *y) { return *x + *y; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 * In python (with proxies)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 * >>> a = intp()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 * >>> a.assign(10)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 * >>> a.value()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 * 10
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 * >>> b = intp()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 * >>> b.assign(20)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 * >>> print add(a,b)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 * 30
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 * As a general rule, this macro should not be used on class/structures that
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 * are already defined in the interface.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 %define %pointer_class(TYPE, NAME)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 %{
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 typedef TYPE NAME;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 } NAME;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 %extend NAME {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 NAME() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 return new TYPE();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 ~NAME() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 if ($self) delete $self;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 NAME() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 return (TYPE *) calloc(1,sizeof(TYPE));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 ~NAME() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65 if ($self) free($self);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 %extend NAME {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 void assign(TYPE value) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73 *$self = value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 TYPE value() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 return *$self;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 TYPE * cast() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 return $self;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 static NAME * frompointer(TYPE *t) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 return (NAME *) t;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 %types(NAME = TYPE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 %enddef
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 * %pointer_functions(type,name)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94 * Create functions for allocating/deallocating pointers. This can be used
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95 * if you don't want to create a proxy class or if the pointer is complex.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97 * %pointer_functions(int, intp)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99 * int add(int *x, int *y) { return *x + *y; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101 * In python (with proxies)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103 * >>> a = copy_intp(10)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104 * >>> intp_value(a)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105 * 10
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106 * >>> b = new_intp()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 * >>> intp_assign(b,20)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108 * >>> print add(a,b)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 * 30
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110 * >>> delete_intp(a)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111 * >>> delete_intp(b)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115 %define %pointer_functions(TYPE,NAME)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116 %{
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
117 static TYPE *new_##NAME() { %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
118 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
119 %{ return new TYPE(); %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
120 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
121 %{ return (TYPE *) calloc(1,sizeof(TYPE)); %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
122 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
123 %{}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
124
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
125 static TYPE *copy_##NAME(TYPE value) { %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
126 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
127 %{ return new TYPE(value); %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
128 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
129 %{ TYPE *obj = (TYPE *) calloc(1,sizeof(TYPE));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
130 *obj = value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
131 return obj; %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
132 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
133 %{}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
134
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
135 static void delete_##NAME(TYPE *obj) { %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
136 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
137 %{ if (obj) delete obj; %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
138 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
139 %{ if (obj) free(obj); %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
140 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
141 %{}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
142
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
143 static void NAME ##_assign(TYPE *obj, TYPE value) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
144 *obj = value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
145 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
146
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
147 static TYPE NAME ##_value(TYPE *obj) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
148 return *obj;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
149 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
150 %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
151
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
152 TYPE *new_##NAME();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
153 TYPE *copy_##NAME(TYPE value);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
154 void delete_##NAME(TYPE *obj);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
155 void NAME##_assign(TYPE *obj, TYPE value);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
156 TYPE NAME##_value(TYPE *obj);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
157
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
158 %enddef
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
159
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
160 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
161 * %pointer_cast(type1,type2,name)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
162 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
163 * Generates a pointer casting function.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
164 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
165
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
166 %define %pointer_cast(TYPE1,TYPE2,NAME)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
167 %inline %{
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
168 TYPE2 NAME(TYPE1 x) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
169 return (TYPE2) x;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
170 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
171 %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
172 %enddef
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
173
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
174
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
175
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
176
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
177
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
178
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
179
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
180