Bugs

MMORPG game develop.

配置文件类!

从台北出差回来,完成了Settings类,参考了词法分析和语言分析。
////////////////////////////
// file : test.conf
a = 1;

b = 1
2
3
;

c = hi you;

d = "hi you" boy 110;

e = "\\=\\ \"test\"";        //  \=\"test"

/* end */
////////////////////////////


其中:
// 和 /* */是注释;
 \\ 转义为\ , \*转义为*;
每个值空格分隔,如果使用了引号",则" "之间的就为值;
转义符,必须用在""形式的值中;
分号;为结束符号。

载入配置文件:
1bool Open(const char *filename);


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


下面是一个使用demo:
 1#include "../src/Common/Settings.h"
 2
 3int 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

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

posted on 2008-05-26 15:25 Bugs 阅读(1802) 评论(4)  编辑 收藏 引用

评论

# re: 配置文件类! 2008-05-27 02:27 yayv

楼主不厚道, 替你找出地址来

Settings.h 和 Settings.cpp文件地址如下:
http://bugs1111.googlecode.com/svn/trunk/src/Common/Settings.h
http://bugs1111.googlecode.com/svn/trunk/src/Common/Settings.cpp  回复  更多评论   

# re: 配置文件类! 2008-05-27 09:29 bugs_killer

不错.. 顶一个..  回复  更多评论   

# re: 配置文件类![未登录] 2008-05-27 10:11 Bugs

@yayv
谢谢 :)  回复  更多评论   

# re: 配置文件类! 2008-05-28 16:09 盛大推广员

楼主是个高手。收藏下  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理