49b5bbe1ebf531b5e216e46595395b7a10ffeb6b
[pspp] / src / output / text-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011 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_TEXT_ITEM_H
18 #define OUTPUT_TEXT_ITEM_H 1
19
20 /* Text items.
21
22    A text item is a subclass of an output item (see
23    output/output-item.h).
24
25    A text item is just a text string. */
26
27 #include <stdbool.h>
28 #include "libpspp/compiler.h"
29 #include "output/output-item.h"
30 #include "output/table.h"
31
32 enum text_item_type
33   {
34     TEXT_ITEM_PAGE_TITLE,       /* TITLE and SUBTITLE commands. */
35     TEXT_ITEM_TITLE,            /* Title. */
36     TEXT_ITEM_SYNTAX,           /* Syntax printback logging. */
37     TEXT_ITEM_LOG,              /* Other logging. */
38   };
39
40 const char *text_item_type_to_string (enum text_item_type);
41
42 /* A text item. */
43 struct text_item
44   {
45     struct output_item output_item;
46     enum text_item_type type;
47     struct pivot_value *text;
48   };
49
50 struct text_item *text_item_create (enum text_item_type,
51                                     const char *text, const char *label);
52 struct text_item *text_item_create_nocopy (enum text_item_type,
53                                            char *text, char *label);
54 struct text_item *text_item_create_value (enum text_item_type,
55                                           struct pivot_value *value,
56                                           char *label);
57
58 enum text_item_type text_item_get_type (const struct text_item *);
59 char *text_item_get_plain_text (const struct text_item *);
60
61 struct text_item *text_item_unshare (struct text_item *);
62 bool text_item_append (struct text_item *dst, const struct text_item *src);
63
64 struct table_item *text_item_to_table_item (struct text_item *);
65 \f
66 /* This boilerplate for text_item, a subclass of output_item, was
67    autogenerated by mk-class-boilerplate. */
68
69 #include <assert.h>
70 #include "libpspp/cast.h"
71
72 extern const struct output_item_class text_item_class;
73
74 /* Returns true if SUPER is a text_item, otherwise false. */
75 static inline bool
76 is_text_item (const struct output_item *super)
77 {
78   return super->class == &text_item_class;
79 }
80
81 /* Returns SUPER converted to text_item.  SUPER must be a text_item, as
82    reported by is_text_item. */
83 static inline struct text_item *
84 to_text_item (const struct output_item *super)
85 {
86   assert (is_text_item (super));
87   return UP_CAST (super, struct text_item, output_item);
88 }
89
90 /* Returns INSTANCE converted to output_item. */
91 static inline struct output_item *
92 text_item_super (const struct text_item *instance)
93 {
94   return CONST_CAST (struct output_item *, &instance->output_item);
95 }
96
97 /* Increments INSTANCE's reference count and returns INSTANCE. */
98 static inline struct text_item *
99 text_item_ref (const struct text_item *instance)
100 {
101   return to_text_item (output_item_ref (&instance->output_item));
102 }
103
104 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
105    the reference count is now zero. */
106 static inline void
107 text_item_unref (struct text_item *instance)
108 {
109   output_item_unref (&instance->output_item);
110 }
111
112 /* Returns true if INSTANCE's reference count is greater than 1,
113    false otherwise. */
114 static inline bool
115 text_item_is_shared (const struct text_item *instance)
116 {
117   return output_item_is_shared (&instance->output_item);
118 }
119
120 void text_item_submit (struct text_item *);
121 \f
122 #endif /* output/text-item.h */