annotate lib/swig/swigwin-2.0.11/Lib/carrays.i @ 1899:b3009adc0e2f

Adding swig, gitignore, hgignore
author Nomad
date Mon, 21 Oct 2013 10:42:27 +0200
parents
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 * carrays.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 * pointers as arrays.
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 * %array_functions(TYPE,NAME)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 * Generates functions for creating and accessing elements of a C array
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 * (as pointers). Creates the following functions:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 * TYPE *new_NAME(int nelements)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15 * void delete_NAME(TYPE *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 * TYPE NAME_getitem(TYPE *, int index);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 * void NAME_setitem(TYPE *, int index, TYPE value);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 %define %array_functions(TYPE,NAME)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 %{
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23 static TYPE *new_##NAME(int nelements) { %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 %{ return new TYPE[nelements]; %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 %{ return (TYPE *) calloc(nelements,sizeof(TYPE)); %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 %{}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 static void delete_##NAME(TYPE *ary) { %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 %{ delete [] ary; %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 %{ free(ary); %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 %{}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 static TYPE NAME##_getitem(TYPE *ary, int index) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 return ary[index];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 static void NAME##_setitem(TYPE *ary, int index, TYPE value) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 ary[index] = value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 TYPE *new_##NAME(int nelements);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 void delete_##NAME(TYPE *ary);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 TYPE NAME##_getitem(TYPE *ary, int index);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 void NAME##_setitem(TYPE *ary, int index, TYPE value);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 %enddef
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 * %array_class(TYPE,NAME)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 * Generates a class wrapper around a C array. The class has the following
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 * interface:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 * struct NAME {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 * NAME(int nelements);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 * ~NAME();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 * TYPE getitem(int index);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65 * void setitem(int index, TYPE value);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 * TYPE * cast();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 * static NAME *frompointer(TYPE *t);
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 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 %define %array_class(TYPE,NAME)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73 %{
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 typedef TYPE NAME;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 %}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 /* Put language specific enhancements here */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 } NAME;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 %extend NAME {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 NAME(int nelements) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84 return new TYPE[nelements];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86 ~NAME() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 delete [] self;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 NAME(int nelements) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 return (TYPE *) calloc(nelements,sizeof(TYPE));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 ~NAME() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94 free(self);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98 TYPE getitem(int index) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99 return self[index];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101 void setitem(int index, TYPE value) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 self[index] = value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104 TYPE * cast() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105 return self;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 static NAME *frompointer(TYPE *t) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108 return (NAME *) t;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 %types(NAME = TYPE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115 %enddef
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116