/******************************************************************************
*
*               Module   : StrDict
*               Fichier  : StrDict.h
*               Auteur   : J. DUCLOY
*               Date     : Aout 93
*               modifications
*                        : 20 Octobre 93
*                            StrDictFree
*                            StrDictDo
*                        : 16 Octobre 95 (L. Mirtain)
*                            ajout declarations type void
*
******************************************************************************/


#ifndef _DILIB_STR_DICT_H
#define _DILIB_STR_DICT_H

/* les types de base */

union StrDictValueTypesUnion
{
   char   *str;
   double d;
   int    i;
};

typedef union StrDictValueTypesUnion StrDictValueUnionTypes;

struct StrDictDatumStruct
{
   char *key;
   StrDictValueUnionTypes value;
};

typedef struct StrDictDatumStruct StrDictDatum;
 
struct StrDictStruct
   {
      StrDictDatum *table;
      int             status;        
                       /* 0 vide , 
                          1 en constitution triee,
                          2 en constitution non triee,
                          3 en utilisation (recherche)
                       */
     int             valueType;
                      /*            not yet implemented
                           p :  pointer (char *)
                           c : char
                           i : int
                           d : double
                      */
     int             size;
     int             incr;
                       /*
                        if incr == 0 it will be equivalent to 20% of size
                       */
     char           *greatest;
     int             numberOfElements;
     int             currentPos;
  };
 
typedef struct StrDictStruct StrDict;

#define StrDictKey(curT)           (curT->table[curT->currentPos].key)
#define StrDictValue(curT)         (curT->table[curT->currentPos].value.str)
#define StrDictValueDouble(curT)   (curT->table[curT->currentPos].value.d)
#define StrDictValueInt(curT)      (curT->table[curT->currentPos].value.i)

extern char *StrDictLastKey;

/* kernel functions from StrDict.c */

StrDict*     StrDictCreate(int number, int incr);
StrDict*     NewStrDict();
StrDict*     StrDictSetValueType(StrDict *table, char valueType);
void         StrDictFree(StrDict *t);
void         StrDictFreeKey(StrDict *t);
void         StrDictFreeStr(StrDict *t);
char *StrDictFist(StrDict *curTable);

int          StrDictCheckSort(StrDict *t);

StrDict*     StrDictReset(StrDict* curTable);

StrDictValueUnionTypes * StrDictCheck(StrDict *t, char *s1);

StrDictValueUnionTypes *StrDictAddNewDatumWithUnion(StrDict *t, char *s1, StrDictValueUnionTypes *u2);

char*        StrDictAddNewDatum(StrDict *t, char *s1, char *s2);
double       StrDictAddNewDatumWithDouble(StrDict *t, char *s1, double d2);
int          StrDictAddNewDatumWithInt(StrDict *t, char *s1, int i1);

StrDictValueUnionTypes *StrDictSetUnion(StrDict *t, char *s1,  StrDictValueUnionTypes *u2);
char*        StrDictSet(StrDict *t, char *s1, char *s2);
double       StrDictSetDouble(StrDict *t, char *k1, double d1);
int          StrDictSetInt(StrDict *t, char *k1, int i1);

StrDictValueUnionTypes *StrDictSearchUnion(StrDict *t, char *s1);
char*        StrDictSearch(StrDict *t, char *s1);
double       StrDictSearchDouble(StrDict *t, char *k1);
int          StrDictSearchInt(StrDict *t, char *k1);

char*        StrDictNext(StrDict *curTable);
char*        StrDictPrevious(StrDict *curTable);

char *StrDictKeyLessEqual(StrDict *curTable, char *s1);

void StrDictIteratorReset(StrDict* curTable);

char *StrDictAddNewDatumChar(StrDict *t, char *k1, unsigned char vc1);
char *StrDictSetChar(StrDict *t, char *k1, char c1);
char StrDictGetChar(StrDict *t, char *k1);




/* file functions from StrDictFile.c */

StrDict *StrDictAddFromFile (StrDict *table, char*stream);
StrDict *StrDictFromFile(char *stream);

StrDict *StrDictFromVarPath (char *var, char *path);

#endif /* _DILIB_STR_DICT_H */
