TEST_COL0_SIZE, TEST_COL1_TS
};
-static struct table test_tbl = {
+static struct table_template test_tbl = {
TBL_COLUMNS {
[TEST_COL0_SIZE] = TBL_COL_SIZE_FMT("size", 15, UNIT_BYTE),
[TEST_COL1_TS] = TBL_COL_TIMESTAMP("ts", 20),
bclose(out);
}
-
-
-static struct table test_tbl2 = {
+static struct table_template test_tbl2 = {
TBL_COLUMNS {
[TEST_COL0_SIZE] = TBL_COL_SIZE_FMT("size", 15, UNIT_BYTE),
[TEST_COL1_TS] = TBL_COL_TIMESTAMP("ts", 20),
test_col0_str, test_col1_int, test_col2_uint, test_col3_bool, test_col4_double
};
-static struct table test_tbl = {
+static struct table_template test_tbl = {
TBL_COLUMNS {
[test_col0_str] = TBL_COL_STR("col0_str", 30 | CELL_ALIGN_LEFT),
[test_col1_int] = TBL_COL_INT("col1_int", 8),
TBL_COL_DELIMITER("\t"),
};
-static int test_to_perform = -1;
static char **cli_table_opts;
static struct opt_section table_printer_opts = {
static struct table_col_info test_column_order[] = { TBL_COL(test_col3_bool), TBL_COL(test_col4_double), TBL_COL(test_col2_uint), TBL_COL(test_col1_int), TBL_COL(test_col0_str) };
-static struct table test_tbl = {
+static struct table_template test_tbl = {
TBL_COLUMNS {
[test_col0_str] = TBL_COL_STR("col0_str", 20),
[test_col1_int] = TBL_COL_INT("col1_int", 8),
test_default_order_col0_int, test_default_order_col1_int, test_default_order_col2_int
};
-static struct table test_default_order_tbl = {
+static struct table_template test_default_order_tbl = {
TBL_COLUMNS {
[test_default_order_col0_int] = TBL_COL_INT("col0_int", 8),
[test_default_order_col1_int] = TBL_COL_INT("col1_int", 9),
/*** Management of tables ***/
-static void table_template_init(struct table *tbl_template)
-{
- if(!tbl_template->pool) {
- tbl_template->pool = mp_new(4096);
- }
-}
-
-static struct table *table_template_copy(struct table *tbl_template)
+static struct table *table_template_copy(struct table_template *tbl_template)
{
struct table *copy = mp_alloc_zero(tbl_template->pool, sizeof(struct table));
copy->columns = tbl_template->columns;
copy->col_delimiter = tbl_template->col_delimiter;
- copy->print_header = tbl_template->print_header;
+ copy->print_header = 1;
copy->out = 0;
copy->last_printed_col = -1;
copy->row_printing_started = 0;
return copy;
}
-struct table *table_init(struct table *tbl_template)
+struct table *table_init(struct table_template *tbl_template)
{
int col_count = 0; // count the number of columns in the struct table
- table_template_init(tbl_template);
+ if(!tbl_template->pool) {
+ tbl_template->pool = mp_new(4096);
+ }
struct table *tbl = table_template_copy(tbl_template);
static struct table_col_info test_column_order[] = { TBL_COL(test_col3_bool), TBL_COL(test_col4_double), TBL_COL(test_col2_uint), TBL_COL(test_col1_int), TBL_COL(test_col0_str) };
-static struct table test_tbl = {
+static struct table_template test_tbl = {
TBL_COLUMNS {
[test_col0_str] = TBL_COL_STR("col0_str", 20),
[test_col1_int] = TBL_COL_INT("col1_int", 8),
static struct table_col_info test_any_column_order[] = { TBL_COL(test_any_col0_int), TBL_COL(test_any_col1_any) };
-static struct table test_any_tbl = {
+static struct table_template test_any_tbl = {
TBL_COLUMNS {
[test_any_col0_int] = TBL_COL_INT("col0_int", 8),
[test_any_col1_any] = TBL_COL_ANY("col1_any", 9),
};
/**
- * Definition of a table. Contains column definitions, per-table settings
- * and internal data. Please use only fields marked with `[*]`.
+ * Definition of a table. Contains column definitions, and some per-table settings.
+ * Please use only fields marked with `[*]`.
+ **/
+struct table_template {
+ struct table_column *columns; // [*] Definition of columns
+ int column_count; // [*] Number of columns (calculated by table_init())
+ struct table_col_info *column_order; // [*] Order of the columns in the print-out of the table
+ uint cols_to_output; // [*] Number of columns that are printed
+ const char *col_delimiter; // [*] Delimiter that is placed between columns
+ // Back-end used for table formatting and its private data
+ struct table_formatter *formatter;
+
+ struct mempool *pool; // Memory pool used for storing table handles.
+};
+
+/**
+ * Handle of a table. Contains column definitions, per-table settings
+ * and internal data. To change the table definition, please use only
+ * fields marked with `[*]`.
**/
struct table {
struct table_column *columns; // [*] Definition of columns
* Creates a new table from a table template. The template should already contain
* the definitions of columns.
**/
-struct table *table_init(struct table *tbl_template);
+struct table *table_init(struct table_template *tbl_template);
/** Destroy a table definition, freeing all memory used by it. **/
void table_cleanup(struct table *tbl);