output: Introduce group_item in place of TEXT_ITEM_COMMAND_OPEN and CLOSE.
[pspp] / src / output / group-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2018 Free Sonftware 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     char *command_name;
33   };
34
35 struct group_open_item *group_open_item_create (const char *command_name);
36
37 /* A group_close item. */
38 struct group_close_item
39   {
40     struct output_item output_item;
41   };
42 struct group_close_item *group_close_item_create (void);
43 \f
44 /* This boilerplate for group_open_item, a subclass of output_item, was
45    autogenerated by mk-class-boilerplate. */
46
47 #include <assert.h>
48 #include "libpspp/cast.h"
49
50 extern const struct output_item_class group_open_item_class;
51
52 /* Returns true if SUPER is a group_open_item, otherwise false. */
53 static inline bool
54 is_group_open_item (const struct output_item *super)
55 {
56   return super->class == &group_open_item_class;
57 }
58
59 /* Returns SUPER converted to group_open_item.  SUPER must be a
60    group_open_item, as reported by is_group_open_item. */
61 static inline struct group_open_item *
62 to_group_open_item (const struct output_item *super)
63 {
64   assert (is_group_open_item (super));
65   return UP_CAST (super, struct group_open_item, output_item);
66 }
67
68 /* Returns INSTANCE converted to output_item. */
69 static inline struct output_item *
70 group_open_item_super (const struct group_open_item *instance)
71 {
72   return CONST_CAST (struct output_item *, &instance->output_item);
73 }
74
75 /* Increments INSTANCE's reference count and returns INSTANCE. */
76 static inline struct group_open_item *
77 group_open_item_ref (const struct group_open_item *instance)
78 {
79   return to_group_open_item (output_item_ref (&instance->output_item));
80 }
81
82 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
83    the reference count is now zero. */
84 static inline void
85 group_open_item_unref (struct group_open_item *instance)
86 {
87   output_item_unref (&instance->output_item);
88 }
89
90 /* Returns true if INSTANCE's reference count is greater than 1,
91    false otherwise. */
92 static inline bool
93 group_open_item_is_shared (const struct group_open_item *instance)
94 {
95   return output_item_is_shared (&instance->output_item);
96 }
97
98 void group_open_item_submit (struct group_open_item *);
99 \f
100 /* This boilerplate for group_close_item, a subclass of output_item, was
101    autogenerated by mk-class-boilerplate. */
102
103 #include <assert.h>
104 #include "libpspp/cast.h"
105
106 extern const struct output_item_class group_close_item_class;
107
108 /* Returns true if SUPER is a group_close_item, otherwise false. */
109 static inline bool
110 is_group_close_item (const struct output_item *super)
111 {
112   return super->class == &group_close_item_class;
113 }
114
115 /* Returns SUPER converted to group_close_item.  SUPER must be a
116    group_close_item, as reported by is_group_close_item. */
117 static inline struct group_close_item *
118 to_group_close_item (const struct output_item *super)
119 {
120   assert (is_group_close_item (super));
121   return UP_CAST (super, struct group_close_item, output_item);
122 }
123
124 /* Returns INSTANCE converted to output_item. */
125 static inline struct output_item *
126 group_close_item_super (const struct group_close_item *instance)
127 {
128   return CONST_CAST (struct output_item *, &instance->output_item);
129 }
130
131 /* Increments INSTANCE's reference count and returns INSTANCE. */
132 static inline struct group_close_item *
133 group_close_item_ref (const struct group_close_item *instance)
134 {
135   return to_group_close_item (output_item_ref (&instance->output_item));
136 }
137
138 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
139    the reference count is now zero. */
140 static inline void
141 group_close_item_unref (struct group_close_item *instance)
142 {
143   output_item_unref (&instance->output_item);
144 }
145
146 /* Returns true if INSTANCE's reference count is greater than 1,
147    false otherwise. */
148 static inline bool
149 group_close_item_is_shared (const struct group_close_item *instance)
150 {
151   return output_item_is_shared (&instance->output_item);
152 }
153
154 void group_close_item_submit (struct group_close_item *);
155 \f
156 #endif /* output/group-item.h */