output: Make table_item a pivot_table, table_cell a pivot_value.
[pspp] / src / output / pivot-table.h
index cc61377fc29818160b438e8866ca001873d51af0..e2bb886c30dc891d65c266d2aac7cdd3e6160fcf 100644 (file)
@@ -60,15 +60,11 @@ union value;
    Creating a pivot table usually consists of the following steps:
 
    1. Create the table with pivot_table_create(), passing in the title.
-      It's commonly useful to set up a few options at this point:
 
-      - If empty rows or columns should not be displayed, set ->omit_empty to
-        true.
+   2. Optionally, set the format to use for "count" values with
+      pivot_table_set_weight_var() or pivot_table_set_weight_format().
 
-      - Set the format to use for "count" values with
-        pivot_table_set_weight_var() or pivot_table_set_weight_format().
-
-   2. Create each dimension with pivot_dimension_create() and populate it with
+   3. Create each dimension with pivot_dimension_create() and populate it with
       categories and, possibly, with groups that contain the categories.  This
       call also assigns the dimension to an axis.
 
@@ -81,14 +77,14 @@ union value;
       first cell for that variable.  In that case, creating categories and
       inserting data can be interleaved.
 
-   3. Insert data.  For each cell, supply the category indexes, which are
+   4. Insert data.  For each cell, supply the category indexes, which are
       assigned starting from 0 in the order in which the categories were
       created in step 2, and the value to go in the cell.  If the table has a
       small, fixed number of dimensions, functions like, e.g.
       pivot_table_put3() for 3 dimensions, can be used.  The general function
       pivot_table_put() works for other cases.
 
-   4. Output the table for user consumption.  Use pivot_table_submit(). */
+   5. Output the table for user consumption.  Use pivot_table_submit(). */
 \f
 /* Pivot table display styling. */
 
@@ -107,7 +103,6 @@ enum pivot_area
   };
 
 const char *pivot_area_to_string (enum pivot_area);
-const struct table_area_style *pivot_area_get_default_style (enum pivot_area);
 
 /* Table borders for styling purposes. */
 enum pivot_border
@@ -146,8 +141,6 @@ enum pivot_border
   };
 
 const char *pivot_border_to_string (enum pivot_border);
-void pivot_border_get_default_style (enum pivot_border,
-                                     struct table_border_style *);
 
 /* Sizing for rows or columns of a rendered table.  The comments below talk
    about columns and their widths but they apply equally to rows and their
@@ -368,6 +361,7 @@ void pivot_category_destroy (struct pivot_category *);
 #define PIVOT_RC_COUNT ("RC_COUNT")
 
 bool pivot_result_class_change (const char *, const struct fmt_spec *);
+bool is_pivot_result_class (const char *);
 \f
 /* Styling for a pivot table.
 
@@ -376,6 +370,11 @@ bool pivot_result_class_change (const char *, const struct fmt_spec *);
    because that's how SPSS documentation and file formats do it. */
 struct pivot_table_look
   {
+    /* Reference count.  A pivot_table_look may be shared between multiple
+       owners, indicated by a reference count greater than 1.  When this is the
+       case, the pivot_table must not be modified. */
+    int ref_cnt;
+
     char *name;                 /* May be null. */
 
     /* General properties. */
@@ -400,10 +399,18 @@ struct pivot_table_look
     size_t n_orphan_lines;
   };
 
-void pivot_table_look_init (struct pivot_table_look *);
-void pivot_table_look_uninit (struct pivot_table_look *);
-void pivot_table_look_copy (struct pivot_table_look *,
-                            const struct pivot_table_look *);
+const struct pivot_table_look *pivot_table_look_get_default (void);
+void pivot_table_look_set_default (const struct pivot_table_look *);
+
+char *pivot_table_look_read (const char *, struct pivot_table_look **)
+  WARN_UNUSED_RESULT;
+
+const struct pivot_table_look *pivot_table_look_builtin_default (void);
+struct pivot_table_look *pivot_table_look_new_builtin_default (void);
+struct pivot_table_look *pivot_table_look_ref (
+  const struct pivot_table_look *);
+void pivot_table_look_unref (struct pivot_table_look *);
+struct pivot_table_look *pivot_table_look_unshare (struct pivot_table_look *);
 \f
 /* A pivot table.  See the top of this file for more information. */
 struct pivot_table
@@ -414,14 +421,15 @@ struct pivot_table
     int ref_cnt;
 
     /* Styling. */
-    struct pivot_table_look look;
+    struct pivot_table_look *look;
 
     /* Display settings. */
     bool rotate_inner_column_labels;
     bool rotate_outer_row_labels;
     bool show_grid_lines;
+    bool show_title;
     bool show_caption;
-    size_t *current_layer; /* axis[PIVOT_AXIS_LAYER].n_dimensions elements. */
+    size_t *current_layer; /* axes[PIVOT_AXIS_LAYER].n_dimensions elements. */
     enum settings_value_show show_values;
     enum settings_value_show show_variables;
     struct fmt_spec weight_format;
