csvfile.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //---------------------------------------------------------------------------
  2. //
  3. // csvfile.h - This file contains the class declaration for the CSV Files
  4. //
  5. // The CSV file is an Excel csv style file.
  6. //
  7. // MechCommander 2
  8. //
  9. //---------------------------------------------------------------------------//
  10. // Copyright (C) Microsoft Corporation. All rights reserved. //
  11. //===========================================================================//
  12. #ifndef CSVFILE_H
  13. #define CSVFILE_H
  14. //---------------------------------------------------------------------------
  15. // Include files
  16. #ifndef DSTD_H
  17. #include "dstd.h"
  18. #endif
  19. #ifndef DCSVFILE_H
  20. #include "dcsvfile.h"
  21. #endif
  22. #ifndef FILE_H
  23. #include "file.h"
  24. #endif
  25. //---------------------------------------------------------------------------
  26. // Macro Definitions
  27. //---------------------------------------------------------------------------
  28. // Enums
  29. //---------------------------------------------------------------------------
  30. // Structs
  31. //---------------------------------------------------------------------------
  32. // CSVFile
  33. class CSVFile : public File
  34. {
  35. // Data Members
  36. //--------------
  37. protected:
  38. DWORD totalRows; //Number of ROWS CSV file has.
  39. DWORD totalCols; //NUmber of COLS CSV file has.
  40. char dataBuffer[2048];
  41. // Member Functions
  42. //------------------
  43. protected:
  44. long afterOpen (void);
  45. void atClose (void);
  46. long countRows (void);
  47. long countCols (void);
  48. long getNextWord (char *&line, char *buffer, unsigned long bufLen);
  49. float textToFloat (char *num);
  50. long textToLong (char *num);
  51. unsigned long textToULong (char *num);
  52. short textToShort (char *num);
  53. unsigned short textToUShort (char *num);
  54. char textToChar (char *num);
  55. unsigned char textToUChar (char *num);
  56. bool booleanToLong (char *num);
  57. long floatToText (char *result, float num, unsigned long bufLen);
  58. long longToTextDec (char *result, long num, unsigned long bufLen);
  59. long longToTextHex (char *result, long num, unsigned long bufLen);
  60. long shortToTextDec (char *result, short num, unsigned long bufLen);
  61. long shortToTextHex (char *result, short num, unsigned long bufLen);
  62. long byteToTextDec (char *result, byte num, unsigned long bufLen);
  63. long byteToTextHex (char *result, byte num, unsigned long bufLen);
  64. long copyString (char* dest, char *src, unsigned long bufLen);
  65. public:
  66. CSVFile (void);
  67. ~CSVFile (void);
  68. virtual long open (const char* fName, FileMode _mode = READ, long numChildren = 50);
  69. virtual long open (FilePtr _parent, unsigned long fileSize, long numChildren = 50);
  70. virtual long create (char* fName);
  71. virtual void close (void);
  72. virtual FileClass getFileClass (void)
  73. {
  74. return CSVFILE;
  75. }
  76. long seekRowCol (DWORD row, DWORD col);
  77. long readFloat (DWORD row, DWORD col, float &value);
  78. long readBoolean (DWORD row, DWORD col, bool &value);
  79. long readLong (DWORD row, DWORD col, long &value);
  80. long readULong (DWORD row, DWORD col, unsigned long &value);
  81. long readShort (DWORD row, DWORD col, short &value);
  82. long readUShort (DWORD row, DWORD col, unsigned short &value);
  83. long readChar (DWORD row, DWORD col, char &value);
  84. long readUChar (DWORD row, DWORD col, unsigned char &value);
  85. long readString (DWORD row, DWORD col, char *result, unsigned long bufferSize);
  86. };
  87. //---------------------------------------------------------------------------
  88. #endif