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.
 
  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.
 
  23  * -- Revision 1.1.1.1  1999/02/28 02:00:53  beazley
 
  26  * -- Revision 1.1  1996/05/22 17:23:48  beazley
 
  36 /* Create an integer array of given size */
 
  38 static int *array_int(int size) {
 
  39   return (int *) malloc(size*sizeof(int));
 
  42 static int get_int(int *array_int, int index) {
 
  44     return (array_int[index]);
 
  49 static int set_int(int *array_int, int index, int val) {
 
  51     return (array_int[index] = val);
 
  56 /* Create double precision arrays */
 
  58 static double *array_double(int size) {
 
  59   return (double *) malloc(size*sizeof(double));
 
  62 static double get_double(double *array_double, int index) {
 
  64     return (array_double[index]);
 
  69 static double set_double(double *array_double, int index, double val) {
 
  71     return (array_double[index] = val);
 
  76 /* Create byte arrays */
 
  78 typedef unsigned char byte;
 
  80 static byte *array_byte(int size) {
 
  81   return (byte *) malloc(size*sizeof(byte));
 
  84 static byte get_byte(byte *array_byte, int index) {
 
  86     return (array_byte[index]);
 
  91 static byte set_byte(byte *array_byte, int index, byte val) {
 
  93     return (array_byte[index] = val);
 
  98 /* Create character string arrays */
 
 100 static char **array_string(int size) {
 
 104   a = (char **) malloc(size*sizeof(char *));
 
 105   for (i = 0; i < size; i++)
 
 110 static char *get_string(char **array_string, int index) {
 
 112     return (array_string[index]);
 
 117 static char *set_string(char **array_string, int index, char * val) {
 
 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];
 
 125       array_string[index] = 0;
 
 135 %section "Array Operations"
 
 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. */
 
 141 int get_int(int *array_int, int index) ;
 
 142 /* Return the integer in array_int[index] */
 
 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. */
 
 148 /* Create double precision arrays */
 
 150 double *array_double(int size);
 
 151 /* Creates an array of double precision floats. */
 
 153 double get_double(double *array_double, int index);
 
 154 /* Return the double in array_double[index] */
 
 156 double set_double(double *array_double, int index, double dval);
 
 157 /* Sets array_double[index] = dval.  Returns it's value */
 
 159 typedef unsigned char byte;
 
 161 byte *array_byte(int nbytes);
 
 162 /* Creates a byte array.  A byte is defined as an unsigned char. */
 
 164 byte get_byte(byte *array_byte, int index);
 
 165 /* Returns array_byte[index] */
 
 167 byte set_byte(byte *array_byte, int index, byte val);
 
 168 /* Sets array_byte[index] = val.  Returns it's new value */
 
 170 char **array_string(int size);
 
 171 /* Creates a string array.  A string is array is the same as char ** in C */
 
 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 */
 
 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. */