output-item: Make command name part of every output_item.
[pspp] / src / output / group-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2018 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_GROUP_ITEM_H
18 #define OUTPUT_GROUP_ITEM_H 1
19
20 /* Grouping items.
21
22    A group-open item marks the beginning of a group of related output items.  A
23    later group-close item ends the group.  Groups can nest. */
24
25 #include <stdbool.h>
26 #include "output/output-item.h"
27
28 /* A group_open item. */
29 struct group_open_item
30   {
31     struct output_item output_item;
32   };
33
34 struct group_open_item *group_open_item_create (const char *command_name,
35                                                 const char *label);
36 struct group_open_item *group_open_item_create_nocopy (char *command_name,
37                                                        char *label);
38
39 /* A group_close item. */
40 struct group_close_item
41   {
42     struct output_item output_item;
43   };
44 struct group_close_item *group_close_item_create (void);
45 \f
46 /* This boilerplate for group_open_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 group_open_item_class;
53
54 /* Returns true if SUPER is a group_open_item, otherwise false. */
55 static inline bool
56 is_group_open_item (const struct output_item *super)
57 {
58   return super->class == &group_open_item_class;
59 }
60
61 /* Returns SUPER converted to group_open_item.  SUPER must be a
62    group_open_item, as reported by is_group_open_item. */
63 static inline struct group_open_item *
64 to_group_open_item (const struct output_item *super)
65 {
66   assert (is_group_open_item (super));
67   return UP_CAST (super, struct group_open_item, output_item);
68 }
69
70 /* Returns INSTANCE converted to output_item. */
71 static inline struct output_item *
72 group_open_item_super (const struct group_open_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 group_open_item *
79 group_open_item_ref (const struct group_open_item *instance)
80 {
81   return to_group_open_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 group_open_item_unref (struct group_open_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 group_open_item_is_shared (const struct group_open_item *instance)
96 {
97   return output_item_is_shared (&instance->output_item);
98 }
99
100 void group_open_item_submit (struct group_open_item *);
101 \f
102 /* This boilerplate for group_close_item, a subclass of output_item, was
103    autogenerated by mk-class-boilerplate. */
104
105 #include <assert.h>
106 #include "libpspp/cast.h"
107
108 extern const struct output_item_class group_close_item_class;
109
110 /* Returns true if SUPER is a group_close_item, otherwise false. */
111 static inline bool
112 is_group_close_item (const struct output_item *super)
113 {
114   return super->class == &group_close_item_class;
115 }
116
117 /* Returns SUPER converted to group_close_item.  SUPER must be a
118    group_close_item, as reported by is_group_close_item. */
119 static inline struct group_close_item *
120 to_group_close_item (const struct output_item *super)
121 {
122   assert (is_group_close_item (super));
123   return UP_CAST (super, struct group_close_item, output_item);
124 }
125
126 /* Returns INSTANCE converted to output_item. */
127 static inline struct output_item *
128 group_close_item_super (const struct group_close_item *instance)
129 {
130   return CONST_CAST (struct output_item *, &instance->output_item);
131 }
132
133 /* Increments INSTANCE's reference count and returns INSTANCE. */
134 static inline struct group_close_item *
135 group_close_item_ref (const struct group_close_item *instance)
136 {
137   return to_group_close_item (output_item_ref (&instance->output_item));
138 }
139
140 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
141    the reference count is now zero. */
142 static inline void
143 group_close_item_unref (struct group_close_item *instance)
144 {
145   output_item_unref (&instance->output_item);
146 }
147
148 /* Returns true if INSTANCE's reference count is greater than 1,
149    false otherwise. */
150 static inline bool
151 group_close_item_is_shared (const struct group_close_item *instance)
152 {
153   return output_item_is_shared (&instance->output_item);
154 }
155
156 void group_close_item_submit (struct group_close_item *);
157 \f
158 #endif /* output/group-item.h */