home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April B / Pcwk4b98.iso / Borland / Dbase50w / EXTERN.PAK / DBFILE.H < prev    next >
C/C++ Source or Header  |  1994-08-02  |  3KB  |  89 lines

  1. //============================================================================
  2. //
  3. // Dbfile.h
  4. //
  5. // Part of dbfile, a dBASE for Windows example.
  6. //
  7. // See dbfile.cpp for a description of the example.
  8. //
  9. //============================================================================
  10.  
  11. //
  12. // TextFile header file that describes the TextFile class 
  13. //
  14.  
  15. #ifndef DBFILE_H
  16.  
  17.    // Get the DBaseVar and DVar stuff.
  18. #include "dbasevar.h"
  19.  
  20.    // C++ TextFile Class.
  21. class TextFile {
  22.  
  23. private:
  24.  
  25.    // BUFFERLENGTH indicates how many char's are read in at the same
  26.    // time with a call to read.
  27. #define BUFFERLENGTH 16000
  28.  
  29.    char         Buffer[ BUFFERLENGTH + 1 ]; // Holds a buffer of text.
  30.    char        *BufPtr;              // Points into the Buffer..
  31.    char        *CopyPtr;             // Start of Bufferpart to copy.
  32.    char         ErrorString[50];     // Room for errormessages.
  33.    char         FieldSeparator;      // Field separator char.
  34.    char        *Filter;              // Holds the filter.
  35.    long         FilterLen;           // How long is the filter.
  36.    int          Handle;              // To hold the filehandle.
  37.    char         LineSeparator;       // Line separator char.
  38.    unsigned int MaxTextLen;          // Maximum length of Text.
  39.    int          NumberOfFields;      // # of fields in a rec.
  40.    char         PlusLineSeparator;   // Do we want any number of this one.
  41.    char        *SaveFieldEndPtr;     // Marks the end of a field in Text.
  42.    char        *Text;                // Text send over to dBASE.
  43.    unsigned int TextLen;             // Length of Text.
  44.  
  45. public:
  46.       // Default constructor.
  47.    TextFile() {
  48.        Handle = 0;
  49.        Text = new char[2];           // Room for a fieldseparator.
  50.        Text[0] = 0x0;
  51.        Text[1] = 0;
  52.        TextLen = 0;
  53.        MaxTextLen = 1;
  54.        Filter = new char[1];
  55.        Filter[0] = 0x0;
  56.        FilterLen = 0;
  57.        FieldSeparator = ' ';      
  58.        LineSeparator = '\n';         
  59.        PlusLineSeparator = 0;        // Default is one EOL.
  60.    }
  61.  
  62.       // Destructor
  63.    ~TextFile() {
  64.       if( Handle != 0 )
  65.          close( Handle );
  66.       delete [] Text;
  67.       delete [] Filter;
  68.    }
  69.  
  70.       // Routines.
  71.    BOOL  AddToText( char *, char * );
  72.    BOOL  Close();
  73.    BOOL  Eof()                         { return *BufPtr == 0x0 &&
  74.                                                 eof( Handle ); }
  75.    BOOL  Error()                       { return ErrorString[0] != 0x0; }
  76.    char *GetErrorString()              { return ErrorString; }
  77.    char *GetField( int );
  78.    int   GetNumberOfFields()           { return NumberOfFields; }
  79.    BOOL  Open( char *FileToOpen );
  80.    char *ReadNextItem( char );
  81.    BOOL  SetFieldSeparator( char * );
  82.    BOOL  SetFilter( char * );
  83.    BOOL  SetLineSeparator( char * );
  84. };
  85.  
  86. #define DBFILE_H
  87. #endif
  88.  
  89.