/* dynVector.h */

#ifndef DINVECTOR_H
#define DINVECTOR_H


typedef struct _DynVector {
  int slotSize;              // amount of bytes which makes up a slot
  int totalSize;             // amount of bytes of storage area
  int nextSlot;              // index of next empty slot
  unsigned char *storage;    // pointer to dynamically allocated memory
  int slotIncr;              // amount of slots to add dynamically if we
} DynVector;                 //  need more space yet have run out of it



/* React on "out of memory condition". */
extern void onErrorOutOfMemory();


/* React on "NULL pointer condition". */
extern void onNullPointer();


/* Allocate memory for a dynamical vector whose totalSize is 0.
 * params:
 *   int slotSize         amount of bytes which make up a slot
 *   int slotIncr         amount of slots dynamically added if we
 *                         have run out storage
 * returns:
 *   DynVector *          pointer to created vector
 */
DynVector *createDynVector(int slotSize, int slotIncr);


/* Add an element to the vector.
 * params:
 *   DynVector *dv        pointer to vector of interest
 *   void *element        pointer to element of interest
 * returns:
 *   void *               NULL if adding not successful: the old
 *                         situation is preserved; not NULL if
 *                         successful
 */
void *addElDynVector(DynVector *dv, void *element);


/* Get pointer to element at the specified index.
 * params:
 *   DynVector *dv        pointer to vector of interest
 *   int slotIndex        slot index or element index
 * returns:
 *   void *               NULL if out of range or if NULL slot;
 *                         pointer to element otherwise
 */
void *getElPtrDynVector(DynVector *dv, int slotIndex);


/* Get number of elements in vector.
 * params:
 *   DynVector *dv        pointer to vector of interest
 * returns:
 *   int                  number of elements
 */
int getSizeDynVector(DynVector *dv);


/* Free all memory in possession of the vector.
 * params:
 *   DynVector *dv        pointer to vector of interest
 * returns:
 *   void                 --
 */
void deleteDynVector(DynVector *dv);


/* Print the vector
 * params:
 *   DynVector *dv        pointer to vector of interest
 *   void (*fp)()         pointer to function printing
 *                         the element.
 * returns:
 *   void                 --
 */
void printDynVector(DynVector *dv, int slotIndex, void (*fp)());

#endif
