home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
INCLUDE
/
VADECL.H
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-01
|
4KB
|
95 lines
/*
vadecl.h 1/10/88
% 'virtual smart' array functions
written by Joe DeSantis.
fleshed out by Ted Peck.
OWL 1.2
Copyright (c) 1986, 1987, 1988, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
4/05/88 Ted added VOID *'s, prototype arg names, clearelem
4/18/88 Ted Added free element/next element handling
3/28/90 jmd ansi-fied
6/01/90 jmd changed index to indeks to avoid DG conflict
*/
/* -------------------------------------------------------------------------- */
/* Data Types */
#define NOID ((unsigned)(-1))
/* -------------------------------------------------------------------------- */
typedef unsigned va_index;
typedef va_index va_key;
typedef int va_tag;
/* The varray structure. */
typedef struct varray_struct {
byte *array; /* the array */
unsigned nelem; /* number of elements in array */
unsigned elemsize; /* size of an element in array */
VOID *clearelem; /* pointer to element full of init vals */
va_index hint;
} *varray;
/* The va_element structure, tacked on to each varray element */
typedef struct _vae {
boolean inuse;
va_tag tag;
} vae_struct;
/* -------------------------------------------------------------------------- */
/* Macros. */
#define oarrayelem(array, indeks, esize) ((byte *)(array)+(indeks)*(esize))
/* -------------------------------------------------------------------------- */
#define va_array(va) ((va)->array)
#define va_nelem(va) ((va)->nelem)
#define va_inesize(va) ((va)->elemsize)
#define va_elemsize(va) ((va)->elemsize - sizeof(vae_struct))
#define va_clearelem(va) ((va)->clearelem)
#define va_hint(va) ((va)->hint)
#define va_isvalid(va, indeks) ((unsigned)(indeks) < (va)->nelem)
#define va_elem(va, indeks) oarrayelem((va)->array, indeks, va_inesize(va))
#define va_elemvae(va, elem) ((vae_struct *)((byte *)elem + va_elemsize(va)))
#define va_vaeptr(va, indeks) ((vae_struct *)((byte *)va_elem(va, (indeks)+1) - sizeof(vae_struct)))
#define va_elemindeks(va,elem) (((elem) != NULL) ? ((va_indeks)(((byte *)elem) - (va)->array)/va_inesize(va)) : NOID)
#define va_geteleminuse(va, elem) (va_elemvae(va, elem)->inuse)
#define va_seteleminuse(va, elem, iu) (va_elemvae(va, elem)->inuse = iu)
#define va_getelemtag(va, elem) (va_elemvae(va, elem)->tag)
#define va_setelemtag(va, elem, tg) (va_elemvae(va, elem)->tag = tg)
#define va_get(va, indeks) (va_isvalid (va, indeks) ? va_elem(va, indeks) : NULL)
#define va_isfree(va, indeks) (!va_vaeptr(va, indeks)->inuse)
#define va_setfree(va, indeks, isfree) (va_vaeptr(va, indeks)->inuse = !isfree)
#define va_gettag(va, indeks) (va_vaeptr(va, indeks)->tag)
#define va_settag(va, indeks, intag) (va_vaeptr(va, indeks)->tag = intag)
#define va_getfirst(va, tag, ip) va_getnext(va, tag, ip, NOID)
/* -------------------------------------------------------------------------- */
/* Function prototypes. */
/* -------------------------------------------------------------------------- */
/* VARRAY.C */
extern varray va_make(unsigned nelem, unsigned elemsize, VOID *clearelem, boolean inuse, va_tag tag);
extern void va_free(varray va);
extern VOID *va_put(varray va, va_index indeks, VOID *elem);
extern unsigned va_clear(varray va, va_index indeks, unsigned nelem);
extern void va_freeelem(varray va, va_index indeks);
extern va_index va_findfree(varray va);
extern va_index va_getnext(varray va, va_tag tagspec, va_index *indexp, va_key key);
extern unsigned va_expand(varray va, va_index indeks);
/* -------------------------------------------------------------------------- */