Frequencies: Added the /BARCHART subcommand.
[pspp] / src / output / charts / barchart.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2015 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 BARCHART_H
18 #define BARCHART_H
19
20 #include "libpspp/str.h"
21 #include "output/chart-item.h"
22
23 struct barchart
24   {
25     struct chart_item chart_item;
26     struct slice *bars;
27     int n_bars;
28     double largest;
29     char *ylabel;
30   };
31
32 struct chart_item *barchart_create (const char *title, const char *ylabel,
33                                     const struct slice *, int n_bars);
34 \f
35 /* This boilerplate for barchart, a subclass of chart_item, was
36    autogenerated by mk-class-boilerplate. */
37
38 #include <assert.h>
39 #include "libpspp/cast.h"
40
41 extern const struct chart_item_class barchart_class;
42
43 /* Returns true if SUPER is a barchart, otherwise false. */
44 static inline bool
45 is_barchart (const struct chart_item *super)
46 {
47   return super->class == &barchart_class;
48 }
49
50 /* Returns SUPER converted to barchart.  SUPER must be a barchart, as
51    reported by is_barchart. */
52 static inline struct barchart *
53 to_barchart (const struct chart_item *super)
54 {
55   assert (is_barchart (super));
56   return UP_CAST (super, struct barchart, chart_item);
57 }
58
59 /* Returns INSTANCE converted to chart_item. */
60 static inline struct chart_item *
61 barchart_super (const struct barchart *instance)
62 {
63   return CONST_CAST (struct chart_item *, &instance->chart_item);
64 }
65
66 /* Increments INSTANCE's reference count and returns INSTANCE. */
67 static inline struct barchart *
68 barchart_ref (const struct barchart *instance)
69 {
70   return to_barchart (chart_item_ref (&instance->chart_item));
71 }
72
73 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
74    the reference count is now zero. */
75 static inline void
76 barchart_unref (struct barchart *instance)
77 {
78   chart_item_unref (&instance->chart_item);
79 }
80
81 /* Returns true if INSTANCE's reference count is greater than 1,
82    false otherwise. */
83 static inline bool
84 barchart_is_shared (const struct barchart *instance)
85 {
86   return chart_item_is_shared (&instance->chart_item);
87 }
88
89 static inline void
90 barchart_submit (struct barchart *instance)
91 {
92   chart_item_submit (&instance->chart_item);
93 }
94 \f
95 #endif /* output/charts/barchart.h */