insert code for reading double numbers from ini-file
Fork of IniFileLib by
Revision 3:1f40bfa093d0, committed 2015-01-07
- Comitter:
- kokisan2000
- Date:
- Wed Jan 07 21:52:20 2015 +0000
- Parent:
- 2:4ae80a05f6ea
- Commit message:
- insert code for double numbers in ini-file
Changed in this revision
IniFile.cpp | Show annotated file Show diff for this revision Revisions of this file |
IniFile.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4ae80a05f6ea -r 1f40bfa093d0 IniFile.cpp --- a/IniFile.cpp Thu Nov 18 17:39:02 2010 +0000 +++ b/IniFile.cpp Wed Jan 07 21:52:20 2015 +0000 @@ -1,6 +1,8 @@ /////////////////////////////////////////////////////////////////////////////// // IniFile: .ini file parser by rinos 2010 /////////////////////////////////////////////////////////////////////////////// +// 07.01.2015: by DS - insert code for double format +/////////////////////////////////////////////////////////////////////////////// #include "IniFile.h" #include <string.h> @@ -112,6 +114,13 @@ printf("IniFile::get %s BOOL %d\n", key, *(bool*)ret); return S_SUCCESS; + case DTYPE_DOUBLE: + strtrim(line, p, INI_LINE_BUF); + *(double*)ret = strtod(line, &p); + + printf("IniFile::get %s DOUBLE %f\n", key, *(double*)ret); + return S_SUCCESS; // always success + default: // string { Status sts = strtrim(ret, p, ret_size); @@ -129,7 +138,9 @@ IniFile::Status IniFile::get(const char* key, bool& ret){ return get(key, (char*)&ret, DTYPE_BOOL); } - +IniFile::Status IniFile::get(const char* key, double& ret){ + return get(key, (char*)&ret, DTYPE_DOUBLE); +} IniFile::Status IniFile::get(const IniFile::IniList* inilist){ Status ret = S_SUCCESS; for(; inilist->key ; ++inilist){
diff -r 4ae80a05f6ea -r 1f40bfa093d0 IniFile.h --- a/IniFile.h Thu Nov 18 17:39:02 2010 +0000 +++ b/IniFile.h Wed Jan 07 21:52:20 2015 +0000 @@ -1,5 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // IniFile: .ini file parser by rinos 2010 +// 07.01.2015: DS: inserted code for double format /////////////////////////////////////////////////////////////////////////////// // Ini file value (int/bool/string) @@ -17,76 +18,83 @@ #include "mbed.h" -class IniFile{ - // defines ///////////////////////////////////////////////////////////////// +class IniFile +{ + // defines ///////////////////////////////////////////////////////////////// public: - // data type - typedef enum { - DTYPE_INT = -1, - DTYPE_BOOL = -2, - // other string - } DataType; + // data type + typedef enum { + DTYPE_INT = -1, + DTYPE_BOOL = -2, + DTYPE_DOUBLE = -3, + // other string + } DataType; - // For the multiple read - struct IniList{ - const char* key; // key name (set NULL for list end) - int typelen; // >0: buffer length, <0: DataType - void* buf; // return buffer - }; + // For the multiple read + struct IniList { + const char* key; // key name (set NULL for list end) + int typelen; // >0: buffer length, <0: DataType + void* buf; // return buffer + }; - // error code - typedef enum { - S_SUCCESS, - S_OPEN_ERROR, - S_NOT_OPENED, - S_NO_KEY, - S_BUFFER_TOO_SHORT, - S_FORMAT_ERROR, - } Status; - - // internal member/method ////////////////////////////////////////////////// + // error code + typedef enum { + S_SUCCESS, + S_OPEN_ERROR, + S_NOT_OPENED, + S_NO_KEY, + S_BUFFER_TOO_SHORT, + S_FORMAT_ERROR, + } Status; + + // internal member/method ////////////////////////////////////////////////// private: - FILE* m_fp; + FILE* m_fp; - // Invalid method + // Invalid method protected: - IniFile(const IniFile& v); - const IniFile& operator =(const IniFile& v); + IniFile(const IniFile& v); + const IniFile& operator =(const IniFile& v); public: - IniFile(const char* file = 0); - ~IniFile(); + IniFile(const char* file = 0); + ~IniFile(); + + // Access methods + Status open(const char* file); + Status close(); + + Status get(const char* key, char* ret, int ret_size); + Status get(const char* key, int& ret); + Status get(const char* key, double& ret); + Status get(const char* key, bool& ret); + Status get(const IniList* inilist); - // Access methods - Status open(const char* file); - Status close(); - - Status get(const char* key, char* ret, int ret_size); - Status get(const char* key, int& ret); - Status get(const char* key, bool& ret); - Status get(const IniList* inilist); - - // For easy acccess - static Status getval(const char* inifile, const char* key, char* ret, int ret_size){ - return IniFile(inifile).get(key, ret, ret_size); - } - static Status getval(const char* inifile, const char* key, int& ret){ - return IniFile(inifile).get(key, ret); - } - static Status getval(const char* inifile, const char* key, bool& ret){ - return IniFile(inifile).get(key, ret); - } - static Status getval(const char* inifile, const IniList* inilist){ - return IniFile(inifile).get(inilist); - } + // For easy acccess + static Status getval(const char* inifile, const char* key, char* ret, int ret_size) { + return IniFile(inifile).get(key, ret, ret_size); + } + static Status getval(const char* inifile, const char* key, int& ret) { + return IniFile(inifile).get(key, ret); + } + static Status getval(const char* inifile, const char* key, bool& ret) { + return IniFile(inifile).get(key, ret); + } + static Status getval(const char* inifile, const char* key, double& ret) { + return IniFile(inifile).get(key, ret); + } + static Status getval(const char* inifile, const IniList* inilist) { + return IniFile(inifile).get(inilist); + } - // for string triming - static Status strtrim(char* dst, const char* src, int dst_size); // move to public + // for string triming + static Status strtrim(char* dst, const char* src, int dst_size); // move to public }; // for the table #define INIFILE_INT(key, val) {key, IniFile::DTYPE_INT, &val} #define INIFILE_BOOL(key, val) {key, IniFile::DTYPE_BOOL, &val} +#define INIFILE_DOUBLE(key, val) {key, IniFile::DTYPE_DOUBLE, &val} #define INIFILE_STR(key, buf, size) {key, size, buf} #define INIFILE_END 0