#ifndef _GETOPT_H
#define _GETOPT_H

#include "HashTable.h"
#include "Vector.h"

#define GOO_BOOL_TYPE 1
#define GOO_STRING_TYPE 2

class GetOptOption
{
 public:
  GetOptOption()
    {
      sname=0;
      lname=NULL;
      svalue=NULL;
      bvalue=false;
    }

  char sname;
  char *lname;

  char *svalue;
  bool bvalue;

  char *help;
  int type;

  int spacer;
  GetOptOption *next;
};

class GetOpt
{
 public:

  GetOpt();
  ~GetOpt();

  bool parse(int argc, char *argv[], bool showErrors);

  void addOptionBool(char sname, const char *lname, bool def, char *help);
  void addOptionString(char sname, const char *lname, char *def, char *help);
  void addOptionInt(char sname, const char *lname, int def, char *help);

  bool getOptionBool(const char *lname);
  char *getOptionString(const char *lname);
  int getOptionInt(const char *lname);
  Vector<char*> *getExtraArgs();

  void setOptionBool(const char *lname, bool val);
  void setOptionString(const char *lname, char *val);
  void setOptionInt(const char *lname, int val);
  
  void showOptions();
  void doUsage();

  // add a spacer row to the doUsage display
  void addSpacer(const char *s);

 protected:
  void addToList(GetOptOption *goo);

  GetOptOption *firstgoo, *lastgoo;

 private:
  HashTable<const char*,GetOptOption*> _loptions;
  HashTable<char, GetOptOption*> _soptions;

  Vector<char*> _extraargs;
};

#endif
