//  Listing 2 - Header file for binaryfile class 
//  This contains the class's elements and in-line functions
//

enum FILEMODE  {Readonly, Update, AnyWrite, Append, Recreate};
enum READMODE  {FirstRecord, NextRecord, PreviousRecord, LastRecord};
enum SHAREMODE {NoneShared, ReadShared, WriteShared};

class binaryfile {
private:
    char name[81];	  // name of file  (size is DOS specific)
    enum FILEMODE mode;   // access mode of the file
    enum SHAREMODE share; // whether shared access is allowed
    unsigned length;      // record length
    int      handle;      // file handle  (-1 if not open)
    long     header;      // size of header at start of file
    long     count;       // number of records in the file
    long     recnbr;      // current record number (starting at 1)
    long     locked;      // if >0, currently locked record
    long     countrecords();  // prototype of private function
public:
    char     *record;     // pointer to record area
    // inline functions to read private elements
    long     getcount  ()      {
        return (share == WriteShared ? countrecords() : count);
    };
    long     getheader ()      {return header;};
    unsigned getlength ()      {return length;};
    long     getlocked ()      {return locked;};
    enum FILEMODE getmode ()   {return mode;};
    char*    getname (char *n) {return (strcpy (n, name));};
    long     getrecnbr ()      {return recnbr;};
    enum SHAREMODE getshare()  {return share;};
    int      isopen ()         {return (handle >= 0);};
};
