From: Ben Pfaff Date: Wed, 25 Dec 2019 22:26:25 +0000 (+0000) Subject: table: Get rid of table_class. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a6b7a4eeccbef99357e07c7f5face4e9be14b6d;p=pspp table: Get rid of table_class. There is only one provider now, so we can slowly get rid of the extra layer. --- diff --git a/src/output/tab.c b/src/output/tab.c index 14d5658629..0166b97808 100644 --- a/src/output/tab.c +++ b/src/output/tab.c @@ -63,8 +63,6 @@ struct tab_joined_cell const struct area_style *style; }; -static const struct table_class tab_table_class; - /* Creates and returns a new table with NC columns and NR rows and initially no header rows or columns. The table's cells are initially empty. */ struct tab_table * @@ -73,7 +71,11 @@ tab_create (int nc, int nr) struct tab_table *t; t = pool_create_container (struct tab_table, container); - table_init (&t->table, &tab_table_class, nc, nr); + t->table.n[TABLE_HORZ] = nc; + t->table.n[TABLE_VERT] = nr; + t->table.h[TABLE_HORZ][0] = t->table.h[TABLE_HORZ][1] = 0; + t->table.h[TABLE_VERT][0] = t->table.h[TABLE_VERT][1] = 0; + t->table.ref_cnt = 1; t->cc = pool_calloc (t->container, nr * nc, sizeof *t->cc); t->ct = pool_calloc (t->container, nr * nc, sizeof *t->ct); @@ -461,14 +463,14 @@ tab_output_text_format (int options, const char *format, ...) /* Table class implementation. */ -static void +void tab_destroy (struct table *table) { struct tab_table *t = tab_cast (table); pool_destroy (t->container); } -static void +void tab_get_cell (const struct table *table, int x, int y, struct table_cell *cell) { @@ -539,7 +541,7 @@ tab_get_cell (const struct table *table, int x, int y, } } -static int +int tab_get_rule (const struct table *table, enum table_axis axis, int x, int y, struct cell_color *color) { @@ -554,15 +556,8 @@ tab_get_rule (const struct table *table, enum table_axis axis, int x, int y, return (raw & TAB_RULE_TYPE_MASK) >> TAB_RULE_TYPE_SHIFT; } -static const struct table_class tab_table_class = { - tab_destroy, - tab_get_cell, - tab_get_rule, -}; - struct tab_table * tab_cast (const struct table *table) { - assert (table->klass == &tab_table_class); return UP_CAST (table, struct tab_table, table); } diff --git a/src/output/tab.h b/src/output/tab.h index b83e178ed8..3f99ac6d07 100644 --- a/src/output/tab.h +++ b/src/output/tab.h @@ -126,5 +126,12 @@ void tab_output_text (int options, const char *string); void tab_output_text_format (int options, const char *, ...) PRINTF_FORMAT (2, 3); +/* For use by table-provider only. */ +struct table_cell; +void tab_destroy (struct table *); +void tab_get_cell (const struct table *, int x, int y, struct table_cell *); +int tab_get_rule (const struct table *, enum table_axis, int x, int y, + struct cell_color *); + #endif /* output/tab.h */ diff --git a/src/output/table-provider.h b/src/output/table-provider.h index 27bf5f47bc..d961d43e10 100644 --- a/src/output/table-provider.h +++ b/src/output/table-provider.h @@ -90,55 +90,6 @@ table_cell_is_joined (const struct table_cell *cell) return table_cell_colspan (cell) > 1 || table_cell_rowspan (cell) > 1; } -/* Declarations to allow defining table classes. */ - -struct table_class - { - /* Frees TABLE. - - The table class may assume that any cells that were retrieved by calling - the 'get_cell' function have been freed (by calling their destructors) - before this function is called. */ - void (*destroy) (struct table *table); - - /* Initializes CELL with the contents of the table cell at column X and row - Y within TABLE. All members of CELL must be initialized, except that if - 'destructor' is set to a null pointer, then 'destructor_aux' need not be - initialized. The 'contents' member of CELL must be set to a nonnull - value. - - The table class must allow any number of cells in the table to be - retrieved simultaneously; that is, TABLE must not assume that a given - cell will be freed before another one is retrieved using 'get_cell'. - - The table class must allow joined cells to be retrieved, with identical - contents, using any (X,Y) location inside the cell. - - The table class must not allow cells to overlap. - - The table class should not allow a joined cell to cross the border - between header rows/columns and the interior of the table. That is, a - joined cell should be entirely within headers rows and columns or - entirely outside them. - - The table class may assume that CELL will be freed before TABLE is - destroyed. */ - void (*get_cell) (const struct table *table, int x, int y, - struct table_cell *cell); - - /* Returns one of the TAL_* enumeration constants (declared in - output/table.h) representing a rule running alongside one of the cells - in TABLE. - - See table_get_rule() in table.c for a detailed explanation of the - meaning of AXIS and X and Y, including a diagram. */ - int (*get_rule) (const struct table *table, - enum table_axis axis, int x, int y, - struct cell_color *color); - }; - -void table_init (struct table *, const struct table_class *, int nc, int nr); - /* For use primarily by output drivers. */ void table_get_cell (const struct table *, int x, int y, struct table_cell *); diff --git a/src/output/table.c b/src/output/table.c index 9f8d202c60..01e2acd118 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -54,7 +54,7 @@ table_unref (struct table *table) { assert (table->ref_cnt > 0); if (--table->ref_cnt == 0) - table->klass->destroy (table); + tab_destroy (table); } } @@ -98,27 +98,6 @@ table_set_hb (struct table *table, int hb) table->h[TABLE_VERT][1] = hb; } -/* Initializes TABLE as a table of the specified CLASS, initially with a - reference count of 1. - - TABLE initially has NR rows and NC columns and no headers. The table - implementation (or its client) may update the header rows and columns. - - A table is an abstract class, that is, a plain struct table is not useful on - its own. Thus, this function is normally called from the initialization - function of some subclass of table. */ -void -table_init (struct table *table, const struct table_class *class, - int nc, int nr) -{ - table->klass = class; - table->n[TABLE_HORZ] = nc; - table->n[TABLE_VERT] = nr; - table->h[TABLE_HORZ][0] = table->h[TABLE_HORZ][1] = 0; - table->h[TABLE_VERT][0] = table->h[TABLE_VERT][1] = 0; - table->ref_cnt = 1; -} - struct area_style * area_style_clone (struct pool *pool, const struct area_style *old) { @@ -154,7 +133,7 @@ table_get_cell (const struct table *table, int x, int y, static const struct area_style default_style = AREA_STYLE_INITIALIZER; cell->style = &default_style; - table->klass->get_cell (table, x, y, cell); + tab_get_cell (table, x, y, cell); } /* Returns one of the TAL_* enumeration constants (declared in output/table.h) @@ -201,7 +180,7 @@ table_get_rule (const struct table *table, enum table_axis axis, int x, int y, assert (x >= 0 && x < table->n[TABLE_HORZ] + (axis == TABLE_HORZ)); assert (y >= 0 && y < table->n[TABLE_VERT] + (axis == TABLE_VERT)); *color = (struct cell_color) CELL_COLOR_BLACK; - return table->klass->get_rule (table, axis, x, y, color); + return tab_get_rule (table, axis, x, y, color); } void diff --git a/src/output/table.h b/src/output/table.h index 5331aa3438..aa1edc107c 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -208,8 +208,6 @@ static inline int table_rule_combine (int a, int b) /* A table. */ struct table { - const struct table_class *klass; - /* Table size. n[TABLE_HORZ]: Number of columns.