-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunix_config.h
73 lines (54 loc) · 1.53 KB
/
unix_config.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
/*
* unix_config.h
*
* Created on: 2011-10-18
* Author: gxl2007@hotmail.com
*/
#ifndef UNIX_CONFIG_H_
#define UNIX_CONFIG_H_
namespace xlnet
{
class unix_config
{
public:
enum
{
BUCKETS_BITS = 10 ,
BUCKETS_MASK = ~((~0x0) << BUCKETS_BITS ) ,
BUCKETS_SIZE = ( 0x1 << BUCKETS_BITS ) ,
MAX_LINE_SIZE = 2048 ,
};
struct config_node_type
{
config_node_type* next ;
unsigned int hash_value ;
unsigned int key_size ;
char key[0] ;
};
public:
const char* get(const char* key,const char* default_value = 0) ;
int get(const char* key,int default_value) ;
int set(const char* key,const char* value) ;
int set(const char* key,int key_size,const char* value,int value_size) ;
void remove(const char* key) ;
int load(const char* file) ;
int load(const char* data,int size) ;
int save(const char* file) ;
void dump(int fd) ;
void clear() ;
public:
unix_config();
~unix_config();
private:
unix_config(const unix_config&) ;
unix_config& operator=(const unix_config&) ;
private:
config_node_type* get_node(const char* key,config_node_type** pre_node_return=0) ;
int parse_line(const char* data) ;
static unsigned int hash(const char *p) ;
static unsigned int bucket(unsigned hash_value) {return hash_value & BUCKETS_MASK ;} ;
private:
config_node_type* m_buckets[BUCKETS_SIZE] ;
};
}
#endif /* SIMPLE_CONFIG_H_ */