1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * This library file contains macros that can be used to manipulate simple
10 * ----------------------------------------------------------------------------- */
12 /* -----------------------------------------------------------------------------
13 * %pointer_class(type,name)
15 * Places a simple proxy around a simple type like 'int', 'float', or whatever.
16 * The proxy provides this interface:
23 * void assign(type value);
28 * %pointer_class(int, intp);
30 * int add(int *x, int *y) { return *x + *y; }
32 * In python (with proxies)
43 * As a general rule, this macro should not be used on class/structures that
44 * are already defined in the interface.
45 * ----------------------------------------------------------------------------- */
48 %define %pointer_class(TYPE, NAME)
58 return %new_instance(TYPE);
61 if (self) %delete(self);
67 void assign(TYPE value) {
76 static NAME * frompointer(TYPE *t) {
85 /* -----------------------------------------------------------------------------
86 * %pointer_functions(type,name)
88 * Create functions for allocating/deallocating pointers. This can be used
89 * if you don't want to create a proxy class or if the pointer is complex.
91 * %pointer_functions(int, intp)
93 * int add(int *x, int *y) { return *x + *y; }
95 * In python (with proxies)
97 * >>> a = copy_intp(10)
101 * >>> intp_assign(b,20)
107 * ----------------------------------------------------------------------------- */
109 %define %pointer_functions(TYPE,NAME)
111 static TYPE *new_##NAME() {
112 return %new_instance(TYPE);
115 static TYPE *copy_##NAME(TYPE value) {
116 return %new_copy(value, TYPE);
119 static void delete_##NAME(TYPE *self) {
120 if (self) %delete(self);
123 static void NAME ##_assign(TYPE *self, TYPE value) {
127 static TYPE NAME ##_value(TYPE *self) {
133 TYPE *copy_##NAME(TYPE value);
134 void delete_##NAME(TYPE *self);
135 void NAME##_assign(TYPE *self, TYPE value);
136 TYPE NAME##_value(TYPE *self);
140 /* -----------------------------------------------------------------------------
141 * %pointer_cast(type1,type2,name)
143 * Generates a pointer casting function.
144 * ----------------------------------------------------------------------------- */
146 %define %pointer_cast(TYPE1,TYPE2,NAME)
148 TYPE2 NAME(TYPE1 x) {
149 return %static_cast(x, TYPE2);