1996-07-09 08:22:35 +02:00
|
|
|
/* ********************************************************************
|
|
|
|
*
|
|
|
|
* Varray.h -- header file for varray.c which provides a generic
|
1997-09-07 07:04:48 +02:00
|
|
|
* set of functions to handle variable sized arrays.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* originally by Jiang Wu
|
1996-07-09 08:22:35 +02:00
|
|
|
* ********************************************************************/
|
|
|
|
|
|
|
|
#ifndef _VARRAY_H_
|
|
|
|
#define _VARRAY_H_
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct _varray
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
size_t nobj; /* number of objects in this array */
|
|
|
|
size_t maxObj; /* max. number of objects in this array */
|
|
|
|
size_t size; /* size of each element in the array */
|
|
|
|
void *val; /* array of elements */
|
|
|
|
} Varray;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* type for custom copying function */
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef void (*CopyingFunct) (void *from, void *to);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
#define VARRAY_INITIAL_SIZE 32
|
|
|
|
|
|
|
|
#define ENLARGE_VARRAY(ARRAY, INC) \
|
|
|
|
(ARRAY)->maxObj += (INC); \
|
|
|
|
(ARRAY)->val = (void *) realloc((ARRAY)->val, \
|
1997-09-07 07:04:48 +02:00
|
|
|
(ARRAY)->size * (ARRAY)->maxObj)
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
#define VARRAY_NTH(VAL, SIZE, N) (((char *) (VAL)) + (SIZE) * (N))
|
|
|
|
|
|
|
|
#define FreeVarray(ARRAY) \
|
|
|
|
if ((ARRAY) != NULL) { free((ARRAY)->val); free((ARRAY)); (ARRAY) = NULL ; }
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#define ModifyVarray(ARRAY, N, NEW, COPY) \
|
|
|
|
if ((N) < (ARRAY)->nobj) \
|
1997-09-07 07:04:48 +02:00
|
|
|
(COPY)(VARRAY_NTH((ARRAY)->val, (ARRAY)->size, (N)), (NEW))
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
#define GetVarray(ARRAY, N) \
|
|
|
|
((N) < (ARRAY)->nobj ? VARRAY_NTH((ARRAY)->val, (ARRAY)->size, (N)) \
|
1997-09-07 07:04:48 +02:00
|
|
|
: NULL)
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern Varray *NewVarray(size_t nobj, size_t size);
|
|
|
|
extern int AppendVarray(Varray * array, void *value, CopyingFunct copy);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* _VARRAY_H_ */
|