1899a511c118515424ab0a6e558a18b519300de7
[pspp] / src / output / charts / piechart.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004, 2009, 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 PIECHART_H
18 #define PIECHART_H
19
20 #include "libpspp/str.h"
21 #include "output/chart-item.h"
22 #include "language/stats/freq.h"
23
24 struct piechart
25   {
26     struct chart_item chart_item;
27     struct slice *slices;
28     int n_slices;
29   };
30
31 struct slice
32   {
33     struct string label;
34     double magnitude;
35   };
36
37 struct variable;
38
39 struct chart_item *piechart_create (const struct variable *var,
40                                     const struct freq *, int n_slices);
41 \f
42 /* This boilerplate for piechart, a subclass of chart_item, was
43    autogenerated by mk-class-boilerplate. */
44
45 #include <assert.h>
46 #include "libpspp/cast.h"
47
48 extern const struct chart_item_class piechart_class;
49
50 /* Returns true if SUPER is a piechart, otherwise false. */
51 static inline bool
52 is_piechart (const struct chart_item *super)
53 {
54   return super->class == &piechart_class;
55 }
56
57 /* Returns SUPER converted to piechart.  SUPER must be a piechart, as
58    reported by is_piechart. */
59 static inline struct piechart *
60 to_piechart (const struct chart_item *super)
61 {
62   assert (is_piechart (super));
63   return UP_CAST (super, struct piechart, chart_item);
64 }
65
66 /* Returns INSTANCE converted to chart_item. */
67 static inline struct chart_item *
68 piechart_super (const struct piechart *instance)
69 {
70   return CONST_CAST (struct chart_item *, &instance->chart_item);
71 }
72
73 /* Increments INSTANCE's reference count and returns INSTANCE. */
74 static inline struct piechart *
75 piechart_ref (const struct piechart *instance)
76 {
77   return to_piechart (chart_item_ref (&instance->chart_item));
78 }
79
80 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
81    the reference count is now zero. */
82 static inline void
83 piechart_unref (struct piechart *instance)
84 {
85   chart_item_unref (&instance->chart_item);
86 }
87
88 /* Returns true if INSTANCE's reference count is greater than 1,
89    false otherwise. */
90 static inline bool
91 piechart_is_shared (const struct piechart *instance)
92 {
93   return chart_item_is_shared (&instance->chart_item);
94 }
95
96 static inline void
97 piechart_submit (struct piechart *instance)
98 {
99   chart_item_submit (&instance->chart_item);
100 }
101 \f
102 #endif /* output/charts/piechart.h */