@@ -457,7 +465,7 @@ struct pivot_table
     struct pivot_value *subtype;  /* Same as spv_item's subtype. */
     struct pivot_value *corner_text;
     struct pivot_value *caption;
-    char *notes;
+    char *notes;                /* Shown as tooltip. */
 
     /* Dimensions. */
     struct pivot_dimension **dimensions;
@@ -477,9 +485,18 @@ struct pivot_table *pivot_table_create_for_text (struct pivot_value *title,
                                                  struct pivot_value *content);
 
 struct pivot_table *pivot_table_ref (const struct pivot_table *);
+struct pivot_table *pivot_table_unshare (struct pivot_table *);
 void pivot_table_unref (struct pivot_table *);
 bool pivot_table_is_shared (const struct pivot_table *);
 
+/* Axes. */
+void pivot_table_swap_axes (struct pivot_table *,
+                            enum pivot_axis_type, enum pivot_axis_type);
+void pivot_table_transpose (struct pivot_table *);
+void pivot_table_move_dimension (struct pivot_table *,
+                                 struct pivot_dimension *,
+                                 enum pivot_axis_type, size_t ofs);
+
 /* Styling. */
 const struct pivot_table_look *pivot_table_get_look (
   const struct pivot_table *);
@@ -516,6 +533,8 @@ const struct pivot_value *pivot_table_get (const struct pivot_table *,
 struct pivot_value *pivot_table_get_rw (struct pivot_table *,
                                         const size_t *dindexes);
 
+bool pivot_table_delete (struct pivot_table *, const size_t *dindexes);
+
 /* Footnotes.
 
    Use pivot_table_create_footnote() to create a footnote.
@@ -628,9 +647,7 @@ struct pivot_value
     char **subscripts;
     size_t n_subscripts;
 
-    char *superscript;
-
-    const struct pivot_footnote **footnotes;
+    size_t *footnote_indexes;
     size_t n_footnotes;
 
     enum pivot_value_type type;
@@ -689,6 +706,10 @@ struct pivot_value
       };
   };
 
+/* Life cycle. */
+struct pivot_value *pivot_value_clone (const struct pivot_value *);
+void pivot_value_destroy (struct pivot_value *);
+
 /* Numbers resulting from calculations. */
 struct pivot_value *pivot_value_new_number (double);
 struct pivot_value *pivot_value_new_integer (double);
@@ -706,7 +727,11 @@ struct pivot_value *pivot_value_new_variable (const struct variable *);
 /* Values from text strings. */
 struct pivot_value *pivot_value_new_text (const char *);
 struct pivot_value *pivot_value_new_text_format (const char *, ...)
+#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__>= 4) || __GNUC__ > 4)
   __attribute__((format(gnu_printf, 1, 2)));
+#else
+  __attribute__((format(__printf__, 1, 2)));
+#endif
 
 struct pivot_value *pivot_value_new_user_text (const char *, size_t length);
 struct pivot_value *pivot_value_new_user_text_nocopy (char *);
@@ -720,19 +745,14 @@ void pivot_value_set_rc (const struct pivot_table *, struct pivot_value *,
 
 /* Converting a pivot_value to a string for display. */
 char *pivot_value_to_string (const struct pivot_value *,
-                             enum settings_value_show show_values,
-                             enum settings_value_show show_variables);
+                             const struct pivot_table *);
+char *pivot_value_to_string_defaults (const struct pivot_value *);
 void pivot_value_format (const struct pivot_value *,
-                         enum settings_value_show show_values,
-                         enum settings_value_show show_variables,
-                         struct string *);
+                         const struct pivot_table *, struct string *);
 bool pivot_value_format_body (const struct pivot_value *,
-                              enum settings_value_show show_values,
-                              enum settings_value_show show_variables,
+                              const struct pivot_table *,
                               struct string *);
 
-void pivot_value_destroy (struct pivot_value *);
-
 /* Styling. */
 void pivot_value_get_style (struct pivot_value *,
                             const struct font_style *base_font_style,
@@ -740,6 +760,10 @@ void pivot_value_get_style (struct pivot_value *,
                             struct table_area_style *);
 void pivot_value_set_style (struct pivot_value *,
                             const struct table_area_style *);
+void pivot_value_set_font_style (struct pivot_value *,
+                                 const struct font_style *);
+void pivot_value_set_cell_style (struct pivot_value *,
+                                 const struct cell_style *);
 
 /* Template arguments. */
 struct pivot_argument
@@ -749,6 +773,8 @@ struct pivot_argument
   };
 
 void pivot_argument_uninit (struct pivot_argument *);
+void pivot_argument_copy (struct pivot_argument *,
+                          const struct pivot_argument *);
 \f
 /* One piece of data within a pivot table. */
 struct pivot_cell