#ifndef FILEOBJECT
#define FILEOBJECT
/***************************************************************
 * CLASS:  File
 * AUTHOR: Johnny Weber
 * SID:    098609881
 * DATE:   Tue May 14 09:17:32 EDT 2001
 * DESCRIPTION:
 *         The File class encapsulates the low-level file
 *         access code.  It provides a file-level record 
 *         abstration, so that higher-level code can simply 
 *         read and write blocks of data a record at a time.
 * SAMPLE USAGE:
 *         int main(void) {
 *             File f("test");
 *             f.write("this is a test");
 *             f.write("yet another test");
 *             while( f.hasMoreData() ) {
 *                string s = f.read(); // Grab each line
 *             }
 *             cout << f;
 *         }
 * EXCEPTIONS:
 *         FileException - If attempt to read beyond EOF
 *         FileException - If file handle is lost
 ***************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>

class File
{
  friend ostream& operator<< ( ostream& os, File& f);
 private:
  FILE*  filePtr;
  string fileName;
  long   fileSize;
  long   current;
 public:
  /****** C o n s t r u c t o r s ******/
  File(string fn);
  ~File();

  /*********** M e t h o d s ***********/
  int getSize();                     // Return size of file
  bool hasMoreData();                // More data in file?

  void initialize();                 // Initialize file

  void first();                      // Move pointer to first record
  void last();                       // Move pointer to last record

  string read();                     // Read current row from file
  string read(int n);                // Read row n from file

  void write(string lines[], int n); // Write n lines to file
  void write(string row);            // Write row to file
};

class FileException
{
 public:
  FileException(string msg) { 
    cout << "FileException: " << msg << endl;
  }
};
#endif
