output-item: Make command name part of every output_item.
[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 table (see table.h) and some formatting properties.  Currently
24    the formatting properties are an optional title (a brief description
25    typically displayed above the table) and an optional caption (a more verbose
26    description typically displayed below the table). */
27
28 #include "libpspp/compiler.h"
29 #include "output/output-item.h"
30 #include "output/table.h"
31
32 /* A table item.
33
34    The members of struct table_item should not be accessed directly.  Use one
35    of the accessor functions defined below. */
36 struct table_item
37   {
38     struct output_item output_item;   /* Superclass. */
39     struct pivot_table *pt;           /* The table to be rendered. */
40
41     char *cached_label;
42   };
43
44 struct table_item *table_item_create (struct pivot_table *);
45 \f
46 /* This boilerplate for table_item, a subclass of output_item, was
47    autogenerated by mk-class-boilerplate. */
48
49 #include <assert.h>
50 #include "libpspp/cast.h"
51
52 extern const struct output_item_class table_item_class;
53
54 /* Returns true if SUPER is a table_item, otherwise false. */
55 static inline bool
56 is_table_item (const struct output_item *super)
57 {
58   return super->class == &table_item_class;
59 }
60
61 /* Returns SUPER converted to table_item.  SUPER must be a table_item, as
62    reported by is_table_item. */
63 static inline struct table_item *
64 to_table_item (const struct output_item *super)
65 {
66   assert (is_table_item (super));
67   return UP_CAST (super, struct table_item, output_item);
68 }
69
70 /* Returns INSTANCE converted to output_item. */
71 static inline struct output_item *
72 table_item_super (const struct table_item *instance)
73 {
74   return CONST_CAST (struct output_item *, &instance->output_item);
75 }
76
77 /* Increments INSTANCE's reference count and returns INSTANCE. */
78 static inline struct table_item *
79 table_item_ref (const struct table_item *instance)
80 {
81   return to_table_item (output_item_ref (&instance->output_item));
82 }
83
84 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
85    the reference count is now zero. */
86 static inline void
87 table_item_unref (struct table_item *instance)
88 {
89   output_item_unref (&instance->output_item);
90 }
91
92 /* Returns true if INSTANCE's reference count is greater than 1,
93    false otherwise. */
94 static inline bool
95 table_item_is_shared (const struct table_item *instance)
96 {
97   return output_item_is_shared (&instance->output_item);
98 }
99
100 void table_item_submit (struct table_item *);
101
102 #endif /* output/table-item.h */