1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 2009, 2011 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/chart-item.h"
20 #include "output/chart-item-provider.h"
25 #include "libpspp/cast.h"
26 #include "libpspp/compiler.h"
27 #include "libpspp/str.h"
28 #include "output/driver.h"
29 #include "output/output-item-provider.h"
31 #include "gl/xalloc.h"
34 #define _(msgid) gettext (msgid)
36 /* Initializes ITEM as a chart item of the specified CLASS. The new chart item
37 initially has the specified TITLE, which may be NULL if no title is yet
38 available. The caller retains ownership of TITLE.
40 A chart item is an abstract class, that is, a plain chart_item is not useful
41 on its own. Thus, this function is normally called from the initialization
42 function of some subclass of chart_item. */
44 chart_item_init (struct chart_item *item, const struct chart_item_class *class,
47 *item = (struct chart_item) {
48 .output_item = OUTPUT_ITEM_INITIALIZER (&chart_item_class),
50 .title = xstrdup_if_nonnull (title)
54 /* Returns ITEM's title, which is a null pointer if no title has been set. */
56 chart_item_get_title (const struct chart_item *item)
61 /* Sets ITEM's title to TITLE, replacing any previous title. Specify NULL for
62 TITLE to clear any title from ITEM. The caller retains ownership of
65 This function may only be used on a chart_item that is unshared. */
67 chart_item_set_title (struct chart_item *item, const char *title)
69 assert (!chart_item_is_shared (item));
71 item->title = xstrdup_if_nonnull (title);
74 /* Submits ITEM to the configured output drivers, and transfers ownership to
75 the output subsystem. */
77 chart_item_submit (struct chart_item *item)
79 output_submit (&item->output_item);
83 chart_item_get_label (const struct output_item *output_item)
85 const struct chart_item *item = to_chart_item (output_item);
86 return item->title ? item->title : _("Chart");
90 chart_item_destroy (struct output_item *output_item)
92 struct chart_item *item = to_chart_item (output_item);
93 char *title = item->title;
94 item->class->destroy (item);
98 const struct output_item_class chart_item_class =
100 chart_item_get_label,