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