//----------------------------------------------------------------------------//
//--  Implements a C++ API for VEX objects as described in its accompanying --//
//--  documentation.  Maintained by eric.fahlgren@mscsoftware.com.          --//
//--                                                                        --//
//--  Copyright (c) 2002 by Eric Fahlgren.  All rights reserved.            --//
//--                                                                        --//
//--  This program is free software; you can redistribute it and/or         --//
//--  modify it under the terms of the GNU General Public License           --//
//--  as published by the Free Software Foundation; either version          --//
//--  2 of the License, or (at your option) any later version.              --//
//--  See http://www.gnu.org/licenses/gpl.txt                               --//
//----------------------------------------------------------------------------//

#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;

   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);
};

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

