配置文件類!
從臺北出差回來,完成了Settings類,參考了詞法分析和語言分析。////////////////////////////
// file : test.conf
a = 1;
b = 1
2
3
;
c = hi you;
d = "hi you" boy 110;
e = "\\=\\ \"test\""; // \=\"test"
/* end */
////////////////////////////
其中:
// 和 /* */是注釋;
\\ 轉義為\ , \*轉義為*;
每個值空格分隔,如果使用了引號",則" "之間的就為值;
轉義符,必須用在""形式的值中;
分號;為結束符號。
載入配置文件:
1
bool Open(const char *filename);

獲取指定key的value:
1
const char *GetValue(const char *key, int idx=0);

下面是一個使用demo:
1
#include "../src/Common/Settings.h"
2
3
int main(int argc, char *argv[])
4

{
5
6
Settings s;
7
if( s.Open("test.conf") )
8
{
9
LOGI("load file succed!");
10
11
LOGE("%s", s.GetValue("c", 3) );
12
}
13
else
14
{
15
LOGE("load file failed!");
16
}
17
return 0;
18
}
19

2

3

4



5

6

7

8



9

10

11

12

13

14



15

16

17

18

19

//
代碼:http://code.google.com/p/bugs1111 里面查找settgings.h settgings.cpp