home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / stingray / dbfile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-27  |  2.3 KB  |  88 lines

  1. // This is a part of the Objective Grid C++ Library.
  2. // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to
  6. // the Objective Grid Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding
  9. // the Objective Grid product.
  10. //
  11.  
  12. // dbfile.h : defines the interface for the CDBaseFile class
  13.  
  14. #ifndef _DBFILE_H_
  15. #define _DBFILE_H_
  16.  
  17. // A note on DBCS/Unicode support.
  18. //
  19. // I assume that data in the dbase file are in ANSI/DBCS format.
  20. // If this application is compiled with _UNICODE switch,
  21. // data and field names will be converted from single byte chars
  22. // to wide chars.
  23.  
  24. class CField
  25. {
  26. public:
  27.     enum FieldType {
  28.         charField       = 'C',
  29.         dateField       = 'D',
  30.         numericField    = 'N',
  31.         logicalField    = 'L',
  32.         memoField       = 'M'
  33.     };
  34.  
  35.     char  name[11];   // dbf field names are 10 chars long max.
  36.         // If this application is compiled with _UNICODE switch,
  37.         // the field name will be converted to wide chars
  38.         // when the column header is displayed in the grid.
  39.     char  type;
  40.     short len;
  41.     short width;
  42.     short decimals;
  43.     int   offset;
  44.     short display_width;
  45. };
  46.  
  47. class CDBaseFile
  48. {
  49. public:
  50.     CDBaseFile();
  51.     ~CDBaseFile();
  52.  
  53.     BOOL Open(LPCTSTR szFileName, BOOL readOnly = FALSE);
  54.     void Close();
  55.  
  56.     CString     sFileName;      // sFileName
  57.     FILE*       fd;             // File handle
  58.     long        nRecordCount;   // No. of records
  59.     long        nCurrentRecord; // Current read record
  60.     int         nFieldCount;    // No. of fields
  61.     CPtrArray   fieldArray;     // Array with fields
  62.     char*       recordBuf;      // buffer for reading records
  63.         // If this application is compiled with _UNICODE switch,
  64.         // the data name will be converted to/from wide chars
  65.         // in the SetValue/GetValue routines (see below).
  66.     BOOL        bReadOnly;
  67.     BOOL        bWriteFlag;
  68.  
  69.     BOOL Seek(long nRecord);
  70.     void Flush();
  71.     void AddNew();
  72.  
  73.     CField* GetField(int n) const;
  74.  
  75.     BOOL IsDeleted() const;
  76.  
  77.     // DBCS/UNICODE aware versions of SetValue and GetValue
  78.     BOOL SetValue(int n, LPCTSTR s);
  79.     BOOL GetValue(int n, CString& result) const;
  80.  
  81.     int InitFields();
  82.  
  83.     short offset;
  84.     short size;
  85. };
  86.  
  87. #endif // _DBFILE_H_
  88.