]>
Commit | Line | Data |
---|---|---|
c90f71dd RD |
1 | // |
2 | // $Header$ | |
3 | // carray.i | |
4 | // Dave Beazley | |
5 | // March 24, 1996 | |
6 | // | |
7 | // This SWIG library file supports C arrays of various datatypes. | |
8 | // These arrays are probably *not* compatible with scripting languages | |
9 | // but they are compatible with C functions. | |
10 | // | |
11 | /* Revision History | |
12 | * -- $Log$ | |
13 | * -- Revision 1.1 2002/04/29 19:56:49 RD | |
14 | * -- Since I have made several changes to SWIG over the years to accomodate | |
15 | * -- special cases and other things in wxPython, and since I plan on making | |
16 | * -- several more, I've decided to put the SWIG sources in wxPython's CVS | |
17 | * -- instead of relying on maintaining patches. This effectivly becomes a | |
18 | * -- fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still | |
19 | * -- doesn't have some things I rely on in 1.1, not to mention that my | |
20 | * -- custom patches would all have to be redone, I felt that this is the | |
21 | * -- easier road to take. | |
22 | * -- | |
23 | * -- Revision 1.1.1.1 1999/02/28 02:00:53 beazley | |
24 | * -- Swig1.1 | |
25 | * -- | |
26 | * -- Revision 1.1 1996/05/22 17:23:48 beazley | |
27 | * -- Initial revision | |
28 | * -- | |
29 | */ | |
30 | ||
31 | %module carray | |
32 | %{ | |
33 | ||
34 | #include <string.h> | |
35 | ||
36 | /* Create an integer array of given size */ | |
37 | ||
38 | static int *array_int(int size) { | |
39 | return (int *) malloc(size*sizeof(int)); | |
40 | } | |
41 | ||
42 | static int get_int(int *array_int, int index) { | |
43 | if (array_int) | |
44 | return (array_int[index]); | |
45 | else | |
46 | return 0; | |
47 | } | |
48 | ||
49 | static int set_int(int *array_int, int index, int val) { | |
50 | if (array_int) | |
51 | return (array_int[index] = val); | |
52 | else | |
53 | return 0; | |
54 | } | |
55 | ||
56 | /* Create double precision arrays */ | |
57 | ||
58 | static double *array_double(int size) { | |
59 | return (double *) malloc(size*sizeof(double)); | |
60 | } | |
61 | ||
62 | static double get_double(double *array_double, int index) { | |
63 | if (array_double) | |
64 | return (array_double[index]); | |
65 | else | |
66 | return 0; | |
67 | } | |
68 | ||
69 | static double set_double(double *array_double, int index, double val) { | |
70 | if (array_double) | |
71 | return (array_double[index] = val); | |
72 | else | |
73 | return 0; | |
74 | } | |
75 | ||
76 | /* Create byte arrays */ | |
77 | ||
78 | typedef unsigned char byte; | |
79 | ||
80 | static byte *array_byte(int size) { | |
81 | return (byte *) malloc(size*sizeof(byte)); | |
82 | } | |
83 | ||
84 | static byte get_byte(byte *array_byte, int index) { | |
85 | if (array_byte) | |
86 | return (array_byte[index]); | |
87 | else | |
88 | return 0; | |
89 | } | |
90 | ||
91 | static byte set_byte(byte *array_byte, int index, byte val) { | |
92 | if (array_byte) | |
93 | return (array_byte[index] = val); | |
94 | else | |
95 | return 0; | |
96 | } | |
97 | ||
98 | /* Create character string arrays */ | |
99 | ||
100 | static char **array_string(int size) { | |
101 | char **a; | |
102 | int i; | |
103 | ||
104 | a = (char **) malloc(size*sizeof(char *)); | |
105 | for (i = 0; i < size; i++) | |
106 | a[i] = 0; | |
107 | return a; | |
108 | } | |
109 | ||
110 | static char *get_string(char **array_string, int index) { | |
111 | if (array_string) | |
112 | return (array_string[index]); | |
113 | else | |
114 | return ""; | |
115 | } | |
116 | ||
117 | static char *set_string(char **array_string, int index, char * val) { | |
118 | if (array_string) { | |
119 | if (array_string[index]) free(array_string[index]); | |
120 | if (strlen(val) > 0) { | |
121 | array_string[index] = (char *) malloc(strlen(val)+1); | |
122 | strcpy(array_string[index],val); | |
123 | return array_string[index]; | |
124 | } else { | |
125 | array_string[index] = 0; | |
126 | return val; | |
127 | } | |
128 | } | |
129 | else | |
130 | return val; | |
131 | } | |
132 | ||
133 | %} | |
134 | ||
135 | %section "Array Operations" | |
136 | ||
137 | int *array_int(int size); | |
138 | /* Creates an integer array of size elements. Integers are the same | |
139 | size as the C int type. */ | |
140 | ||
141 | int get_int(int *array_int, int index) ; | |
142 | /* Return the integer in array_int[index] */ | |
143 | ||
144 | int set_int(int *array_int, int index, int ival); | |
145 | /* Sets array_int[index] = ival. Returns it's value so you | |
146 | can use this function in an expression. */ | |
147 | ||
148 | /* Create double precision arrays */ | |
149 | ||
150 | double *array_double(int size); | |
151 | /* Creates an array of double precision floats. */ | |
152 | ||
153 | double get_double(double *array_double, int index); | |
154 | /* Return the double in array_double[index] */ | |
155 | ||
156 | double set_double(double *array_double, int index, double dval); | |
157 | /* Sets array_double[index] = dval. Returns it's value */ | |
158 | ||
159 | typedef unsigned char byte; | |
160 | ||
161 | byte *array_byte(int nbytes); | |
162 | /* Creates a byte array. A byte is defined as an unsigned char. */ | |
163 | ||
164 | byte get_byte(byte *array_byte, int index); | |
165 | /* Returns array_byte[index] */ | |
166 | ||
167 | byte set_byte(byte *array_byte, int index, byte val); | |
168 | /* Sets array_byte[index] = val. Returns it's new value */ | |
169 | ||
170 | char **array_string(int size); | |
171 | /* Creates a string array. A string is array is the same as char ** in C */ | |
172 | ||
173 | char *get_string(char **array_string, int index); | |
174 | /* Returns character string in array_string[index]. If that entry is | |
175 | NULL, returns an empty string */ | |
176 | ||
177 | char *set_string(char **array_string, int index, char * string); | |
178 | /* Sets array_string[index] = string. string must be a 0-terminated | |
179 | ASCII string. If string is "" then this will create a NULL pointer. */ | |
180 | ||
181 | ||
182 |