insert code for reading double numbers from ini-file

Fork of IniFileLib by rinosh 2

Committer:
kokisan2000
Date:
Wed Jan 07 21:52:20 2015 +0000
Revision:
3:1f40bfa093d0
Parent:
1:3601c7feb547
insert code for double numbers in ini-file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rinosh2 0:995403221573 1 ///////////////////////////////////////////////////////////////////////////////
rinosh2 0:995403221573 2 // IniFile: .ini file parser by rinos 2010
kokisan2000 3:1f40bfa093d0 3 // 07.01.2015: DS: inserted code for double format
rinosh2 0:995403221573 4 ///////////////////////////////////////////////////////////////////////////////
rinosh2 0:995403221573 5
rinosh2 0:995403221573 6 // Ini file value (int/bool/string)
rinosh2 0:995403221573 7 // Key1 = 123 -> 123 (int)
rinosh2 0:995403221573 8 // Key2 = 0x123 -> 291 (int)
rinosh2 0:995403221573 9 // Key3 = FALSE -> false (bool)
rinosh2 0:995403221573 10 // Key4 = TRUE -> true (bool)
rinosh2 0:995403221573 11 // Key5 = 123 -> true (bool)
rinosh2 0:995403221573 12 // key6 = abc "def -> 'abc "def' (string)
rinosh2 0:995403221573 13 // key7 = " ghi "jkl " -> ' ghi "jkl '(string)
rinosh2 0:995403221573 14 // #comment line
rinosh2 0:995403221573 15
rinosh2 0:995403221573 16 #ifndef __INI_FILE_H__
rinosh2 0:995403221573 17 #define __INI_FILE_H__
rinosh2 0:995403221573 18
rinosh2 0:995403221573 19 #include "mbed.h"
rinosh2 0:995403221573 20
kokisan2000 3:1f40bfa093d0 21 class IniFile
kokisan2000 3:1f40bfa093d0 22 {
kokisan2000 3:1f40bfa093d0 23 // defines /////////////////////////////////////////////////////////////////
rinosh2 0:995403221573 24 public:
kokisan2000 3:1f40bfa093d0 25 // data type
kokisan2000 3:1f40bfa093d0 26 typedef enum {
kokisan2000 3:1f40bfa093d0 27 DTYPE_INT = -1,
kokisan2000 3:1f40bfa093d0 28 DTYPE_BOOL = -2,
kokisan2000 3:1f40bfa093d0 29 DTYPE_DOUBLE = -3,
kokisan2000 3:1f40bfa093d0 30 // other string
kokisan2000 3:1f40bfa093d0 31 } DataType;
rinosh2 0:995403221573 32
kokisan2000 3:1f40bfa093d0 33 // For the multiple read
kokisan2000 3:1f40bfa093d0 34 struct IniList {
kokisan2000 3:1f40bfa093d0 35 const char* key; // key name (set NULL for list end)
kokisan2000 3:1f40bfa093d0 36 int typelen; // >0: buffer length, <0: DataType
kokisan2000 3:1f40bfa093d0 37 void* buf; // return buffer
kokisan2000 3:1f40bfa093d0 38 };
rinosh2 0:995403221573 39
kokisan2000 3:1f40bfa093d0 40 // error code
kokisan2000 3:1f40bfa093d0 41 typedef enum {
kokisan2000 3:1f40bfa093d0 42 S_SUCCESS,
kokisan2000 3:1f40bfa093d0 43 S_OPEN_ERROR,
kokisan2000 3:1f40bfa093d0 44 S_NOT_OPENED,
kokisan2000 3:1f40bfa093d0 45 S_NO_KEY,
kokisan2000 3:1f40bfa093d0 46 S_BUFFER_TOO_SHORT,
kokisan2000 3:1f40bfa093d0 47 S_FORMAT_ERROR,
kokisan2000 3:1f40bfa093d0 48 } Status;
kokisan2000 3:1f40bfa093d0 49
kokisan2000 3:1f40bfa093d0 50 // internal member/method //////////////////////////////////////////////////
rinosh2 0:995403221573 51 private:
kokisan2000 3:1f40bfa093d0 52 FILE* m_fp;
rinosh2 0:995403221573 53
kokisan2000 3:1f40bfa093d0 54 // Invalid method
rinosh2 0:995403221573 55 protected:
kokisan2000 3:1f40bfa093d0 56 IniFile(const IniFile& v);
kokisan2000 3:1f40bfa093d0 57 const IniFile& operator =(const IniFile& v);
rinosh2 0:995403221573 58
rinosh2 0:995403221573 59 public:
kokisan2000 3:1f40bfa093d0 60 IniFile(const char* file = 0);
kokisan2000 3:1f40bfa093d0 61 ~IniFile();
kokisan2000 3:1f40bfa093d0 62
kokisan2000 3:1f40bfa093d0 63 // Access methods
kokisan2000 3:1f40bfa093d0 64 Status open(const char* file);
kokisan2000 3:1f40bfa093d0 65 Status close();
kokisan2000 3:1f40bfa093d0 66
kokisan2000 3:1f40bfa093d0 67 Status get(const char* key, char* ret, int ret_size);
kokisan2000 3:1f40bfa093d0 68 Status get(const char* key, int& ret);
kokisan2000 3:1f40bfa093d0 69 Status get(const char* key, double& ret);
kokisan2000 3:1f40bfa093d0 70 Status get(const char* key, bool& ret);
kokisan2000 3:1f40bfa093d0 71 Status get(const IniList* inilist);
rinosh2 0:995403221573 72
kokisan2000 3:1f40bfa093d0 73 // For easy acccess
kokisan2000 3:1f40bfa093d0 74 static Status getval(const char* inifile, const char* key, char* ret, int ret_size) {
kokisan2000 3:1f40bfa093d0 75 return IniFile(inifile).get(key, ret, ret_size);
kokisan2000 3:1f40bfa093d0 76 }
kokisan2000 3:1f40bfa093d0 77 static Status getval(const char* inifile, const char* key, int& ret) {
kokisan2000 3:1f40bfa093d0 78 return IniFile(inifile).get(key, ret);
kokisan2000 3:1f40bfa093d0 79 }
kokisan2000 3:1f40bfa093d0 80 static Status getval(const char* inifile, const char* key, bool& ret) {
kokisan2000 3:1f40bfa093d0 81 return IniFile(inifile).get(key, ret);
kokisan2000 3:1f40bfa093d0 82 }
kokisan2000 3:1f40bfa093d0 83 static Status getval(const char* inifile, const char* key, double& ret) {
kokisan2000 3:1f40bfa093d0 84 return IniFile(inifile).get(key, ret);
kokisan2000 3:1f40bfa093d0 85 }
kokisan2000 3:1f40bfa093d0 86 static Status getval(const char* inifile, const IniList* inilist) {
kokisan2000 3:1f40bfa093d0 87 return IniFile(inifile).get(inilist);
kokisan2000 3:1f40bfa093d0 88 }
rinosh2 1:3601c7feb547 89
kokisan2000 3:1f40bfa093d0 90 // for string triming
kokisan2000 3:1f40bfa093d0 91 static Status strtrim(char* dst, const char* src, int dst_size); // move to public
rinosh2 0:995403221573 92 };
rinosh2 0:995403221573 93
rinosh2 1:3601c7feb547 94 // for the table
rinosh2 1:3601c7feb547 95 #define INIFILE_INT(key, val) {key, IniFile::DTYPE_INT, &val}
rinosh2 1:3601c7feb547 96 #define INIFILE_BOOL(key, val) {key, IniFile::DTYPE_BOOL, &val}
kokisan2000 3:1f40bfa093d0 97 #define INIFILE_DOUBLE(key, val) {key, IniFile::DTYPE_DOUBLE, &val}
rinosh2 1:3601c7feb547 98 #define INIFILE_STR(key, buf, size) {key, size, buf}
rinosh2 1:3601c7feb547 99 #define INIFILE_END 0
rinosh2 1:3601c7feb547 100
rinosh2 0:995403221573 101 #endif