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"
29 /* Increases ITEM's reference count, indicating that it has an additional
30 owner. An output item that is shared among multiple owners must not be
33 output_item_ref (const struct output_item *item_)
35 struct output_item *item = CONST_CAST (struct output_item *, item_);
40 /* Decreases ITEM's reference count, indicating that it has one fewer owner.
41 If ITEM no longer has any owners, it is freed. */
43 output_item_unref (struct output_item *item)
47 assert (item->ref_cnt > 0);
48 if (--item->ref_cnt == 0)
49 item->class->destroy (item);
53 /* Returns true if ITEM has more than one owner. An output item that is shared
54 among multiple owners must not be modified. */
56 output_item_is_shared (const struct output_item *item)
58 return item->ref_cnt > 1;
61 /* Initializes ITEM as an output item of the specified CLASS, initially with a
64 An output item is an abstract class, that is, a plain output_item is not
65 useful on its own. Thus, this function is normally called from the
66 initialization function of some subclass of output_item. */
68 output_item_init (struct output_item *item,
69 const struct output_item_class *class)