Inifile.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //---------------------------------------------------------------------------
  2. //
  3. // inifile.h - This file contains the class declaration for the FitIni Files
  4. //
  5. // The FitIni file is a ini style file.
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef INIFILE_H
  11. #define INIFILE_H
  12. //---------------------------------------------------------------------------
  13. // Include files
  14. #ifndef DSTD_H
  15. #include "dstd.h"
  16. #endif
  17. #ifndef DINIFILE_H
  18. #include "dinifile.h"
  19. #endif
  20. #ifndef FILE_H
  21. #include "file.h"
  22. #endif
  23. //---------------------------------------------------------------------------
  24. // Macro Definitions
  25. #ifndef NO_ERR
  26. #define NO_ERR 0x00000000
  27. #endif
  28. #define BLOCK_NOT_FOUND 0xFADA0000
  29. #define ID_NOT_FOUND 0xFADA0001
  30. #define DATA_NOT_CORRECT_TYPE 0xFADA0002
  31. #define BUFFER_TOO_SMALL 0xFADA0003
  32. #define NOT_A_FITINIFILE 0xFADA0004
  33. #define NO_RAM_FOR_INI_BLOCKS 0xFADA0005
  34. #define NO_MORE_BLOCKS 0xFADA0006
  35. #define TOO_MANY_BLOCKS 0xFADA0007
  36. #define NOT_ENOUGH_BLOCKS 0xFADA0008
  37. #define VARIABLE_NOT_FOUND 0xFADA0009
  38. #define SYNTAX_ERROR 0xFADA000A
  39. #define NOT_ENOUGH_ELEMENTS_FOR_ARRAY 0xFADA000B
  40. #define GET_NEXT_LINE 0xFADA000C
  41. #define USER_ARRAY_TOO_SMALL 0xFADA000D
  42. #define TOO_MANY_ELEMENTS 0xFADA000E
  43. //---------------------------------------------------------------------------
  44. // Enums
  45. //---------------------------------------------------------------------------
  46. // Structs
  47. struct IniBlockNode
  48. {
  49. char blockId[50];
  50. unsigned long blockOffset;
  51. };
  52. //---------------------------------------------------------------------------
  53. // FitIniFile
  54. class FitIniFile : public File
  55. {
  56. // Data Members
  57. //--------------
  58. protected:
  59. unsigned long totalBlocks; //Total number of blocks in file
  60. IniBlockNode *fileBlocks; //Data for blocks to speed up file
  61. char *currentBlockId; //Id of current block
  62. unsigned long currentBlockOffset; //Offset into file of block start
  63. unsigned long currentBlockSize; //Length of current block
  64. // Member Functions
  65. //------------------
  66. protected:
  67. long afterOpen (void);
  68. void atClose (void);
  69. long findNextBlockStart (char *line = NULL, unsigned long lineLen = 0);
  70. long countBlocks (void);
  71. long getNextWord (char *&line, char *buffer, unsigned long bufLen);
  72. float textToFloat (const char *num);
  73. double textToDouble (const char *num);
  74. long textToLong (const char *num);
  75. unsigned long textToULong (const char *num);
  76. short textToShort (const char *num);
  77. unsigned short textToUShort (const char *num);
  78. char textToChar (const char *num);
  79. unsigned char textToUChar (const char *num);
  80. bool booleanToLong (const char *num);
  81. float mathToFloat (const char *num);
  82. long mathToLong (const char *num);
  83. unsigned long mathToULong (const char *num);
  84. short mathToShort (const char *num);
  85. unsigned short mathToUShort (const char *num);
  86. char mathToChar (const char *num);
  87. unsigned char mathToUChar (const char *num);
  88. long floatToText (char *result, float num, unsigned long bufLen);
  89. long longToTextDec (char *result, long num, unsigned long bufLen);
  90. long longToTextHex (char *result, long num, unsigned long bufLen);
  91. long shortToTextDec (char *result, short num, unsigned long bufLen);
  92. long shortToTextHex (char *result, short num, unsigned long bufLen);
  93. long byteToTextDec (char *result, byte num, unsigned long bufLen);
  94. long byteToTextHex (char *result, byte num, unsigned long bufLen);
  95. long copyString (char* dest, char *src, unsigned long bufLen);
  96. public:
  97. FitIniFile (void);
  98. ~FitIniFile (void);
  99. virtual long open (const char* fName, FileMode _mode = READ, long numChildren = 50);
  100. virtual long open (FilePtr _parent, unsigned long fileSize, long numChildren = 50);
  101. virtual long create (char* fName);
  102. virtual long createWithCase( char* fName );
  103. virtual void close (void);
  104. virtual FileClass getFileClass (void)
  105. {
  106. return INIFILE;
  107. }
  108. long seekBlock (const char *blockId);
  109. long readIdFloat (const char *varName, float &value);
  110. long readIdDouble (const char *varName, double &value);
  111. long readIdBoolean (const char *varName, bool &value);
  112. long readIdLong (const char *varName, long &value);
  113. long readIdULong (const char *varName, unsigned long &value);
  114. long readIdShort (const char *varName, short &value);
  115. long readIdUShort (const char *varName, unsigned short &value);
  116. long readIdChar (const char *varName, char &value);
  117. long readIdUChar (const char *varName, unsigned char &value);
  118. long readIdString (const char *varName, char *result, unsigned long bufferSize);
  119. long getIdStringLength (const char *varName);
  120. long readIdFloatArray (const char *varName, float *result, unsigned long numElements);
  121. long readIdLongArray (const char *varName, long *result, unsigned long numElements);
  122. long readIdULongArray (const char *varName, unsigned long *result, unsigned long numElements);
  123. long readIdShortArray (const char *varName, short *result, unsigned long numElements);
  124. long readIdUShortArray (const char *varName, unsigned short *result, unsigned long numElements);
  125. long readIdCharArray (const char *varName, char *result, unsigned long numElements);
  126. long readIdUCharArray (const char *varName, unsigned char *result, unsigned long numElements);
  127. unsigned long getIdFloatArrayElements (const char *varName);
  128. unsigned long getIdLongArrayElements (const char *varName);
  129. unsigned long getIdULongArrayElements (const char *varName);
  130. unsigned long getIdShortArrayElements (const char *varName);
  131. unsigned long getIdUShortArrayElements (const char *varName);
  132. unsigned long getIdCharArrayElements (const char *varName);
  133. unsigned long getIdUCharArrayElements (const char *varName);
  134. long writeBlock (const char *blockId);
  135. long writeIdFloat (const char *varName, float value);
  136. long writeIdBoolean (const char *varName, bool value);
  137. long writeIdLong (const char *varName, long value);
  138. long writeIdULong (const char *varName, unsigned long value);
  139. long writeIdShort (const char *varName, short value);
  140. long writeIdUShort (const char *varName, unsigned short value);
  141. long writeIdChar (const char *varName, char value);
  142. long writeIdUChar (const char *varName, unsigned char value);
  143. long writeIdString (const char *varName, const char *result);
  144. long writeIdFloatArray (const char *varName, float *array, unsigned long numElements);
  145. long writeIdLongArray (const char *varName, long *array, unsigned long numElements);
  146. long writeIdUShortArray (const char *varName, unsigned short *array, unsigned long numElements);
  147. long writeIdUCharArray (const char *varName, unsigned char *array, unsigned long numElements);
  148. };
  149. //---------------------------------------------------------------------------
  150. #endif
  151. //---------------------------------------------------------------------------
  152. //
  153. // Edit Log
  154. //
  155. //
  156. //---------------------------------------------------------------------------