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 *
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);
\f
/* 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)
{
}
}
-static int
+int
tab_get_rule (const struct table *table, enum table_axis axis, int x, int y,
struct cell_color *color)
{
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);
}
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 */
return table_cell_colspan (cell) > 1 || table_cell_rowspan (cell) > 1;
}
\f
-/* 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);
-\f
/* For use primarily by output drivers. */
void table_get_cell (const struct table *, int x, int y, struct table_cell *);
{
assert (table->ref_cnt > 0);
if (--table->ref_cnt == 0)
- table->klass->destroy (table);
+ tab_destroy (table);
}
}
table->h[TABLE_VERT][1] = hb;
}
\f
-/* 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;
-}
-\f
struct area_style *
area_style_clone (struct pool *pool, const struct area_style *old)
{
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)
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
/* A table. */
struct table
{
- const struct table_class *klass;
-
/* Table size.
n[TABLE_HORZ]: Number of columns.