1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997, 1998, 1999, 2000, 2009, 2013, 2014 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #ifndef OUTPUT_TABLE_H
18 #define OUTPUT_TABLE_H 1
22 . A table is a rectangular grid of cells. Cells can be joined to form larger
23 cells. Rows and columns can be separated by rules of various types. Rows
24 at the top and bottom of a table and columns at the left and right edges of
25 a table can be designated as headers, which means that if the table must be
26 broken across more than one page, those rows or columns are repeated on each
29 Every table is an instance of a particular table class that is responsible
30 for keeping track of cell data. By far the most common table class is
31 struct tab_table (see output/tab.h). This header also declares some other
32 kinds of table classes, near the end of the file.
34 A table is not itself an output_item, and thus a table cannot by itself be
35 used for output, but they can be embedded inside struct table_item (see
36 table-item.h) for that purpose. */
46 /* Properties of a table cell. */
51 /* Horizontal alignment of cell contents. */
55 TAB_HALIGN = 3 << 0, /* Alignment mask. */
57 /* Vertical alignment of cell contents. */
61 TAB_VALIGN = 3 << 2, /* Alignment mask. */
63 /* These flags may be combined with any alignment. */
64 TAB_EMPH = 1 << 4, /* Emphasize cell contents. */
65 TAB_FIX = 1 << 5, /* Use fixed font. */
67 /* Bits with values (1 << TAB_FIRST_AVAILABLE) and higher are
68 not used, so they are available for subclasses to use as
70 TAB_FIRST_AVAILABLE = 6
73 /* Styles for the rules around table cells. */
77 TAL_1, /* Single line. */
78 TAL_2, /* Double line. */
82 /* Given line styles A and B (each one of the TAL_* enumeration constants
83 above), returns a line style that "combines" them, that is, that gives a
84 reasonable line style choice for a rule for different reasons should have
87 Used especially for pasting tables together (see table_paste()). */
88 static inline int table_rule_combine (int a, int b)
95 Many table-related declarations use 2-element arrays in place of "x" and "y"
96 variables. This reduces code duplication significantly, because much table
97 code has treat rows and columns the same way.
99 A lot of code that uses these enumerations assumes that the two values are 0
100 and 1, so don't change them to other values. */
111 const struct table_class *klass;
115 n[TABLE_HORZ]: Number of columns.
116 n[TABLE_VERT]: Number of rows. */
121 Rows at the top and bottom of a table and columns at the left and right
122 edges of a table can be designated as headers. If the table must be
123 broken across more than one page for output, headers rows and columns
124 are repeated on each page.
126 h[TABLE_HORZ][0]: Left header columns.
127 h[TABLE_HORZ][1]: Right header columns.
128 h[TABLE_VERT][0]: Top header rows.
129 h[TABLE_VERT][1]: Bottom header rows. */
130 int h[TABLE_N_AXES][2];
132 /* Reference count. A table may be shared between multiple owners,
133 indicated by a reference count greater than 1. When this is the case,
134 the table must not be modified. */
138 /* Reference counting. */
139 struct table *table_ref (const struct table *);
140 void table_unref (struct table *);
141 bool table_is_shared (const struct table *);
142 struct table *table_unshare (struct table *);
144 /* Returns the number of columns or rows, respectively, in T. */
145 static inline int table_nc (const struct table *t)
146 { return t->n[TABLE_HORZ]; }
147 static inline int table_nr (const struct table *t)
148 { return t->n[TABLE_VERT]; }
150 /* Returns the number of left, right, top, or bottom headers, respectively, in
152 static inline int table_hl (const struct table *t)
153 { return t->h[TABLE_HORZ][0]; }
154 static inline int table_hr (const struct table *t)
155 { return t->h[TABLE_HORZ][1]; }
156 static inline int table_ht (const struct table *t)
157 { return t->h[TABLE_VERT][0]; }
158 static inline int table_hb (const struct table *t)
159 { return t->h[TABLE_VERT][1]; }
162 void table_set_hl (struct table *, int hl);
163 void table_set_hr (struct table *, int hr);
164 void table_set_ht (struct table *, int ht);
165 void table_set_hb (struct table *, int hb);
169 /* Simple kinds of tables. */
170 struct table *table_from_string (unsigned int options, const char *);
171 struct table *table_from_string_span (unsigned int options, const char *,
172 int colspan, int rowspan);
173 struct table *table_from_variables (unsigned int options,
174 struct variable **, size_t);
175 struct table *table_from_casereader (const struct casereader *,
178 const struct fmt_spec *);
180 /* Combining tables. */
181 struct table *table_paste (struct table *, struct table *,
182 enum table_axis orientation);
183 struct table *table_hpaste (struct table *left, struct table *right);
184 struct table *table_vpaste (struct table *top, struct table *bottom);
185 struct table *table_stomp (struct table *);
187 /* Taking subsets of tables. */
188 struct table *table_select (struct table *, int rect[TABLE_N_AXES][2]);
189 struct table *table_select_slice (struct table *, enum table_axis,
190 int z0, int z1, bool add_headers);
191 struct table *table_select_columns (struct table *,
192 int x0, int x1, bool add_headers);
193 struct table *table_select_rows (struct table *,
194 int y0, int y1, bool add_headers);
196 /* Miscellaneous table operations. */
197 struct table *table_transpose (struct table *);
199 #endif /* output/table.h */