forked from gozfree/gear-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibconfig.h
57 lines (46 loc) · 1.78 KB
/
libconfig.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
/*****************************************************************************
* Copyright (C) 2014-2015
* file: libconfig.h
* author: gozfree <[email protected]>
* created: 2015-09-29 23:49
* updated: 2015-09-29 23:49
*****************************************************************************/
#ifndef LIBCONFIG_H
#define LIBCONFIG_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct config {
struct config_ops *ops;
void *priv;
} config_t;
typedef struct config_ops {
int (*load)(struct config *c, const char *name);
int (*set_string)(struct config *c, const char *key, const char *val, const char *end);
char *(*get_string) (struct config *c, ...);
int (*get_int) (struct config *c, ...);
double (*get_double)(struct config *c, ...);
int (*get_boolean) (struct config *c, ...);
void (*del)(struct config *c, const char *key);
void (*dump)(struct config *c, FILE *f);
int (*save)(struct config *c);
void (*unload)(struct config *c);
} config_ops_t;
extern struct config *g_config;
struct config *conf_load(const char *name);
int conf_set(struct config *c, const char *key, const char *val);
#define conf_get_int(c, ...) g_config->ops->get_int(c, __VA_ARGS__, NULL)
#define conf_get_string(c, ...) g_config->ops->get_string(c, __VA_ARGS__, NULL)
#define conf_set_string(c, ...) g_config->ops->set_string(c, __VA_ARGS__, NULL)
#define conf_get_double(c, ...) g_config->ops->get_double(c, __VA_ARGS__, NULL)
#define conf_get_boolean(c, ...) g_config->ops->get_boolean(c, __VA_ARGS__, NULL)
void conf_del(struct config *c, const char *key);
void conf_dump(struct config *c);
int conf_save(struct config *c);
void conf_dump_to_file(FILE *f, struct config *c);
void conf_unload(struct config *c);
#ifdef __cplusplus
}
#endif
#endif