-
Notifications
You must be signed in to change notification settings - Fork 21
/
cfg.h
39 lines (32 loc) · 1.18 KB
/
cfg.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
#ifndef CONFIG_H_WED_AUG_13_14_38_23_2015
#define CONFIG_H_WED_AUG_13_14_38_23_2015
#include <stdlib.h>
#include <stdbool.h>
typedef enum {
// config data type
cdt_none = 0,
cdt_bool,
cdt_uint16,
cdt_int,
cdt_double,
cdt_string,
cdt_object,
} cfg_data_type;
typedef struct config_item_t {
const char * key;
cfg_data_type type;
void * value; // Must be NULL for array and object
unsigned int vcount;
bool list; //
struct config_item_t * subitems; // Must be NULL for object array
//unsigned int n_subitems;
// This callback is responsible for allocate and init data area for subitems.
struct config_item_t * (*subitems_init_cb)(unsigned int count);
void (*subitems_free_cb)(struct config_item_t * items, unsigned int count);
void * _malloc; // internal usage only. For remember memory allocated by configsystem.
} config_item;
bool cfg_loads(const char * json, size_t len, config_item *items);
bool cfg_loadf(const char * path, config_item * items);
void cfg_reset_items(config_item *items);
config_item * cfg_find_item(const char * key, config_item * items);
#endif /* CONFIG_H_WED_AUG_13_14_38_23_2015 */