summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tvconfig/CIniFile.h (plain)
blob: 95ffd65a7817945e49937bc2f5e85f1a40480ed4
1#ifndef INI_FILE_H_
2#define INI_FILE_H_
3/*
4 *vertion 0.01, just linux 8bit byte string, write by showbo
5 */
6#include <CTvLog.h>
7
8static const int MAX_INI_FILE_LINE_LEN = 512;
9
10typedef enum _LINE_TYPE {
11 LINE_TYPE_SECTION = 0,
12 LINE_TYPE_KEY,
13 LINE_TYPE_COMMENT,
14} LINE_TYPE;
15
16//基于链表结构
17
18//行链表,去掉多余的空格和回车,换行后.
19typedef struct _LINE {
20 LINE_TYPE type;//类型
21 char Text[MAX_INI_FILE_LINE_LEN];//内容
22 int LineLen;
23 char *pKeyStart;
24 char *pKeyEnd;
25 char *pValueStart;
26 char *pValueEnd;
27 struct _LINE *pNext;
28} LINE;
29//段链表
30typedef struct _SECTION {
31 LINE *pLine;
32 struct _SECTION *pNext;
33} SECTION;
34
35
36class CIniFile
37{
38public:
39 //const int MAX_SECTION_NAME_LEN = 16;
40 //const int MAX_KEY_NAME_LEN = 64;
41 //const int MAX_VALUE_LEN = 512;
42
43 CIniFile();
44 ~CIniFile();
45 int LoadFromFile(const char *filename);
46 int LoadFromString(const char *str);
47
48 int SaveToFile(const char *filename = NULL);
49
50 int SetString(const char *section, const char *key, const char *value);
51 int SetInt(const char *section, const char *key, int value);
52
53 const char *GetString(const char *section, const char *key, const char *def_value);
54 int GetInt(const char *section, const char *key, int def_value);
55
56 void printAll();
57private:
58 LINE_TYPE getLineType(char *Str);
59 //去掉串里面的,空格,回车,换行,s指向转换处理后的串的开头
60 void allTrim(char *Str);
61
62 SECTION *getSection(const char *section);
63 LINE *getKeyLineAtSec(SECTION *pSec, const char *key);
64
65 void FreeAllMem();
66 int InsertSection(SECTION *pSec);
67 int InsertKeyLine(SECTION *pSec, LINE *line);
68 char mpFileName[256];
69 FILE *m_pIniFile;
70 LINE *mpFirstLine;
71 SECTION *mpFirstSection;
72};
73#endif //end of INI_FILE_H_
74