1 | /* |
1 | /* |
2 | * Copyright © 2007 William Pitcock <nenolod -at- sacredspiral.co.uk> |
2 | * Copyright © 2007 William Pitcock <nenolod -at- sacredspiral.co.uk> |
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 | * Table rendering class. |
5 | * Table rendering class. |
6 | * |
6 | * |
7 | * $Id: table.h,v 1.2 2007/07/21 01:29:07 pippijn Exp $ |
7 | * $Id: table.h,v 1.3 2007/08/28 17:08:07 pippijn Exp $ |
8 | */ |
8 | */ |
9 | |
9 | |
10 | #ifndef ATHEME_TABLE_H |
10 | #ifndef ATHEME_TABLE_H |
11 | #define ATHEME_TABLE_H |
11 | #define ATHEME_TABLE_H |
12 | |
12 | |
13 | struct table_t |
13 | struct table_t : zero_initialised |
14 | { |
14 | { |
15 | object_t parent; |
15 | object_t parent; |
16 | list_t rows; |
16 | list_t rows; |
17 | }; |
17 | }; |
18 | |
18 | |
19 | struct table_row_t |
19 | struct table_row_t : zero_initialised |
20 | { |
20 | { |
21 | int id; |
21 | int id; |
22 | list_t cells; |
22 | list_t cells; |
23 | }; |
23 | }; |
24 | |
24 | |
25 | struct table_cell_t |
25 | struct table_cell_t : zero_initialised |
26 | { |
26 | { |
27 | int width; /* only if first row. */ |
27 | int width; /* only if first row. */ |
28 | char *name; |
28 | char *name; |
29 | char *value; |
29 | char *value; |
30 | }; |
30 | }; |
31 | |
31 | |
32 | /* |
32 | /* |
33 | * Creates a new table object. Use object_unref() to destroy it. |
33 | * Creates a new table object. Use object_unref() to destroy it. |
34 | */ |
34 | */ |
35 | E table_t *table_new (const char *fmt, ...); |
35 | E table_t *table_new (char const * const fmt, ...); |
36 | |
36 | |
37 | /* |
37 | /* |
38 | * Renders a table, each line going to callback(). |
38 | * Renders a table, each line going to callback(). |
39 | */ |
39 | */ |
40 | E void table_render (table_t * t, void (*callback) (const char *line, void *data), void *data); |
40 | E void table_render (table_t * t, void (*callback) (char const * const line, void *data), void *data); |
41 | |
41 | |
42 | /* |
42 | /* |
43 | * Associates a value with a row. |
43 | * Associates a value with a row. |
44 | */ |
44 | */ |
45 | E void table_cell_associate (table_row_t * r, const char *name, const char *value); |
45 | E void table_cell_associate (table_row_t * r, char const * const name, char const * const value); |
46 | |
46 | |
47 | /* |
47 | /* |
48 | * Associates a row with a table. |
48 | * Associates a row with a table. |
49 | */ |
49 | */ |
50 | E table_row_t *table_row_new (table_t * t); |
50 | E table_row_t *table_row_new (table_t * t); |