pivot-table: Properly allocate pivot_table's current_layer.
[pspp] / src / output / pivot-table.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2017-2018 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #ifndef OUTPUT_PIVOT_TABLE_H
18 #define OUTPUT_PIVOT_TABLE_H 1
19
20 #include <stdint.h>
21 #include <time.h>
22 #include "data/format.h"
23 #include "data/settings.h"
24 #include "libpspp/compiler.h"
25 #include "libpspp/hmap.h"
26 #include "output/table.h"
27
28 struct pivot_value;
29 struct variable;
30 union value;
31
32 /* Pivot tables.
33
34    Pivot tables are PSPP's primary form of output.  They are analogous to the
35    pivot tables you might be familiar with from spreadsheets and databases.
36    See https://en.wikipedia.org/wiki/Pivot_table for a brief introduction to
37    the overall concept of a pivot table.
38
39    In PSPP, the most important internal pieces of a pivot table are:
40
41    - Title.  Every pivot table has a title that is displayed above it.  It also
42      has an optional caption (displayed below it) and corner text (displayed in
43      the upper left corner).
44
45    - Dimensions.  A dimension consists of zero or more categories.  A category
46      has a label, such as "df" or "Asymp. Sig." or 123 or a variable name.  The
47      categories are the leaves of a tree whose non-leaf nodes form groups of
48      categories.  The tree always has a root group whose label is the name of
49      the dimension.
50
51    - Axes.  A table has three axes: column, row, and layer.  Each dimension is
52      assigned to an axis, and each axis has zero or more dimensions.  When an
53      axis has more than one dimension, they are ordered from innermost to
54      outermost.
55
56    - Data.  A table's data consists of zero or more cells.  Each cell maps from
57      a category for each dimension to a value, which is commonly a number but
58      could also be a variable name or an arbitrary text string.
59
60    Creating a pivot table usually consists of the following steps:
61
62    1. Create the table with pivot_table_create(), passing in the title.
63       It's commonly useful to set up a few options at this point:
64
65       - If empty rows or columns should not be displayed, set ->omit_empty to
66         true.
67
68       - Set the format to use for "count" values with
69         pivot_table_set_weight_var() or pivot_table_set_weight_format().
70
71    2. Create each dimension with pivot_dimension_create() and populate it with
72       categories and, possibly, with groups that contain the categories.  This
73       call also assigns the dimension to an axis.
74
75       In simple cases, only a call to pivot_dimension_create() is needed.
76       Other functions such as pivot_category_create_group() can be used for
77       hierarchies of categories.
78
79       Sometimes it's easier to create categories in tandem with inserting data,
80       for example by adding a category for a variable just before inserting the
81       first cell for that variable.  In that case, creating categories and
82       inserting data can be interleaved.
83
84    3. Insert data.  For each cell, supply the category indexes, which are
85       assigned starting from 0 in the order in which the categories were
86       created in step 2, and the value to go in the cell.  If the table has a
87       small, fixed number of dimensions, functions like, e.g.
88       pivot_table_put3() for 3 dimensions, can be used.  The general function
89       pivot_table_put() works for other cases.
90
91    4. Output the table for user consumption.  Use pivot_table_submit(). */
92 \f
93 /* Pivot table display styling. */
94
95 /* Areas of a pivot table for styling purposes. */
96 enum pivot_area
97   {
98     PIVOT_AREA_TITLE,
99     PIVOT_AREA_CAPTION,
100     PIVOT_AREA_FOOTER,          /* Footnotes. */
101     PIVOT_AREA_CORNER,          /* Top-left corner. */
102     PIVOT_AREA_COLUMN_LABELS,
103     PIVOT_AREA_ROW_LABELS,
104     PIVOT_AREA_DATA,
105     PIVOT_AREA_LAYERS,          /* Layer indication. */
106     PIVOT_N_AREAS
107   };
108
109 const char *pivot_area_to_string (enum pivot_area);
110
111 /* Table borders for styling purposes. */
112 enum pivot_border
113   {
114     PIVOT_BORDER_TITLE,
115
116     /* Outer frame. */
117     PIVOT_BORDER_OUTER_LEFT,
118     PIVOT_BORDER_OUTER_TOP,
119     PIVOT_BORDER_OUTER_RIGHT,
120     PIVOT_BORDER_OUTER_BOTTOM,
121
122     /* Inner frame. */
123     PIVOT_BORDER_INNER_LEFT,
124     PIVOT_BORDER_INNER_TOP,
125     PIVOT_BORDER_INNER_RIGHT,
126     PIVOT_BORDER_INNER_BOTTOM,
127
128     /* Data area. */
129     PIVOT_BORDER_DATA_LEFT,
130     PIVOT_BORDER_DATA_TOP,
131
132     /* Dimensions. */
133     PIVOT_BORDER_DIM_ROW_HORZ,
134     PIVOT_BORDER_DIM_ROW_VERT,
135     PIVOT_BORDER_DIM_COL_HORZ,
136     PIVOT_BORDER_DIM_COL_VERT,
137
138     /* Categories. */
139     PIVOT_BORDER_CAT_ROW_HORZ,
140     PIVOT_BORDER_CAT_ROW_VERT,
141     PIVOT_BORDER_CAT_COL_HORZ,
142     PIVOT_BORDER_CAT_COL_VERT,
143
144     PIVOT_N_BORDERS
145   };
146
147 const char *pivot_border_to_string (enum pivot_border);
148
149 /* Sizing for rows or columns of a rendered table.  The comments below talk
150    about columns and their widths but they apply equally to rows and their
151    heights. */
152 struct pivot_table_sizing
153   {
154     /* Minimum and maximum column width, in 1/96" units. */
155     int range[2];
156
157     /* Specific column widths, in 1/96" units. */
158     int *widths;
159     size_t n_widths;
160
161     /* Specific page breaks: 0-based columns after which a page break must
162        occur, e.g. a value of 1 requests a break after the second column. */
163     size_t *breaks;
164     size_t n_breaks;
165
166     /* Keeps: columns to keep together on a page if possible. */
167     struct pivot_keep *keeps;
168     size_t n_keeps;
169   };
170
171 void pivot_table_sizing_uninit (struct pivot_table_sizing *);
172
173 /* A set of columns to keep together on a page if possible, e.g. ofs=1, n=10
174    requests keeping together the 2nd through 11th columns. */
175 struct pivot_keep
176   {
177     size_t ofs;                 /* 0-based first column. */
178     size_t n;                   /* Number of columns. */
179   };
180 \f
181 /* Axes. */
182
183 enum pivot_axis_type
184   {
185     PIVOT_AXIS_LAYER,
186     PIVOT_AXIS_ROW,
187     PIVOT_AXIS_COLUMN,
188
189     PIVOT_N_AXES
190   };
191
192 const char *pivot_axis_type_to_string (enum pivot_axis_type);
193
194 /* An axis within a pivot table. */
195 struct pivot_axis
196   {
197     /* dimensions[0] is the innermost dimension,
198        dimensions[1] is the next outer dimension,
199        ...
200        dimensions[n_dimensions - 1] is the outermost dimension. */
201     struct pivot_dimension **dimensions;
202     size_t n_dimensions;
203
204     /* The number of rows or columns along the axis,
205        that is, the product of dimension[*]->n_leaves.
206        It is 0 if any dimension has 0 leaves. */
207     size_t extent;
208
209     /* Sum of dimensions[*]->label_depth. */
210     size_t label_depth;
211   };
212
213 /* Successively assigns to INDEXES (which should be a "size_t *") each of the
214    combinations of the categories in AXIS's dimensions, in lexicographic order
215    with the innermost dimension iterating most quickly.
216
217    The value assigned to INDEXES is dynamically allocated.  If the client
218    breaks out of the loop prematurely, it needs to free it with free(). */
219 #define PIVOT_AXIS_FOR_EACH(INDEXES, AXIS)                              \
220   for ((INDEXES) = NULL;                                                \
221        ((INDEXES) = pivot_axis_iterator_next (INDEXES, AXIS)) != NULL; )
222 size_t *pivot_axis_iterator_next (size_t *indexes, const struct pivot_axis *);
223 \f
224 /* Dimensions.
225
226    A pivot_dimension identifies the categories associated with a single
227    dimension within a multidimensional pivot table.
228
229    A dimension contains a collection of categories, which are the leaves in a
230    tree of groups.
231
232    (A dimension or a group can contain zero categories, but this is unusual.
233    If a dimension contains no categories, then its table cannot contain any
234    data.)
235 */
236 struct pivot_dimension
237   {
238     /* table->axes[axis_type]->dimensions[level] == dimension. */
239     struct pivot_table *table;
240     enum pivot_axis_type axis_type;
241     size_t level;               /* 0 for innermost dimension within axis. */
242
243     /* table->dimensions[top_index] == dimension. */
244     size_t top_index;
245
246     /* Hierarchy of categories within the dimension.  The groups and categories
247        are sorted in the order that should be used for display.  This might be
248        different from the original order produced for output if the user
249        adjusted it.
250
251        The root must always be a group, although it is allowed to have no
252        subcategories. */
253     struct pivot_category *root;
254
255     /* All of the leaves reachable via the root.
256
257        The indexing for presentation_leaves is presentation order, thus
258        presentation_leaves[i]->presentation_index == i.  This order is the same
259        as would be produced by an in-order traversal of the groups.  It is the
260        order into which the user reordered or sorted the categories.
261
262        The indexing for data_leaves is that used for idx[] in struct
263        pivot_cell, thus data_leaves[i]->data_index == i.  This might differ
264        from what an in-order traversal of 'root' would yield, if the user
265        reordered categories. */
266     struct pivot_category **data_leaves;
267     struct pivot_category **presentation_leaves;
268     size_t n_leaves, allocated_leaves;
269
270     /* Display. */
271     bool hide_all_labels;
272
273     /* Number of rows or columns needed to express the labels. */
274     int label_depth;
275   };
276
277 struct pivot_dimension *pivot_dimension_create (
278   struct pivot_table *, enum pivot_axis_type, const char *name, ...)
279   SENTINEL (0);
280 #define pivot_dimension_create(...) \
281   pivot_dimension_create(__VA_ARGS__, NULL_SENTINEL)
282 struct pivot_dimension *pivot_dimension_create__ (struct pivot_table *,
283                                                   enum pivot_axis_type,
284                                                   struct pivot_value *name);
285
286 void pivot_dimension_destroy (struct pivot_dimension *);
287
288 void pivot_dimension_dump (const struct pivot_dimension *, int indentation);
289 \f
290 /* A pivot_category is a leaf (a category) or a group:
291
292    - For a leaf, neither index is SIZE_MAX.
293
294    - For a group, both indexes are SIZE_MAX.
295
296    Do not use 'subs' or 'n_subs' to determine whether a category is a group,
297    because a group may (pathologically) have no leaves. */
298 struct pivot_category
299   {
300     struct pivot_value *name;
301     struct pivot_category *parent;
302     struct pivot_dimension *dimension;
303     size_t label_depth, extra_depth;
304
305     /* Groups only.
306
307        If show_label is true, then the group itself has a row (or a column)
308        giving the group's name.  Otherwise, the group's own name is not
309        displayed. */
310     struct pivot_category **subs; /* Child categories or groups. */
311     size_t n_subs, allocated_subs;
312     bool show_label;            /* Display a label for the group itself? */
313     bool show_label_in_corner;
314
315     /* Leaf only. */
316     struct fmt_spec format;
317     size_t group_index;        /* In ->parent->subs[]. */
318     size_t data_index;         /* In ->dimension->data_leaves[]. */
319     size_t presentation_index; /* In ->dimension->presentation_leaves[]. */
320   };
321
322 static inline bool
323 pivot_category_is_group (const struct pivot_category *category)
324 {
325   return category->data_index == SIZE_MAX;
326 }
327
328 static inline bool
329 pivot_category_is_leaf (const struct pivot_category *category)
330 {
331   return !pivot_category_is_group (category);
332 }
333
334 /* Creating leaf categories. */
335 int pivot_category_create_leaves (struct pivot_category *parent, ...)
336   SENTINEL (0);
337 #define pivot_category_create_leaves(...) \
338   pivot_category_create_leaves(__VA_ARGS__, NULL_SENTINEL)
339
340 int pivot_category_create_leaf (
341   struct pivot_category *parent, struct pivot_value *name);
342 int pivot_category_create_leaf_rc (
343   struct pivot_category *parent, struct pivot_value *name, const char *rc);
344
345 /* Creating category groups. */
346 struct pivot_category *pivot_category_create_group (
347   struct pivot_category *parent, const char *name, ...) SENTINEL (0);
348 #define pivot_category_create_group(...) \
349   pivot_category_create_group(__VA_ARGS__, NULL_SENTINEL)
350 struct pivot_category *pivot_category_create_group__ (
351   struct pivot_category *parent, struct pivot_value *name);
352
353 void pivot_category_destroy (struct pivot_category *);
354
355 /* Pivot result classes.
356
357    These are used to mark leaf categories as having particular types of data,
358    to set their numeric formats.  The formats that actually get used for these
359    classes are in the result_classes[] global array in pivot-table.c, except
360    that PIVOT_RC_OTHER comes from settings_get_format() and PIVOT_RC_COUNT
361    should come from the weight variable in the dataset's dictionary. */
362 #define PIVOT_RC_OTHER ("RC_OTHER")
363 #define PIVOT_RC_INTEGER ("RC_INTEGER")
364 #define PIVOT_RC_CORRELATION ("RC_CORRELATIONS")
365 #define PIVOT_RC_SIGNIFICANCE ("RC_SIGNIFICANCE")
366 #define PIVOT_RC_PERCENT ("RC_PERCENT")
367 #define PIVOT_RC_RESIDUAL ("RC_RESIDUAL")
368 #define PIVOT_RC_COUNT ("RC_COUNT")
369
370 bool pivot_result_class_change (const char *, const struct fmt_spec *);
371 \f
372 /* A pivot table.  See the top of this file for more information. */
373 struct pivot_table
374   {
375     /* Display settings. */
376     bool rotate_inner_column_labels;
377     bool rotate_outer_row_labels;
378     bool row_labels_in_corner;
379     bool show_grid_lines;
380     bool omit_empty;       /* Omit empty rows and columns? */
381     size_t *current_layer; /* axis[PIVOT_AXIS_LAYER].n_dimensions elements. */
382     char *table_look;
383     enum settings_value_show show_values;
384     enum settings_value_show show_variables;
385     struct fmt_spec weight_format;
386
387     /* Footnote display settings. */
388     bool show_numeric_markers;
389     bool footnote_marker_superscripts;
390
391     /* Column and row sizing and page breaks.
392        sizing[TABLE_HORZ] is for columns, sizing[TABLE_VERT] is for rows. */
393     struct pivot_table_sizing sizing[TABLE_N_AXES];
394
395     /* Print settings. */
396     bool print_all_layers;
397     bool paginate_layers;
398     bool shrink_to_fit[TABLE_N_AXES];
399     bool top_continuation, bottom_continuation;
400     char *continuation;
401     size_t n_orphan_lines;
402
403     /* Format settings. */
404     int epoch;
405     char decimal;               /* Usually ',' or '.'. */
406     char grouping;              /* Usually '.' or ','. */
407     char *ccs[5];               /* Custom currency. */
408     double small;
409
410     /* Command information. */
411     char *command_local;        /* May be NULL. */
412     char *command_c;            /* May be NULL. */
413     char *language;             /* May be NULL. */
414     char *locale;               /* May be NULL. */
415
416     /* Source information. */
417     char *dataset;              /* May be NULL. */
418     char *datafile;             /* May be NULL. */
419     time_t date;                /* May be 0 if unknown. */
420
421     /* Footnotes. */
422     struct pivot_footnote **footnotes;
423     size_t n_footnotes, allocated_footnotes;
424
425     /* Titles. */
426     struct pivot_value *title;
427     struct pivot_value *subtype;  /* Same as pivot_item's subtype. */
428     struct pivot_value *corner_text;
429     struct pivot_value *caption;
430     char *notes;
431
432     /* Styles. */
433     struct area_style areas[PIVOT_N_AREAS];
434     struct table_border_style borders[PIVOT_N_BORDERS];
435
436     /* Dimensions. */
437     struct pivot_dimension **dimensions;
438     size_t n_dimensions;
439
440     /* Allocation of dimensions to rows, columns, and layers. */
441     struct pivot_axis axes[PIVOT_N_AXES];
442
443     struct hmap cells;          /* Contains "struct pivot_cell"s. */
444   };
445
446 /* Creating and destroy pivot tables. */
447 struct pivot_table *pivot_table_create (const char *title);
448 struct pivot_table *pivot_table_create__ (struct pivot_value *title);
449 struct pivot_table *pivot_table_create_for_text (struct pivot_value *title,
450                                                  struct pivot_value *content);
451 void pivot_table_destroy (struct pivot_table *);
452
453 /* Format of PIVOT_RC_COUNT cells. */
454 void pivot_table_set_weight_var (struct pivot_table *,
455                                  const struct variable *);
456 void pivot_table_set_weight_format (struct pivot_table *,
457                                     const struct fmt_spec *);
458
459 /* Query. */
460 bool pivot_table_is_empty (const struct pivot_table *);
461
462 /* Output. */
463 void pivot_table_submit (struct pivot_table *);
464
465 /* Data cells. */
466 void pivot_table_put (struct pivot_table *, const size_t *dindexes, size_t n,
467                       struct pivot_value *);
468 void pivot_table_put1 (struct pivot_table *, size_t idx1,
469                        struct pivot_value *);
470 void pivot_table_put2 (struct pivot_table *, size_t idx1, size_t idx2,
471                        struct pivot_value *);
472 void pivot_table_put3 (struct pivot_table *, size_t idx1, size_t idx2,
473                        size_t idx3, struct pivot_value *);
474 void pivot_table_put4 (struct pivot_table *, size_t idx1, size_t idx2,
475                        size_t idx3, size_t idx4, struct pivot_value *);
476
477 const struct pivot_value *pivot_table_get (const struct pivot_table *,
478                                            const size_t *dindexes);
479
480 struct pivot_value *pivot_table_get_rw (struct pivot_table *,
481                                         const size_t *dindexes);
482
483 /* Footnotes.
484
485    Use pivot_table_create_footnote() to create a footnote.
486    Use pivot_value_add_footnote() to add a reference to a footnote. */
487 struct pivot_footnote
488   {
489     size_t idx;
490     struct pivot_value *content;
491     struct pivot_value *marker;
492   };
493
494 struct pivot_footnote *pivot_table_create_footnote (
495   struct pivot_table *, struct pivot_value *content);
496 struct pivot_footnote *pivot_table_create_footnote__ (
497   struct pivot_table *, size_t idx,
498   struct pivot_value *marker, struct pivot_value *content);
499
500 void pivot_footnote_destroy (struct pivot_footnote *);
501
502 /* Internals. */
503 void pivot_table_convert_indexes_ptod (const struct pivot_table *,
504                                        const size_t *pindexes[PIVOT_N_AXES],
505                                        size_t *dindexes);
506 size_t *pivot_table_enumerate_axis (const struct pivot_table *,
507                                     enum pivot_axis_type,
508                                     const size_t *layer_indexes,
509                                     bool omit_empty, size_t *n);
510 #define PIVOT_ENUMERATION_FOR_EACH(INDEXES, ENUMERATION, AXIS)  \
511   for ((INDEXES) = (ENUMERATION); *(INDEXES) != SIZE_MAX;       \
512        (INDEXES) += MAX (1, (AXIS)->n_dimensions))
513
514 void pivot_table_assign_label_depth (struct pivot_table *);
515
516 void pivot_table_dump (const struct pivot_table *, int indentation);
517 \f
518 /* pivot_value. */
519
520 enum pivot_value_type
521   {
522     PIVOT_VALUE_NUMERIC,          /* A value of a numeric variable. */
523     PIVOT_VALUE_STRING,           /* A value of a string variable. */
524     PIVOT_VALUE_VARIABLE,         /* Name of a variable. */
525     PIVOT_VALUE_TEXT,             /* Text. */
526     PIVOT_VALUE_TEMPLATE,         /* Templated text. */
527   };
528
529 /* A pivot_value is the content of a single pivot table cell.  A pivot_value is
530    also a pivot table's title, caption, footnote marker and contents, and so
531    on.
532
533    A given pivot_value is one of:
534
535    1. A number resulting from a calculation (PIVOT_VALUE_NUMERIC).  Use
536       pivot_value_new_number() to create such a pivot_value.
537
538       A numeric pivot_value has an associated display format (usually an F or
539       PCT format).  This format can be set directly on the pivot_value, but
540       that is not usually the easiest way.  Instead, it is usually true that
541       all of the values in a single category should have the same format
542       (e.g. all "Significance" values might use format F40.3), so PSPP makes
543       it easy to set the default format for a category while creating the
544       category.  See pivot_dimension_create() for more details.
545
546       For numbers that should be displayed as integers,
547       pivot_value_new_integer() can occasionally be a useful special case.
548
549    2. A numeric or string value obtained from data (PIVOT_VALUE_NUMERIC or
550       PIVOT_VALUE_STRING).  If such a value corresponds to a variable, then the
551       variable's name can be attached to the pivot_value.  If the value has a
552       value label, then that can also be attached.  When a label is present,
553       the user can control whether to show the value or the label or both.
554
555       Use pivot_value_new_var_value() to create pivot_values of these kinds.
556
557    3. A variable name (PIVOT_VALUE_VARIABLE).  The variable label, if any, can
558       be attached too, and again the user can control whether to show the value
559       or the label or both.
560
561    4. A text string (PIVOT_VALUE_TEXT).  The value stores the string in English
562       and translated into the output language (localized).  Use
563       pivot_value_new_text() or pivot_value_new_text_format() for those cases.
564       In some cases, only an English or a localized version is available for
565       one reason or another, although this is regrettable; in those cases, use
566       pivot_value_new_user_text() or pivot_value_new_user_text_nocopy().
567
568    (There is also a PIVOT_VALUE_TEMPLATE but PSPP does not yet create these
569    itself.)
570
571
572    Footnotes
573    =========
574
575    A pivot_value may reference any number of footnotes.  Use
576    pivot_value_add_footnote() to add a footnote reference.  The footnotes being
577    referenced must first be created with pivot_table_create_footnote().
578
579
580    Styling
581    =======
582
583    A pivot_value can have specific font and cell styles.  Only the user should
584    add these.
585 */
586 struct pivot_value
587   {
588     struct font_style *font_style;
589     struct cell_style *cell_style;
590     char *subscript;
591     char *superscript;
592
593     struct pivot_footnote **footnotes;
594     size_t n_footnotes;
595
596     enum pivot_value_type type;
597     union
598       {
599         /* PIVOT_VALUE_NUMERIC. */
600         struct
601           {
602             double x;                 /* The numeric value. */
603             struct fmt_spec format;   /* Format to display 'x'. */
604             char *var_name;           /* May be NULL. */
605             char *value_label;        /* May be NULL. */
606             enum settings_value_show show; /* Show value or label or both? */
607           }
608         numeric;
609
610         /* PIVOT_VALUE_STRING. */
611         struct
612           {
613             char *s;                  /* The string value. */
614             bool hex;                 /* Display in hex? */
615             char *var_name;           /* May be NULL. */
616             char *value_label;        /* May be NULL. */
617             enum settings_value_show show; /* Show value or label or both? */
618           }
619         string;
620
621         /* PIVOT_VALUE_VARIABLE. */
622         struct
623           {
624             char *var_name;
625             char *var_label;          /* May be NULL. */
626             enum settings_value_show show; /* Show name or label or both? */
627           }
628         variable;
629
630         /* PIVOT_VALUE_TEXT. */
631         struct
632           {
633             char *local;              /* Localized. */
634             char *c;                  /* English. */
635             char *id;                 /* Identifier. */
636             bool user_provided;
637           }
638         text;
639
640         /* PIVOT_VALUE_TEMPLATE. */
641         struct
642           {
643             char *s;
644             struct pivot_argument *args;
645             size_t n_args;
646           }
647         template;
648       };
649   };
650
651 /* Numbers resulting from calculations. */
652 struct pivot_value *pivot_value_new_number (double);
653 struct pivot_value *pivot_value_new_integer (double);
654
655 /* Values from data. */
656 struct pivot_value *pivot_value_new_var_value (
657   const struct variable *, const union value *);
658 struct pivot_value *pivot_value_new_value (const union value *, int width,
659                                            const struct fmt_spec *,
660                                            const char *encoding);
661
662 /* Values from variable names. */
663 struct pivot_value *pivot_value_new_variable (const struct variable *);
664
665 /* Values from text strings. */
666 struct pivot_value *pivot_value_new_text (const char *);
667 struct pivot_value *pivot_value_new_text_format (const char *, ...)
668   PRINTF_FORMAT (1, 2);
669
670 struct pivot_value *pivot_value_new_user_text (const char *, size_t length);
671 struct pivot_value *pivot_value_new_user_text_nocopy (char *);
672
673 /* Footnotes. */
674 void pivot_value_add_footnote (struct pivot_value *, struct pivot_footnote *);
675
676 /* Numeric formats. */
677 void pivot_value_set_rc (struct pivot_table *, struct pivot_value *,
678                          const char *rc);
679
680 /* Converting a pivot_value to a string for display. */
681 char *pivot_value_to_string (const struct pivot_value *,
682                              enum settings_value_show show_values,
683                              enum settings_value_show show_variables);
684 void pivot_value_format (const struct pivot_value *,
685                          enum settings_value_show show_values,
686                          enum settings_value_show show_variables,
687                          struct string *);
688 bool pivot_value_format_body (const struct pivot_value *,
689                               enum settings_value_show show_values,
690                               enum settings_value_show show_variables,
691                               struct string *);
692
693 void pivot_value_destroy (struct pivot_value *);
694
695 /* Styling. */
696 void pivot_value_get_style (struct pivot_value *,
697                             const struct area_style *default_style,
698                             struct area_style *);
699 void pivot_value_set_style (struct pivot_value *, const struct area_style *);
700
701 /* Template arguments. */
702 struct pivot_argument
703   {
704     size_t n;
705     struct pivot_value **values;
706   };
707
708 void pivot_argument_uninit (struct pivot_argument *);
709
710 #endif /* output/pivot-table.h */