1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 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/output-item-provider.h"
24 #include "libpspp/assertion.h"
25 #include "libpspp/cast.h"
27 #include "gl/xalloc.h"
31 /* Increases ITEM's reference count, indicating that it has an additional
32 owner. An output item that is shared among multiple owners must not be
35 output_item_ref (const struct output_item *item_)
37 struct output_item *item = CONST_CAST (struct output_item *, item_);
42 /* Decreases ITEM's reference count, indicating that it has one fewer owner.
43 If ITEM no longer has any owners, it is freed. */
45 output_item_unref (struct output_item *item)
49 assert (item->ref_cnt > 0);
50 if (--item->ref_cnt == 0)
52 char *label = item->label;
53 item->class->destroy (item);
59 /* Returns true if ITEM has more than one owner. An output item that is shared
60 among multiple owners must not be modified. */
62 output_item_is_shared (const struct output_item *item)
64 return item->ref_cnt > 1;
67 /* Returns the label for ITEM, which the caller must not modify or free. */
69 output_item_get_label (const struct output_item *item)
71 return item->label ? item->label : item->class->get_label (item);
74 /* Sets the label for ITEM to LABEL. The caller retains ownership of LABEL.
75 If LABEL is nonnull, it overrides any previously set label and the default
76 label. If LABEL is null, ITEM will now use its default label.
78 ITEM must not be shared. */
80 output_item_set_label (struct output_item *item, const char *label)
82 output_item_set_label_nocopy (item, label ? xstrdup (label) : NULL);
85 /* Sets the label for ITEM to LABEL, transferring ownership of LABEL to ITEM.
86 If LABEL is nonnull, it overrides any previously set label and the default
87 label. If LABEL is null, ITEM will now use its default label.
89 ITEM must not be shared. */
91 output_item_set_label_nocopy (struct output_item *item, char *label)
93 assert (!output_item_is_shared (item));