table: Get rid of table_class.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 25 Dec 2019 22:26:25 +0000 (22:26 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:28:10 +0000 (05:28 +0000)
There is only one provider now, so we can slowly get rid of the extra
layer.

src/output/tab.c
src/output/tab.h
src/output/table-provider.h
src/output/table.c
src/output/table.h

index 14d56586291d11a264b24bac4f631839b27a73ff..0166b978083f6d85c73b558b4029c1791cdd85e0 100644 (file)
@@ -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, ...)
 \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)
 {
@@ -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);
 }
index b83e178ed8cd7b872f9b84cd195173adad914dd0..3f99ac6d07cefe6ec538d1644433d0c1a75286f8 100644 (file)
@@ -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 */
 
index 27bf5f47bca3c89cd4454fad1eb7ba0e38d5cac9..d961d43e10184058ff0124b8aecdf2b9df0af667 100644 (file)
@@ -90,55 +90,6 @@ table_cell_is_joined (const struct table_cell *cell)
   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 *);
index 9f8d202c60ae99b7bcd7b8214fd8c24cc1382dd4..01e2acd11892c54f9878b5998b79da3fd4c47dc6 100644 (file)
@@ -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;
 }
 \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)
 {
@@ -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
index 5331aa34388d97f0d534ddf6bf8fc3a462db30d5..aa1edc107c307165399e46cbe3404aa6fb898067 100644 (file)
@@ -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.