1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009, 2011, 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/>. */
19 #include "output/table-provider.h"
23 #include "libpspp/assertion.h"
24 #include "libpspp/cast.h"
25 #include "output/driver.h"
26 #include "output/output-item-provider.h"
27 #include "output/pivot-table.h"
28 #include "output/table-item.h"
29 #include "output/table-provider.h"
31 #include "gl/xalloc.h"
34 #define _(msgid) gettext (msgid)
36 /* Initializes ITEM as a table item for rendering PT. Takes ownership of
39 table_item_create (struct pivot_table *pt)
41 pivot_table_assign_label_depth (pt);
43 struct table_item *item = xmalloc (sizeof *item);
44 *item = (struct table_item) {
45 .output_item = OUTPUT_ITEM_INITIALIZER (&table_item_class),
51 /* Submits TABLE_ITEM to the configured output drivers, and transfers ownership
52 to the output subsystem. */
54 table_item_submit (struct table_item *table_item)
56 output_submit (&table_item->output_item);
60 table_item_get_label (const struct output_item *output_item)
62 struct table_item *item = to_table_item (output_item);
64 if (!item->cached_label)
69 item->cached_label = pivot_value_to_string (item->pt->title,
70 SETTINGS_VALUE_SHOW_DEFAULT,
71 SETTINGS_VALUE_SHOW_DEFAULT);
73 return item->cached_label;
77 table_item_destroy (struct output_item *output_item)
79 struct table_item *item = to_table_item (output_item);
80 pivot_table_unref (item->pt);
81 free (item->cached_label);
85 const struct output_item_class table_item_class =