e4c40ab228c5ce959a90c828053cb70f24150528
[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 #include "output/table.h"
31
32 /* Title or caption in a table item. */
33 struct table_item_text
34   {
35     char *content;
36     const struct footnote **footnotes;
37     size_t n_footnotes;
38     struct table_area_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 struct table_item_layer
46   {
47     char *content;
48     const struct footnote **footnotes;
49     size_t n_footnotes;
50   };
51
52 void table_item_layer_copy (struct table_item_layer *,
53                             const struct table_item_layer *);
54 void table_item_layer_uninit (struct table_item_layer *);
55
56 struct table_item_layers
57   {
58     struct table_item_layer *layers;
59     size_t n_layers;
60     struct table_area_style *style;
61   };
62
63 struct table_item_layers *table_item_layers_clone (
64   const struct table_item_layers *);
65 void table_item_layers_destroy (struct table_item_layers *);
66
67 /* A table item.
68
69    The members of struct table_item should not be accessed directly.  Use one
70    of the accessor functions defined below. */
71 struct table_item
72   {
73     struct output_item output_item;   /* Superclass. */
74     struct table *table;              /* The table to be rendered. */
75     struct table_item_text *title;    /* Null if there is no title. */
76     struct table_item_text *caption;  /* Null if there is no caption. */
77     struct table_item_layers *layers; /* Null if there is no layer info. */
78     char *notes;                      /* Shown as tooltip. */
79     struct pivot_table *pt;
80   };
81
82 struct table_item *table_item_create (struct table *, const char *title,
83                                       const char *caption, const char *notes);
84
85 const struct table *table_item_get_table (const struct table_item *);
86
87 const struct table_item_text *table_item_get_title (const struct table_item *);
88 void table_item_set_title (struct table_item *,
89                            const struct table_item_text *);
90
91 const struct table_item_layers *table_item_get_layers (
92   const struct table_item *);
93 void table_item_set_layers (struct table_item *,
94                            const struct table_item_layers *);
95
96 const struct table_item_text *table_item_get_caption (
97   const struct table_item *);
98 void table_item_set_caption (struct table_item *,
99                              const struct table_item_text *);
100
101 const char *table_item_get_notes (const struct table_item *);
102 void table_item_set_notes (struct table_item *, const char *notes);
103 \f
104 /* This boilerplate for table_item, a subclass of output_item, was
105    autogenerated by mk-class-boilerplate. */
106
107 #include <assert.h>
108 #include "libpspp/cast.h"
109
110 extern const struct output_item_class table_item_class;
111
112 /* Returns true if SUPER is a table_item, otherwise false. */
113 static inline bool
114 is_table_item (const struct output_item *super)
115 {
116   return super->class == &table_item_class;
117 }
118
119 /* Returns SUPER converted to table_item.  SUPER must be a table_item, as
120    reported by is_table_item. */
121 static inline struct table_item *
122 to_table_item (const struct output_item *super)
123 {
124   assert (is_table_item (super));
125   return UP_CAST (super, struct table_item, output_item);
126 }
127
128 /* Returns INSTANCE converted to output_item. */
129 static inline struct output_item *
130 table_item_super (const struct table_item *instance)
131 {
132   return CONST_CAST (struct output_item *, &instance->output_item);
133 }
134
135 /* Increments INSTANCE's reference count and returns INSTANCE. */
136 static inline struct table_item *
137 table_item_ref (const struct table_item *instance)
138 {
139   return to_table_item (output_item_ref (&instance->output_item));
140 }
141
142 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
143    the reference count is now zero. */
144 static inline void
145 table_item_unref (struct table_item *instance)
146 {
147   output_item_unref (&instance->output_item);
148 }
149
150 /* Returns true if INSTANCE's reference count is greater than 1,
151    false otherwise. */
152 static inline bool
153 table_item_is_shared (const struct table_item *instance)
154 {
155   return output_item_is_shared (&instance->output_item);
156 }
157
158 void table_item_submit (struct table_item *);
159 \f
160 #endif /* output/table-item.h */