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