#if !defined(VEX_H)
#define VEX_H 1

// $Id$

#if _MSC_VER > 1000
#  pragma once
#endif // _MSC_VER > 1000

//------------------------------------------------------------------------------

#include <stdio.h> // Primitive but effective.

//------------------------------------------------------------------------------

class veTable {
   int  *loadBins;
   int  *rpmBins;
   int  *veBins;
   int  nLoad;
   int  nRPM;
   char loadtype[10];

   void cleanUp();

public:
   veTable(int nRPM=0, int nLoad=0, int rpmBins[]=NULL, int loadBins[]=NULL, int veBins[]=NULL);
  ~veTable();


   bool setSize(int nRPM, int nLoad, int rpmBins[]=NULL, int loadBins[]=NULL, int veBins[]=NULL);

   void  loadType(char *type);
   char *loadType();

   int   load(int index);
   void  load(int value, int index);
   int   rpm (int index);
   void  rpm (int value, int index);
   int   ve  (int r, int c);
   void  ve  (int value, int r, int c);

   int nLoads() { return nLoad; }
   int nRPMs () { return nRPM;  }
};

//------------------------------------------------------------------------------

class vex {
   char lineBuffer[512];
   FILE *vexFile;

   double UserRev;
   char   UserComment[256];
   char   Date[20];
   char   Time[20];

   bool getLine  ();
   bool readTable(int *table, int rows, int cols);
   bool write    (veTable &p);
   bool closeFile(bool);

   veTable **pages;
   int      nPages;

public:
   vex();
  ~vex();

   veTable *page   (int pageNo);
   veTable *newPage(int pageNo);
   int      pageCount() { return nPages; }

   bool     read (const char *fileName);
   bool     write(const char *fileName);

   double   userRev()             { return UserRev; }
   void     userRev(double ur)    { UserRev = ur;   }
   char    *userComment()         { return UserComment; }
   void     userComment(char *uc) { if (strlen(uc) < sizeof(UserComment)-1) strcpy(UserComment, uc); }
   char    *date()                { return Date; }
   void     date(char *d)         { if (strlen(d) < sizeof(Date)-1) strcpy(Date, d); }
   char    *time()                { return Time; }
   void     time(char *t)         { if (strlen(t) < sizeof(Time)-1) strcpy(Time, t); }
};

//------------------------------------------------------------------------------
#endif // !defined(VEX_H)

