-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathconfReader.h
87 lines (68 loc) · 2.02 KB
/
confReader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @file confReader.h
* @brief 配置文件读取类的头文件
*/
/* confReader.h */
#ifndef _confReader_H
#define _confReader_H
/**
* @example confReader用例
confReader ini("/where/is/config.conf");\n
ini.setSection("MysqlDB");\n
ini.readStr("mysqlServer", ""); // On error,"" is returned.\n
ini.readInt("mysqlPort", 3306); // On error,3306 is returned.\n
*/
#include <string>
using namespace std;
#ifdef _MSC_VER
#define strcasecmp stricmp
#define strncasecmp _strnicmp
#endif
//////////////////////////////////////////////////////////////////////////
/**
* @class confReader
* @brief 配置读取类
*/
class confReader
{
private:
/// 配置文件名称
string m_fileName;
/// 配置文件节点
string m_section;
public:
confReader(const string & fileName);
virtual ~confReader(void);
const string & getFileName() const
{
return m_fileName;
}
// const string &getSection() const;
const string &getSection() const
{
return m_section;
}
void setSection(const string §ion);
string readStr(const string &key,const string &default_value) const;
int readInt(const string &key, int default_value) const;
#ifndef _MSC_VER
bool write(const string &key, const string & value) const ;
bool write(const string &key, int value) const ;
public:
static int read_profile_string( const char *section, const char *key,char *value,
int size, const char *default_value, const char *file);
static int read_profile_int( const char *section, const char *key,int default_value,
const char *file);
static int write_profile_string(const char *section, const char *key,
const char *value, const char *file);
private:
static int load_ini_file(const char *file, char *buf,int *file_size);
static int newline(char c);
static int end_of_string(char c);
static int left_barce(char c);
static int right_brace(char c );
static int parse_file(const char *section, const char *key, const char *buf,int *sec_s,int *sec_e,
int *key_s,int *key_e, int *value_s, int *value_e);
#endif
};
#endif //_confReader_H