/* -----------------------------------------------------------------------------
* Author(s): David Beazley (beazley@cs.uchicago.edu)
* This library file contains macros that can be used to manipulate simple
* $Header: /cvsroot/swig/SWIG/Lib/carrays.i,v 1.5 2004/10/06 16:51:19 marcelomatus Exp $
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* %array_functions(TYPE,NAME)
* Generates functions for creating and accessing elements of a C array
* (as pointers). Creates the following functions:
* TYPE *new_NAME(int nelements)
* void delete_NAME(TYPE *);
* TYPE NAME_getitem(TYPE *, int index);
* void NAME_setitem(TYPE *, int index, TYPE value);
* ----------------------------------------------------------------------------- */
%define %array_functions(TYPE,NAME)
static TYPE *new_##NAME(int nelements) { %}
%{ return new TYPE[nelements]; %}
%{ return (TYPE *) calloc(nelements,sizeof(TYPE)); %}
static void delete_##NAME(TYPE *ary) { %}
static TYPE NAME##_getitem(TYPE *ary, int index) {
static void NAME##_setitem(TYPE *ary, int index, TYPE value) {
TYPE *new_##NAME(int nelements);
void delete_##NAME(TYPE *ary);
TYPE NAME##_getitem(TYPE *ary, int index);
void NAME##_setitem(TYPE *ary, int index, TYPE value);
/* -----------------------------------------------------------------------------
* %array_class(TYPE,NAME)
* Generates a class wrapper around a C array. The class has the following
* TYPE getitem(int index);
* void setitem(int index, TYPE value);
* static NAME *frompointer(TYPE *t);
* ----------------------------------------------------------------------------- */
%define %array_class(TYPE,NAME)
/* Put language specific enhancements here */
#if defined(SWIGPYTHON) || defined(SWIGRUBY)
%rename(__getitem__) getitem;
%rename(__setitem__) setitem;
return new TYPE[nelements];
return (TYPE *) calloc(nelements,sizeof(TYPE));
TYPE getitem(int index) {
void setitem(int index, TYPE value) {
static NAME *frompointer(TYPE *t) {