insert code for reading double numbers from ini-file

Fork of IniFileLib by rinosh 2

Committer:
rinosh2
Date:
Tue Nov 16 16:34:45 2010 +0000
Revision:
0:995403221573
Child:
1:3601c7feb547

        

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