#include "flags.h"
FLAGSTORE flag_CreateStore(MEMORY Memory)
{
  FLAGSTORE store;
  store = (FLAGSTORE)memory_Malloc(Memory, sizeof(FLAGSTORE_NODE));
  store->store = array_Create(Memory, 10);
  return store;
}
void flag_DeleteStore(MEMORY Memory, FLAGSTORE Store)
{
  FLAG flag;
  ARRAY flags;
  int i;
  flags = Store->store;
  for (i=0;i<array_GetSize(flags);i++) {
    flag = (FLAG)array_GetElement(flags,i);
    string_StringFree(Memory,flag->flagsname);
    string_StringFree(Memory,flag->flaglname);
    string_StringFree(Memory,flag->flagexpl);
    memory_Free(Memory, flag, sizeof(FLAG_NODE));
  }
  array_Delete(Memory, flags);
  memory_Free(Memory, Store, sizeof(FLAGSTORE_NODE));
  return;
}
void flag_PrintStore(FLAGSTORE Store)
{
  FLAG flag;
  ARRAY flags;
  int i;
  flags = Store->store;
  for (i=0;i<array_GetSize(flags);i++) {
    flag = (FLAG)array_GetElement(flags,i);
    printf("\n %s %s : %d", flag->flagsname, flag->flaglname, flag->value);
  }
  return;
}
void flag_PrintStoreUsage(FLAGSTORE Store)
{
  FLAG flag;
  ARRAY flags;
  int i;
  flags = Store->store;
  for (i=0;i<array_GetSize(flags);i++) {
    flag = (FLAG)array_GetElement(flags,i);
    printf("\n-%s or --%s\n", flag->flagsname, flag->flaglname);
    printf("%s\n", flag->flagexpl);
  }
  return;
}
void flag_PrintPartialStoreUsage(FLAGSTORE Store, unsigned Start, unsigned End)
{
  FLAG flag;
  ARRAY flags;
  unsigned i;
  flags = Store->store;
  for (i=Start;i<array_GetSize(flags) && i<=End;i++) {
    flag = (FLAG)array_GetElement(flags,i);
    printf("\n-%s or --%s\n", flag->flagsname, flag->flaglname);
    printf("%s\n", flag->flagexpl);
  }
  return;
}
FLAGID flag_CreateFlag(MEMORY Memory, FLAGSTORE Store, const char * FlagSName, const char * FlagLName, const char * Explanation, int Deflt, int Min, int Max)
{
  FLAGID id;
  FLAG newflag;
  newflag = (FLAG)memory_Malloc(Memory, sizeof(FLAG_NODE));
  newflag->flagsname = string_StringCopy(Memory, FlagSName);
  newflag->flaglname = string_StringCopy(Memory, FlagLName);
  newflag->flagexpl = string_StringCopy(Memory, Explanation);
  newflag->deflt = Deflt;
  newflag->value = Deflt;
  newflag->min = Min;
  newflag->max = Max;
  id = array_GetSize(Store->store);
  Store->store = array_Add(Memory, Store->store, (intptr_t)newflag);
  return id;
}
char* flag_StoreGetFlagSName(FLAGSTORE Store, FLAGID Id)
{
  return ((FLAG) (Store->store[Id]))->flagsname;
}
char* flag_StoreGetFlagLName(FLAGSTORE Store, FLAGID Id)
{
  return ((FLAG) (Store->store[Id]))->flaglname;
}
int flag_StoreGetFlagValue(FLAGSTORE Store, FLAGID Id)
{
  return ((FLAG) (Store->store[Id]))->value;
}
void flag_StoreSetFlagValue(FLAGSTORE Store, FLAGID Id, int Value)
{
  ((FLAG) (Store->store[Id]))->value = Value;
}
int flag_StoreGetFlagMin(FLAGSTORE Store, FLAGID Id)
{
  return ((FLAG) (Store->store[Id]))->min;
}
int flag_StoreGetFlagMax(FLAGSTORE Store, FLAGID Id)
{
  return ((FLAG) (Store->store[Id]))->max;
}
int flag_StoreGetNumberOfFlags(FLAGSTORE Store)
{
  return array_GetSize(Store->store);
}
