work
[pspp] / src / output / table-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2011, 2014 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #ifndef OUTPUT_TABLE_ITEM_H
18 #define OUTPUT_TABLE_ITEM_H 1
19
20 /* Table items.
21
22    A table item is a subclass of an output item (see output-item.h) that
23    contains a pivot table (see pivot-table.h). */
24
25 #include "libpspp/compiler.h"
26 #include "output/output-item.h"
27
28 /* A table item. */
29 struct table_item
30   {
31     struct output_item output_item;  /* Superclass. */
32     struct pivot_table *table;       /* The table to be rendered. */
33   };
34
35 struct table_item *table_item_create (struct pivot_table *);
36 \f
37 /* This boilerplate for table_item, a subclass of output_item, was
38    autogenerated by mk-class-boilerplate. */
39
40 #include <assert.h>
41 #include "libpspp/cast.h"
42
43 extern const struct output_item_class table_item_class;
44
45 /* Returns true if SUPER is a table_item, otherwise false. */
46 static inline bool
47 is_table_item (const struct output_item *super)
48 {
49   return super->class == &table_item_class;
50 }
51
52 /* Returns SUPER converted to table_item.  SUPER must be a table_item, as
53    reported by is_table_item. */
54 static inline struct table_item *
55 to_table_item (const struct output_item *super)
56 {
57   assert (is_table_item (super));
58   return UP_CAST (super, struct table_item, output_item);
59 }
60
61 /* Returns INSTANCE converted to output_item. */
62 static inline struct output_item *
63 table_item_super (const struct table_item *instance)
64 {
65   return CONST_CAST (struct output_item *, &instance->output_item);
66 }
67
68 /* Increments INSTANCE's reference count and returns INSTANCE. */
69 static inline struct table_item *
70 table_item_ref (const struct table_item *instance)
71 {
72   return to_table_item (output_item_ref (&instance->output_item));
73 }
74
75 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
76    the reference count is now zero. */
77 static inline void
78 table_item_unref (struct table_item *instance)
79 {
80   output_item_unref (&instance->output_item);
81 }
82
83 /* Returns true if INSTANCE's reference count is greater than 1,
84    false otherwise. */
85 static inline bool
86 table_item_is_shared (const struct table_item *instance)
87 {
88   return output_item_is_shared (&instance->output_item);
89 }
90
91 void table_item_submit (struct table_item *);
92 \f
93 #endif /* output/table-item.h */