Claes Ekengren / Mbed 2 deprecated Measurement_system

Dependencies:   mbed

Committer:
CE
Date:
Thu Jan 06 19:01:44 2011 +0000
Revision:
0:0732b16d9a92
R1A

Who changed what in which revision?

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