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

# User Rev Content
1 pippijn 1.1 /*
2 pippijn 1.3 * Copyright © 2005 William Pitcock, et al.
3 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * Data structures for flags to bitmask processing routines.
6     *
7 pippijn 1.4 * $Id: confparse.h,v 1.3 2007-08-28 17:08:06 pippijn Exp $
8 pippijn 1.1 */
9    
10     #ifndef CONFPARSE_H
11     #define CONFPARSE_H
12    
13 pippijn 1.3 #include <ermyth/callback.h>
14 pippijn 1.4 #include <ermyth/type_traits.h>
15 pippijn 1.3
16     struct config_file_t : zero_initialised
17 pippijn 1.1 {
18     char *cf_filename;
19     config_entry_t *cf_entries;
20     config_file_t *cf_next;
21     };
22    
23 pippijn 1.3 struct config_entry_t : zero_initialised
24 pippijn 1.1 {
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 pippijn 1.4
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 pippijn 1.1 };
63    
64     struct Token
65     {
66 pippijn 1.3 char const * const text;
67     int const value;
68 pippijn 1.1 };
69    
70 pippijn 1.4 class ConfTable
71 pippijn 1.1 {
72 pippijn 1.3 struct callbacks
73     {
74     functor::callback0<> ready;
75     };
76    
77     public:
78     char const * const name;
79     int const rehashable;
80 pippijn 1.1 int (*handler) (config_entry_t *);
81     char *str_val;
82     int *int_val;
83 pippijn 1.3
84     static callbacks callback;
85    
86     ConfTable (char const * const blockname, int const can_rehash, int (*handlerfunc) (config_entry_t *))
87 pippijn 1.4 : name (blockname), rehashable (can_rehash), handler (handlerfunc), str_val (0), int_val (0)
88 pippijn 1.3 {
89     }
90 pippijn 1.1 };
91    
92 pippijn 1.4 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 pippijn 1.1
101     #endif