… | |
… | |
2 | * Copyright © 2005 William Pitcock, et al. |
2 | * Copyright © 2005 William Pitcock, et al. |
3 | * Rights to this code are as documented in doc/pod/license.pod. |
3 | * Rights to this code are as documented in doc/pod/license.pod. |
4 | * |
4 | * |
5 | * Data structures for flags to bitmask processing routines. |
5 | * Data structures for flags to bitmask processing routines. |
6 | * |
6 | * |
7 | * $Id: confparse.h,v 1.3 2007/08/28 17:08:06 pippijn Exp $ |
7 | * $Id: confparse.h,v 1.4 2007/08/28 22:18:30 pippijn Exp $ |
8 | */ |
8 | */ |
9 | |
9 | |
10 | #ifndef CONFPARSE_H |
10 | #ifndef CONFPARSE_H |
11 | #define CONFPARSE_H |
11 | #define CONFPARSE_H |
12 | |
12 | |
13 | #include <ermyth/callback.h> |
13 | #include <ermyth/callback.h> |
|
|
14 | #include <ermyth/type_traits.h> |
14 | |
15 | |
15 | struct config_file_t : zero_initialised |
16 | struct config_file_t : zero_initialised |
16 | { |
17 | { |
17 | char *cf_filename; |
18 | char *cf_filename; |
18 | config_entry_t *cf_entries; |
19 | config_entry_t *cf_entries; |
… | |
… | |
34 | config_entry_t *ce_entries; |
35 | config_entry_t *ce_entries; |
35 | |
36 | |
36 | config_entry_t *ce_prevlevel; |
37 | config_entry_t *ce_prevlevel; |
37 | |
38 | |
38 | config_entry_t *ce_next; |
39 | config_entry_t *ce_next; |
|
|
40 | |
|
|
41 | bool valid () |
|
|
42 | { |
|
|
43 | return ce_vardata != NULL; |
|
|
44 | } |
|
|
45 | |
|
|
46 | template<typename T> |
|
|
47 | T vardata () |
|
|
48 | { |
|
|
49 | return vardata (types::get<T> ()); |
|
|
50 | } |
|
|
51 | |
|
|
52 | private: |
|
|
53 | char *vardata (types::charptr_type) |
|
|
54 | { |
|
|
55 | return ce_vardata; |
|
|
56 | } |
|
|
57 | |
|
|
58 | int vardata (types::int_type) |
|
|
59 | { |
|
|
60 | return ce_vardatanum; |
|
|
61 | } |
39 | }; |
62 | }; |
40 | |
63 | |
41 | struct Token |
64 | struct Token |
42 | { |
65 | { |
43 | char const * const text; |
66 | char const * const text; |
44 | int const value; |
67 | int const value; |
45 | }; |
68 | }; |
46 | |
69 | |
47 | class ConfTable : public zero_initialised |
70 | class ConfTable |
48 | { |
71 | { |
49 | struct callbacks |
72 | struct callbacks |
50 | { |
73 | { |
51 | functor::callback0<> ready; |
74 | functor::callback0<> ready; |
52 | }; |
75 | }; |
… | |
… | |
59 | int *int_val; |
82 | int *int_val; |
60 | |
83 | |
61 | static callbacks callback; |
84 | static callbacks callback; |
62 | |
85 | |
63 | ConfTable (char const * const blockname, int const can_rehash, int (*handlerfunc) (config_entry_t *)) |
86 | ConfTable (char const * const blockname, int const can_rehash, int (*handlerfunc) (config_entry_t *)) |
64 | : name (blockname), rehashable (can_rehash), handler (handlerfunc) |
87 | : name (blockname), rehashable (can_rehash), handler (handlerfunc), str_val (0), int_val (0) |
65 | { |
88 | { |
66 | } |
89 | } |
67 | }; |
90 | }; |
68 | |
91 | |
69 | extern void init_newconf (void); |
92 | E void init_newconf (void); |
70 | extern struct ConfTable *find_top_conf (char const * const name); |
93 | E struct ConfTable *find_top_conf (char const * const name); |
71 | extern struct ConfTable *find_conf_item (char const * const name, list_t *conflist); |
94 | E struct ConfTable *find_conf_item (char const * const name, list_t *conflist); |
72 | extern void add_top_conf (char const * const name, int (*handler) (config_entry_t *ce)); |
95 | E void add_top_conf (char const * const name, int (*handler) (config_entry_t *ce)); |
73 | extern void add_conf_item (char const * const name, list_t *conflist, int (*handler) (config_entry_t *ce)); |
96 | E void add_conf_item (char const * const name, list_t *conflist, int (*handler) (config_entry_t *ce)); |
74 | extern void del_top_conf (char const * const name); |
97 | E void del_top_conf (char const * const name); |
75 | extern void del_conf_item (char const * const name, list_t *conflist); |
98 | E void del_conf_item (char const * const name, list_t *conflist); |
76 | extern int subblock_handler (config_entry_t *ce, list_t *entries); |
99 | E int subblock_handler (config_entry_t *ce, list_t *entries); |
77 | |
100 | |
78 | #endif |
101 | #endif |