1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2017-2018 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_PIVOT_TABLE_H
18 #define OUTPUT_PIVOT_TABLE_H 1
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"
36 Pivot tables are PSPP's primary form of output. They are analogous to the
37 pivot tables you might be familiar with from spreadsheets and databases.
38 See https://en.wikipedia.org/wiki/Pivot_table for a brief introduction to
39 the overall concept of a pivot table.
41 In PSPP, the most important internal pieces of a pivot table are:
43 - Title. Every pivot table has a title that is displayed above it. It also
44 has an optional caption (displayed below it) and corner text (displayed in
45 the upper left corner).
47 - Dimensions. A dimension consists of zero or more categories. A category
48 has a label, such as "df" or "Asymp. Sig." or 123 or a variable name. The
49 categories are the leaves of a tree whose non-leaf nodes form groups of
50 categories. The tree always has a root group whose label is the name of
53 - Axes. A table has three axes: column, row, and layer. Each dimension is
54 assigned to an axis, and each axis has zero or more dimensions. When an
55 axis has more than one dimension, they are ordered from innermost to
58 - Data. A table's data consists of zero or more cells. Each cell maps from
59 a category for each dimension to a value, which is commonly a number but
60 could also be a variable name or an arbitrary text string.
62 Creating a pivot table usually consists of the following steps:
64 1. Create the table with pivot_table_create(), passing in the title.
66 2. Optionally, set the format to use for "count" values with
67 pivot_table_set_weight_var() or pivot_table_set_weight_format().
69 3. Create each dimension with pivot_dimension_create() and populate it with
70 categories and, possibly, with groups that contain the categories. This
71 call also assigns the dimension to an axis.
73 In simple cases, only a call to pivot_dimension_create() is needed.
74 Other functions such as pivot_category_create_group() can be used for
75 hierarchies of categories.
77 Sometimes it's easier to create categories in tandem with inserting data,
78 for example by adding a category for a variable just before inserting the
79 first cell for that variable. In that case, creating categories and
80 inserting data can be interleaved.
82 4. Insert data. For each cell, supply the category indexes, which are
83 assigned starting from 0 in the order in which the categories were
84 created in step 2, and the value to go in the cell. If the table has a
85 small, fixed number of dimensions, functions like, e.g.
86 pivot_table_put3() for 3 dimensions, can be used. The general function
87 pivot_table_put() works for other cases.
89 5. Output the table for user consumption. Use pivot_table_submit(). */
91 /* Pivot table display styling. */
93 /* Areas of a pivot table for styling purposes. */
98 PIVOT_AREA_FOOTER, /* Footnotes. */
99 PIVOT_AREA_CORNER, /* Top-left corner. */
100 PIVOT_AREA_COLUMN_LABELS,
101 PIVOT_AREA_ROW_LABELS,
103 PIVOT_AREA_LAYERS, /* Layer indication. */
107 const char *pivot_area_to_string (enum pivot_area);
109 /* Table borders for styling purposes. */
115 PIVOT_BORDER_OUTER_LEFT,
116 PIVOT_BORDER_OUTER_TOP,
117 PIVOT_BORDER_OUTER_RIGHT,
118 PIVOT_BORDER_OUTER_BOTTOM,
121 PIVOT_BORDER_INNER_LEFT,
122 PIVOT_BORDER_INNER_TOP,
123 PIVOT_BORDER_INNER_RIGHT,
124 PIVOT_BORDER_INNER_BOTTOM,
127 PIVOT_BORDER_DATA_LEFT,
128 PIVOT_BORDER_DATA_TOP,
131 PIVOT_BORDER_DIM_ROW_HORZ,
132 PIVOT_BORDER_DIM_ROW_VERT,
133 PIVOT_BORDER_DIM_COL_HORZ,
134 PIVOT_BORDER_DIM_COL_VERT,
137 PIVOT_BORDER_CAT_ROW_HORZ,
138 PIVOT_BORDER_CAT_ROW_VERT,
139 PIVOT_BORDER_CAT_COL_HORZ,
140 PIVOT_BORDER_CAT_COL_VERT,
145 const char *pivot_border_to_string (enum pivot_border);
147 /* Sizing for rows or columns of a rendered table. The comments below talk
148 about columns and their widths but they apply equally to rows and their
150 struct pivot_table_sizing
152 /* Specific column widths, in 1/96" units. */
156 /* Specific page breaks: 0-based columns after which a page break must
157 occur, e.g. a value of 1 requests a break after the second column. */
161 /* Keeps: columns to keep together on a page if possible. */
162 struct pivot_keep *keeps;
166 void pivot_table_sizing_uninit (struct pivot_table_sizing *);
168 /* A set of columns to keep together on a page if possible, e.g. ofs=1, n=10
169 requests keeping together the 2nd through 11th columns. */
172 size_t ofs; /* 0-based first column. */
173 size_t n; /* Number of columns. */
183 #define PIVOT_N_AXES 3
186 const char *pivot_axis_type_to_string (enum pivot_axis_type);
188 /* An axis within a pivot table. */
191 /* dimensions[0] is the innermost dimension,
192 dimensions[1] is the next outer dimension,
194 dimensions[n_dimensions - 1] is the outermost dimension. */
195 struct pivot_dimension **dimensions;
198 /* The number of rows or columns along the axis,
199 that is, the product of dimension[*]->n_leaves.
200 It is 0 if any dimension has 0 leaves. */
203 /* Sum of dimensions[*]->label_depth. */
207 /* Successively assigns to INDEXES (which should be a "size_t *") each of the
208 combinations of the categories in AXIS's dimensions, in lexicographic order
209 with the innermost dimension iterating most quickly.
211 The value assigned to INDEXES is dynamically allocated. If the client
212 breaks out of the loop prematurely, it needs to free it with free(). */
213 #define PIVOT_AXIS_FOR_EACH(INDEXES, AXIS) \
214 for ((INDEXES) = NULL; \
215 ((INDEXES) = pivot_axis_iterator_next (INDEXES, AXIS)) != NULL;)
216 size_t *pivot_axis_iterator_next (size_t *indexes, const struct pivot_axis *);
220 A pivot_dimension identifies the categories associated with a single
221 dimension within a multidimensional pivot table.
223 A dimension contains a collection of categories, which are the leaves in a
226 (A dimension or a group can contain zero categories, but this is unusual.
227 If a dimension contains no categories, then its table cannot contain any
230 struct pivot_dimension
232 /* table->axes[axis_type]->dimensions[level] == dimension. */
233 struct pivot_table *table;
234 enum pivot_axis_type axis_type;
235 size_t level; /* 0 for innermost dimension within axis. */
237 /* table->dimensions[top_index] == dimension. */
240 /* Hierarchy of categories within the dimension. The groups and categories
241 are sorted in the order that should be used for display. This might be
242 different from the original order produced for output if the user
245 The root must always be a group, although it is allowed to have no
247 struct pivot_category *root;
249 /* All of the leaves reachable via the root.
251 The indexing for presentation_leaves is presentation order, thus
252 presentation_leaves[i]->presentation_index == i. This order is the same
253 as would be produced by an in-order traversal of the groups. It is the
254 order into which the user reordered or sorted the categories.
256 The indexing for data_leaves is that used for idx[] in struct
257 pivot_cell, thus data_leaves[i]->data_index == i. This might differ
258 from what an in-order traversal of 'root' would yield, if the user
259 reordered categories. */
260 struct pivot_category **data_leaves;
261 struct pivot_category **presentation_leaves;
262 size_t n_leaves, allocated_leaves;
265 bool hide_all_labels;
267 /* Number of rows or columns needed to express the labels. */
271 struct pivot_dimension *pivot_dimension_create (
272 struct pivot_table *, enum pivot_axis_type, const char *name, ...)
274 #define pivot_dimension_create(...) \
275 pivot_dimension_create(__VA_ARGS__, NULL_SENTINEL)
276 struct pivot_dimension *pivot_dimension_create__ (struct pivot_table *,
277 enum pivot_axis_type,
278 struct pivot_value *name);
280 void pivot_dimension_destroy (struct pivot_dimension *);
282 void pivot_dimension_dump (const struct pivot_dimension *,
283 const struct pivot_table *, int indentation);
285 struct pivot_splits *pivot_splits_create (struct pivot_table *,
286 enum pivot_axis_type,
287 const struct dictionary *);
288 void pivot_splits_destroy (struct pivot_splits *);
290 void pivot_splits_new_split (struct pivot_splits *, const struct ccase *);
291 size_t pivot_splits_get_dindexes (const struct pivot_splits *,
294 void pivot_splits_put1 (struct pivot_splits *, struct pivot_table *,
295 size_t idx1, struct pivot_value *);
296 void pivot_splits_put2 (struct pivot_splits *, struct pivot_table *,
297 size_t idx1, size_t idx2, struct pivot_value *);
298 void pivot_splits_put3 (struct pivot_splits *, struct pivot_table *,
299 size_t idx1, size_t idx2, size_t idx3,
300 struct pivot_value *);
301 void pivot_splits_put4 (struct pivot_splits *, struct pivot_table *,
302 size_t idx1, size_t idx2, size_t idx3, size_t idx4,
303 struct pivot_value *);
305 size_t pivot_splits_count (const struct pivot_splits *);
307 /* A pivot_category is a leaf (a category) or a group:
309 - For a leaf, neither index is SIZE_MAX.
311 - For a group, both indexes are SIZE_MAX.
313 Do not use 'subs' or 'n_subs' to determine whether a category is a group,
314 because a group may (pathologically) have no leaves. */
315 struct pivot_category
317 struct pivot_value *name;
318 struct pivot_category *parent;
319 struct pivot_dimension *dimension;
320 size_t label_depth, extra_depth;
324 If show_label is true, then the group itself has a row (or a column)
325 giving the group's name. Otherwise, the group's own name is not
327 struct pivot_category **subs; /* Child categories or groups. */
328 size_t n_subs, allocated_subs;
329 bool show_label; /* Display a label for the group itself? */
330 bool show_label_in_corner;
333 size_t group_index; /* In ->parent->subs[]. */
334 size_t data_index; /* In ->dimension->data_leaves[]. */
335 size_t presentation_index; /* In ->dimension->presentation_leaves[]. */
336 struct fmt_spec format; /* Default format for values in this category. */
337 bool honor_small; /* Honor pivot_table 'small' setting? */
341 pivot_category_is_group (const struct pivot_category *category)
343 return category->data_index == SIZE_MAX;
347 pivot_category_is_leaf (const struct pivot_category *category)
349 return !pivot_category_is_group (category);
352 /* Creating leaf categories. */
353 int pivot_category_create_leaves (struct pivot_category *parent, ...)
355 #define pivot_category_create_leaves(...) \
356 pivot_category_create_leaves(__VA_ARGS__, NULL_SENTINEL)
358 int pivot_category_create_leaf (
359 struct pivot_category *parent, struct pivot_value *name);
360 int pivot_category_create_leaf_rc (
361 struct pivot_category *parent, struct pivot_value *name, const char *rc);
363 /* Creating category groups. */
364 struct pivot_category *pivot_category_create_group (
365 struct pivot_category *parent, const char *name, ...) SENTINEL (0);
366 #define pivot_category_create_group(...) \
367 pivot_category_create_group(__VA_ARGS__, NULL_SENTINEL)
368 struct pivot_category *pivot_category_create_group__ (
369 struct pivot_category *parent, struct pivot_value *name);
371 void pivot_category_destroy (struct pivot_category *);
373 /* Pivot result classes.
375 These are used to mark leaf categories as having particular types of data,
376 to set their numeric formats. The formats that actually get used for these
377 classes are in the result_classes[] global array in pivot-table.c, except
378 that PIVOT_RC_OTHER comes from settings_get_format() and PIVOT_RC_COUNT
379 should come from the weight variable in the dataset's dictionary. */
380 #define PIVOT_RC_OTHER ("RC_OTHER")
381 #define PIVOT_RC_INTEGER ("RC_INTEGER")
382 #define PIVOT_RC_CORRELATION ("RC_CORRELATIONS")
383 #define PIVOT_RC_SIGNIFICANCE ("RC_SIGNIFICANCE")
384 #define PIVOT_RC_PERCENT ("RC_PERCENT")
385 #define PIVOT_RC_RESIDUAL ("RC_RESIDUAL")
386 #define PIVOT_RC_COUNT ("RC_COUNT")
388 bool pivot_result_class_change (const char *, const struct fmt_spec *);
389 bool is_pivot_result_class (const char *);
391 /* Styling for a pivot table.
393 The division between this and the style information in struct pivot_table
394 seems fairly arbitrary. The ultimate reason for the division is simply
395 because that's how SPSS documentation and file formats do it. */
396 struct pivot_table_look
398 /* Reference count. A pivot_table_look may be shared between multiple
399 owners, indicated by a reference count greater than 1. When this is the
400 case, the pivot_table must not be modified. */
403 char *name; /* May be null. */
405 /* General properties. */
407 bool row_labels_in_corner;
408 int width_ranges[TABLE_N_AXES][2]; /* In 1/96" units. */
410 /* Footnote display settings. */
411 bool show_numeric_markers;
412 bool footnote_marker_superscripts;
415 struct table_area_style areas[PIVOT_N_AREAS];
416 struct table_border_style borders[PIVOT_N_BORDERS];
418 /* Print settings. */
419 bool print_all_layers;
420 bool paginate_layers;
421 bool shrink_to_fit[TABLE_N_AXES];
422 bool top_continuation, bottom_continuation;
424 size_t n_orphan_lines;
427 const struct pivot_table_look *pivot_table_look_get_default (void);
428 void pivot_table_look_set_default (const struct pivot_table_look *);
430 char *pivot_table_look_read (const char *, struct pivot_table_look **)
433 const struct pivot_table_look *pivot_table_look_builtin_default (void);
434 struct pivot_table_look *pivot_table_look_new_builtin_default (void);
435 struct pivot_table_look *pivot_table_look_ref (
436 const struct pivot_table_look *);
437 void pivot_table_look_unref (struct pivot_table_look *);
438 struct pivot_table_look *pivot_table_look_unshare (struct pivot_table_look *);
440 /* A pivot table. See the top of this file for more information. */
443 /* Reference count. A pivot_table may be shared between multiple owners,
444 indicated by a reference count greater than 1. When this is the case,
445 the pivot_table must not be modified. */
449 struct pivot_table_look *look;
451 /* Display settings. */
452 bool rotate_inner_column_labels;
453 bool rotate_outer_row_labels;
454 bool show_grid_lines;
457 size_t *current_layer; /* axes[PIVOT_AXIS_LAYER].n_dimensions elements. */
458 enum settings_value_show show_values;
459 enum settings_value_show show_variables;
460 struct fmt_spec weight_format;
462 /* Column and row sizing and page breaks.
463 sizing[TABLE_HORZ] is for columns, sizing[TABLE_VERT] is for rows. */
464 struct pivot_table_sizing sizing[TABLE_N_AXES];
466 /* Format settings. */
467 struct fmt_settings settings;
468 char grouping; /* Usually '.' or ','. */
471 /* Command information. */
472 char *command_local; /* May be NULL. */
473 char *command_c; /* May be NULL. */
474 char *language; /* May be NULL. */
475 char *locale; /* May be NULL. */
477 /* Source information. */
478 char *dataset; /* May be NULL. */
479 char *datafile; /* May be NULL. */
480 time_t date; /* May be 0 if unknown. */
483 struct pivot_footnote **footnotes;
484 size_t n_footnotes, allocated_footnotes;
487 struct pivot_value *title;
488 struct pivot_value *subtype; /* Same as spv_item's subtype. */
489 struct pivot_value *corner_text;
490 struct pivot_value *caption;
491 char *notes; /* Shown as tooltip. */
494 struct pivot_dimension **dimensions;
497 /* Allocation of dimensions to rows, columns, and layers. */
498 struct pivot_axis axes[PIVOT_N_AXES];
500 struct hmap cells; /* Contains "struct pivot_cell"s. */
503 /* Creating and destroy pivot tables. */
504 struct pivot_table *pivot_table_create (const char *title);
505 struct pivot_table *pivot_table_create__ (struct pivot_value *title,
506 const char *subtype);
507 struct pivot_table *pivot_table_create_for_text (struct pivot_value *title,
508 struct pivot_value *content);
510 struct pivot_table *pivot_table_ref (const struct pivot_table *);
511 struct pivot_table *pivot_table_unshare (struct pivot_table *);
512 void pivot_table_unref (struct pivot_table *);
513 bool pivot_table_is_shared (const struct pivot_table *);
516 void pivot_table_set_title (struct pivot_table *, struct pivot_value *);
517 void pivot_table_set_subtype (struct pivot_table *, struct pivot_value *);
518 void pivot_table_set_corner_text (struct pivot_table *, struct pivot_value *);
519 void pivot_table_set_caption (struct pivot_table *, struct pivot_value *);
522 void pivot_table_swap_axes (struct pivot_table *,
523 enum pivot_axis_type, enum pivot_axis_type);
524 void pivot_table_transpose (struct pivot_table *);
525 void pivot_table_move_dimension (struct pivot_table *,
526 struct pivot_dimension *,
527 enum pivot_axis_type, size_t ofs);
530 const struct pivot_table_look *pivot_table_get_look (
531 const struct pivot_table *);
532 void pivot_table_set_look (struct pivot_table *,
533 const struct pivot_table_look *);
535 /* Format of PIVOT_RC_COUNT cells. */
536 void pivot_table_set_weight_var (struct pivot_table *,
537 const struct variable *);
538 void pivot_table_set_weight_format (struct pivot_table *,
539 const struct fmt_spec *);
542 bool pivot_table_is_empty (const struct pivot_table *);
545 void pivot_table_submit (struct pivot_table *);
548 void pivot_table_put (struct pivot_table *, const size_t *dindexes, size_t n,
549 struct pivot_value *);
550 void pivot_table_put1 (struct pivot_table *, size_t idx1,
551 struct pivot_value *);
552 void pivot_table_put2 (struct pivot_table *, size_t idx1, size_t idx2,
553 struct pivot_value *);
554 void pivot_table_put3 (struct pivot_table *, size_t idx1, size_t idx2,
555 size_t idx3, struct pivot_value *);
556 void pivot_table_put4 (struct pivot_table *, size_t idx1, size_t idx2,
557 size_t idx3, size_t idx4, struct pivot_value *);
559 const struct pivot_value *pivot_table_get (const struct pivot_table *,
560 const size_t *dindexes);
562 struct pivot_value *pivot_table_get_rw (struct pivot_table *,
563 const size_t *dindexes);
565 bool pivot_table_delete (struct pivot_table *, const size_t *dindexes);
569 Use pivot_table_create_footnote() to create a footnote.
570 Use pivot_value_add_footnote() to add a reference to a footnote. */
571 struct pivot_footnote
574 struct pivot_value *content;
575 struct pivot_value *marker;
579 struct pivot_footnote *pivot_table_create_footnote (
580 struct pivot_table *, struct pivot_value *content);
581 struct pivot_footnote *pivot_table_create_footnote__ (
582 struct pivot_table *, size_t idx,
583 struct pivot_value *marker, struct pivot_value *content);
585 void pivot_footnote_format_marker (const struct pivot_footnote *,
586 const struct pivot_table *,
588 char *pivot_footnote_marker_string (const struct pivot_footnote *,
589 const struct pivot_table *);
591 void pivot_footnote_destroy (struct pivot_footnote *);
594 void pivot_table_convert_indexes_ptod (const struct pivot_table *,
595 const size_t *pindexes[PIVOT_N_AXES],
597 size_t *pivot_table_enumerate_axis (const struct pivot_table *,
598 enum pivot_axis_type,
599 const size_t *layer_indexes,
600 bool omit_empty, size_t *n);
601 #define PIVOT_ENUMERATION_FOR_EACH(INDEXES, ENUMERATION, AXIS) \
602 for ((INDEXES) = (ENUMERATION); *(INDEXES) != SIZE_MAX; \
603 (INDEXES) += MAX (1, (AXIS)->n_dimensions))
605 void pivot_table_assign_label_depth (struct pivot_table *);
607 void pivot_table_dump (const struct pivot_table *, int indentation);
611 enum ATTRIBUTE ((packed)) pivot_value_type
613 PIVOT_VALUE_NUMERIC, /* A value of a numeric variable. */
614 PIVOT_VALUE_STRING, /* A value of a string variable. */
615 PIVOT_VALUE_VARIABLE, /* Name of a variable. */
616 PIVOT_VALUE_TEXT, /* Text. */
617 PIVOT_VALUE_TEMPLATE, /* Templated text. */
620 /* A pivot_value is the content of a single pivot table cell. A pivot_value is
621 also a pivot table's title, caption, footnote marker and contents, and so
624 A given pivot_value is one of:
626 1. A number resulting from a calculation (PIVOT_VALUE_NUMERIC). Use
627 pivot_value_new_number() to create such a pivot_value.
629 A numeric pivot_value has an associated display format (usually an F or
630 PCT format). This format can be set directly on the pivot_value, but
631 that is not usually the easiest way. Instead, it is usually true that
632 all of the values in a single category should have the same format
633 (e.g. all "Significance" values might use format F40.3), so PSPP makes
634 it easy to set the default format for a category while creating the
635 category. See pivot_dimension_create() for more details.
637 For numbers that should be displayed as integers,
638 pivot_value_new_integer() can occasionally be a useful special case.
640 2. A numeric or string value obtained from data (PIVOT_VALUE_NUMERIC or
641 PIVOT_VALUE_STRING). If such a value corresponds to a variable, then the
642 variable's name can be attached to the pivot_value. If the value has a
643 value label, then that can also be attached. When a label is present,
644 the user can control whether to show the value or the label or both.
646 Use pivot_value_new_var_value() to create pivot_values of these kinds.
648 3. A variable name (PIVOT_VALUE_VARIABLE). The variable label, if any, can
649 be attached too, and again the user can control whether to show the value
650 or the label or both.
652 4. A text string (PIVOT_VALUE_TEXT). The value stores the string in English
653 and translated into the output language (localized). Use
654 pivot_value_new_text() or pivot_value_new_text_format() for those cases.
655 In some cases, only an English or a localized version is available for
656 one reason or another, although this is regrettable; in those cases, use
657 pivot_value_new_user_text() or pivot_value_new_user_text_nocopy().
659 (There is also a PIVOT_VALUE_TEMPLATE but PSPP does not yet create these
666 A pivot_value may reference any number of footnotes. Use
667 pivot_value_add_footnote() to add a footnote reference. The footnotes being
668 referenced must first be created with pivot_table_create_footnote().
674 A pivot_value can have specific font and cell styles. Only the user should
679 struct pivot_value_ex *ex;
682 enum pivot_value_type type;
684 /* PIVOT_VALUE_NUMERIC. */
687 enum pivot_value_type type;
688 enum settings_value_show show; /* Show value or label or both? */
689 struct fmt_spec format; /* Format to display 'x'. */
690 bool honor_small; /* Honor value of pivot table 'small'? */
691 double x; /* The numeric value. */
692 char *var_name; /* May be NULL. */
693 char *value_label; /* May be NULL. */
697 /* PIVOT_VALUE_STRING. */
700 enum pivot_value_type type;
701 enum settings_value_show show; /* Show value or label or both? */
702 bool hex; /* Display in hex? */
703 char *s; /* The string value. */
704 char *var_name; /* May be NULL. */
705 char *value_label; /* May be NULL. */
709 /* PIVOT_VALUE_VARIABLE. */
712 enum pivot_value_type type;
713 enum settings_value_show show; /* Show name or label or both? */
715 char *var_label; /* May be NULL. */
719 /* PIVOT_VALUE_TEXT. */
722 enum pivot_value_type type;
724 /* 'local', 'c', and 'id' must all be nonnull, but they are allowed
725 to be the same pointer. */
727 char *local; /* Localized. */
728 char *c; /* English. */
729 char *id; /* Identifier. */
733 /* PIVOT_VALUE_TEMPLATE. */
736 enum pivot_value_type type;
740 The odd ordering in this struct reduces the overall size
741 of struct pivot_value. */
743 struct pivot_argument *args;
745 /* Both 'local' and 'id' must be nonnull, but they are allowed to
746 be the same pointer. */
747 char *local; /* Localized. */
748 char *id; /* Identifier. */
755 struct pivot_value *pivot_value_clone (const struct pivot_value *);
756 void pivot_value_destroy (struct pivot_value *);
758 /* Numbers resulting from calculations. */
759 struct pivot_value *pivot_value_new_number (double);
760 struct pivot_value *pivot_value_new_integer (double);
762 /* Values from data. */
763 struct pivot_value *pivot_value_new_var_value (
764 const struct variable *, const union value *);
765 struct pivot_value *pivot_value_new_value (const union value *, int width,
766 const struct fmt_spec *,
767 const char *encoding);
769 /* Values from variable names. */
770 struct pivot_value *pivot_value_new_variable (const struct variable *);
771 struct pivot_value *pivot_value_new_variable__ (const char *name,
774 /* Values from text strings. */
775 struct pivot_value *pivot_value_new_text (const char *);
776 struct pivot_value *pivot_value_new_text_format (const char *, ...)
777 #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__>= 4) || __GNUC__ > 4)
778 __attribute__((format(gnu_printf, 1, 2)));
780 __attribute__((format(__printf__, 1, 2)));
783 struct pivot_value *pivot_value_new_user_text (const char *, size_t length);
784 struct pivot_value *pivot_value_new_user_text_nocopy (char *);
787 void pivot_value_add_footnote (struct pivot_value *, const struct pivot_footnote *);
788 void pivot_value_sort_footnotes (struct pivot_value *);
790 /* Numeric formats. */
791 void pivot_value_set_rc (const struct pivot_table *, struct pivot_value *,
794 /* Converting a pivot_value to a string for display. */
795 char *pivot_value_to_string (const struct pivot_value *,
796 const struct pivot_table *);
797 char *pivot_value_to_string_defaults (const struct pivot_value *);
798 bool pivot_value_format (const struct pivot_value *,
799 const struct pivot_table *, struct string *);
800 bool pivot_value_format_body (const struct pivot_value *,
801 const struct pivot_table *,
805 void pivot_value_get_style (struct pivot_value *,
806 const struct font_style *base_font_style,
807 const struct cell_style *base_cell_style,
808 struct table_area_style *);
809 void pivot_value_set_style (struct pivot_value *,
810 const struct table_area_style *);
811 void pivot_value_set_font_style (struct pivot_value *,
812 const struct font_style *);
813 void pivot_value_set_cell_style (struct pivot_value *,
814 const struct cell_style *);
816 /* Template arguments. */
817 struct pivot_argument
820 struct pivot_value **values;
823 void pivot_argument_uninit (struct pivot_argument *);
824 void pivot_argument_copy (struct pivot_argument *,
825 const struct pivot_argument *);
827 /* Extra styling for a pivot_value.
829 This is logically part of pivot_value itself. It is broken into a separate
830 structure to save memory because it is rarely used. */
831 struct pivot_value_ex
833 struct font_style *font_style;
834 struct cell_style *cell_style;
839 size_t *footnote_indexes;
843 static inline const struct pivot_value_ex *
844 pivot_value_ex (const struct pivot_value *value)
846 static const struct pivot_value_ex empty_ex = { .font_style = NULL };
847 return value->ex ? value->ex : &empty_ex;
850 struct pivot_value_ex *pivot_value_ex_rw (struct pivot_value *);
851 struct pivot_value_ex *pivot_value_ex_clone (const struct pivot_value_ex *);
852 void pivot_value_ex_destroy (struct pivot_value_ex *);
854 /* One piece of data within a pivot table. */
857 struct hmap_node hmap_node; /* In struct pivot_table's 'cells' hmap. */
858 struct pivot_value *value;
859 unsigned int idx[]; /* One index per table dimension. */
862 #endif /* output/pivot-table.h */