ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/confparse.h
Revision: 1.4
Committed: Tue Aug 28 22:18:30 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +34 -11 lines
Log Message:
added type traits

File Contents

# Content
1 /*
2 * Copyright © 2005 William Pitcock, et al.
3 * Rights to this code are as documented in doc/pod/license.pod.
4 *
5 * Data structures for flags to bitmask processing routines.
6 *
7 * $Id: confparse.h,v 1.3 2007-08-28 17:08:06 pippijn Exp $
8 */
9
10 #ifndef CONFPARSE_H
11 #define CONFPARSE_H
12
13 #include <ermyth/callback.h>
14 #include <ermyth/type_traits.h>
15
16 struct config_file_t : zero_initialised
17 {
18 char *cf_filename;
19 config_entry_t *cf_entries;
20 config_file_t *cf_next;
21 };
22
23 struct config_entry_t : zero_initialised
24 {
25 config_file_t *ce_fileptr;
26
27 int ce_varlinenum;
28 char *ce_varname;
29 char *ce_vardata;
30 int ce_vardatanum;
31 int ce_fileposstart;
32 int ce_fileposend;
33
34 int ce_sectlinenum;
35 config_entry_t *ce_entries;
36
37 config_entry_t *ce_prevlevel;
38
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 }
62 };
63
64 struct Token
65 {
66 char const * const text;
67 int const value;
68 };
69
70 class ConfTable
71 {
72 struct callbacks
73 {
74 functor::callback0<> ready;
75 };
76
77 public:
78 char const * const name;
79 int const rehashable;
80 int (*handler) (config_entry_t *);
81 char *str_val;
82 int *int_val;
83
84 static callbacks callback;
85
86 ConfTable (char const * const blockname, int const can_rehash, int (*handlerfunc) (config_entry_t *))
87 : name (blockname), rehashable (can_rehash), handler (handlerfunc), str_val (0), int_val (0)
88 {
89 }
90 };
91
92 E void init_newconf (void);
93 E struct ConfTable *find_top_conf (char const * const name);
94 E struct ConfTable *find_conf_item (char const * const name, list_t *conflist);
95 E void add_top_conf (char const * const name, 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));
97 E void del_top_conf (char const * const name);
98 E void del_conf_item (char const * const name, list_t *conflist);
99 E int subblock_handler (config_entry_t *ce, list_t *entries);
100
101 #endif