output: Add support for layer info in table output.
[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
31 /* Title or caption in a table item. */
32 struct table_item_text
33   {
34     char *content;
35     const struct footnote **footnotes;
36     size_t n_footnotes;
37     int halign;                 /* TAB_*. */
38     struct cell_style *style;
39   };
40
41 struct table_item_text *table_item_text_create (const char *);
42 struct table_item_text *table_item_text_clone (const struct table_item_text *);
43 void table_item_text_destroy (struct table_item_text *);
44
45 /* A table item.
46
47    The members of struct table_item should not be accessed directly.  Use one
48    of the accessor functions defined below. */
49 struct table_item
50   {
51     struct output_item output_item;  /* Superclass. */
52     struct table *table;             /* The table to be rendered. */
53     struct table_item_text *title;   /* Null if there is no title. */
54     struct table_item_text *layers;  /* Null if there is no layer info. */
55     struct table_item_text *caption; /* Null if there is no caption. */
56   };
57
58 struct table_item *table_item_create (struct table *, const char *title,
59                                       const char *caption);
60
61 const struct table *table_item_get_table (const struct table_item *);
62
63 const struct table_item_text *table_item_get_title (const struct table_item *);
64 void table_item_set_title (struct table_item *,
65                            const struct table_item_text *);
66
67 const struct table_item_text *table_item_get_layers (
68   const struct table_item *);
69 void table_item_set_layers (struct table_item *,
70                            const struct table_item_text *);
71
72 const struct table_item_text *table_item_get_caption (
73   const struct table_item *);
74 void table_item_set_caption (struct table_item *,
75                              const struct table_item_text *);
76 \f
77 /* This boilerplate for table_item, a subclass of output_item, was
78    autogenerated by mk-class-boilerplate. */
79
80 #include <assert.h>
81 #include "libpspp/cast.h"
82
83 extern const struct output_item_class table_item_class;
84
85 /* Returns true if SUPER is a table_item, otherwise false. */
86 static inline bool
87 is_table_item (const struct output_item *super)
88 {
89   return super->class == &table_item_class;
90 }
91
92 /* Returns SUPER converted to table_item.  SUPER must be a table_item, as
93    reported by is_table_item. */
94 static inline struct table_item *
95 to_table_item (const struct output_item *super)
96 {
97   assert (is_table_item (super));
98   return UP_CAST (super, struct table_item, output_item);
99 }
100
101 /* Returns INSTANCE converted to output_item. */
102 static inline struct output_item *
103 table_item_super (const struct table_item *instance)
104 {
105   return CONST_CAST (struct output_item *, &instance->output_item);
106 }
107
108 /* Increments INSTANCE's reference count and returns INSTANCE. */
109 static inline struct table_item *
110 table_item_ref (const struct table_item *instance)
111 {
112   return to_table_item (output_item_ref (&instance->output_item));
113 }
114
115 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
116    the reference count is now zero. */
117 static inline void
118 table_item_unref (struct table_item *instance)
119 {
120   output_item_unref (&instance->output_item);
121 }
122
123 /* Returns true if INSTANCE's reference count is greater than 1,
124    false otherwise. */
125 static inline bool
126 table_item_is_shared (const struct table_item *instance)
127 {
128   return output_item_is_shared (&instance->output_item);
129 }
130
131 void table_item_submit (struct table_item *);
132 \f
133 #endif /* output/table-item.h */