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/>. */
22 #include "libpspp/cast.h"
23 #include "libpspp/compiler.h"
24 #include "libpspp/str.h"
25 #include "output/chart-provider.h"
26 #include "output/output-item.h"
28 #include "gl/xalloc.h"
31 #define _(msgid) gettext (msgid)
34 chart_ref (const struct chart *chart_)
36 struct chart *chart = CONST_CAST (struct chart *, chart_);
37 assert (chart->ref_cnt > 0);
43 chart_unref (struct chart *chart)
47 assert (chart->ref_cnt > 0);
48 if (!--chart->ref_cnt)
50 char *title = chart->title;
51 chart->class->destroy (chart);
58 chart_is_shared (const struct chart *chart)
60 assert (chart->ref_cnt > 0);
61 return chart->ref_cnt > 1;
64 /* Initializes CHART as a chart of the specified CLASS. The new chart
65 initially has the specified TITLE, which may be NULL if no title is yet
66 available. The caller retains ownership of TITLE.
68 A chart is abstract, that is, a plain chart is not useful on its own. Thus,
69 this function is normally called from the initialization function of some
72 chart_init (struct chart *chart, const struct chart_class *class,
75 *chart = (struct chart) {
78 .title = xstrdup_if_nonnull (title),
82 /* Returns CHART's title, which is a null pointer if no title has been set. */
84 chart_get_title (const struct chart *chart)
89 /* Sets CHART's title to TITLE, replacing any previous title. Specify NULL for
90 TITLE to clear any title from CHART. The caller retains ownership of
93 This function may only be used on a chart that is unshared. */
95 chart_set_title (struct chart *chart, const char *title)
97 assert (!chart_is_shared (chart));
99 chart->title = xstrdup_if_nonnull (title);
102 /* Submits CHART to the configured output drivers, and transfers ownership to
103 the output subsystem. */
105 chart_submit (struct chart *chart)
108 output_item_submit (chart_item_create (chart));