/* ---------------------------------------------------- */
/* Header-file DBSYS 1.0, (C) Wabnig Harald, 15.12.2002 */
/* ---------------------------------------------------- */

#ifndef DBARRAY_INCLUDE
#define DBARRAY_INCLUDE

#include <string.h>

/* -------------------------------------------------------------------------- */
/* ARRAY-Datastructure:                                                       */
/*                                                                            */
/* These functions allow the definition of arrays without a limit in the      */
/* number of array elements.                                                  */
/* -------------------------------------------------------------------------- */

/* ARRAY element pointers are increased by the count defined in ARRAY_MORE */
#define ARRAY_MORE	250

typedef int (*PFNCMP) (const void *, const void *);

typedef struct {
  int iSize;
  int iCount;
  int _iTablenr;
  PFNCMP pfnCmp;
  void **Data;
} ARRAY;

/* Remark: 
     iSize is always -2 for ARRAYs; this is needed for the COMPR-functions to
     distinct ARRAYs from Structs, Tables and Composeds which have always 
     iSize > 0 */

extern ARRAY * ARRAY_New(void);
extern ARRAY * ARRAY_Init(ARRAY *arr);
extern ARRAY * ARRAY_Assign(ARRAY * arr1, ARRAY * arr2);
extern void ARRAY_Free(ARRAY *arr);
extern void * ARRAY_Get(const ARRAY *arr, void * info, int idx);
extern void * ARRAY_GetPtr(const ARRAY *arr, int idx);
extern void ARRAY_Remove(ARRAY *arr, int idx);
extern void ARRAY_Add(ARRAY *arr, void * info);
extern void * ARRAY_AddNew(ARRAY *arr, size_t size);
extern void ARRAY_Sort(ARRAY *arr);

extern void ARRAY_AddArray(ARRAY *arr1, ARRAY *arr2);

extern ARRAY * ARRAY_CompAssign(ARRAY * arr1, ARRAY * arr2, void * assignfunc);
extern void ARRAY_CompFree(ARRAY *arr, void * freefunc);
extern void ARRAY_CompRemove(ARRAY *arr, int idx, void * freefunc);
extern void ARRAY_CompAdd(ARRAY *arr, void * info, void * assignfunc);

#endif
