output-item: Collapse the inheritance hierarchy into a single struct.
[pspp] / src / output / charts / spreadlevel-plot.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2012 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_CHARTS_SL_PLOT_H
18 #define OUTPUT_CHARTS_SL_PLOT_H 1
19
20 #include "output/chart.h"
21 #include <stddef.h>
22
23 struct datum
24 {
25   double x;
26   double y;
27 };
28
29 struct spreadlevel_plot_chart
30   {
31     struct chart chart;
32
33     /* Calculated parameters */
34     double y_lower, y_upper;
35     double x_lower, x_upper;
36
37     double tx_pwr;
38
39     size_t n_data;
40     struct datum *data;
41   };
42
43 struct chart *spreadlevel_plot_create (const char *label, double slp);
44
45 void spreadlevel_plot_add (struct chart *, double spread, double level);
46
47
48 \f
49 /* This boilerplate for spreadlevel_plot_chart, a subclass of chart, was
50    autogenerated by mk-class-boilerplate. */
51
52 #include <assert.h>
53 #include "libpspp/cast.h"
54
55 extern const struct chart_class spreadlevel_plot_chart_class;
56
57 /* Returns true if SUPER is a spreadlevel_plot_chart, otherwise false. */
58 static inline bool
59 is_spreadlevel_plot_chart (const struct chart *super)
60 {
61   return super->class == &spreadlevel_plot_chart_class;
62 }
63
64 /* Returns SUPER converted to spreadlevel_plot_chart.  SUPER must be a spreadlevel_plot_chart, as
65    reported by is_spreadlevel_plot_chart. */
66 static inline struct spreadlevel_plot_chart *
67 to_spreadlevel_plot_chart (const struct chart *super)
68 {
69   assert (is_spreadlevel_plot_chart (super));
70   return UP_CAST (super, struct spreadlevel_plot_chart, chart);
71 }
72
73 /* Returns INSTANCE converted to chart. */
74 static inline struct chart *
75 spreadlevel_plot_chart_super (const struct spreadlevel_plot_chart *instance)
76 {
77   return CONST_CAST (struct chart *, &instance->chart);
78 }
79
80 /* Increments INSTANCE's reference count and returns INSTANCE. */
81 static inline struct spreadlevel_plot_chart *
82 spreadlevel_plot_chart_ref (const struct spreadlevel_plot_chart *instance)
83 {
84   return to_spreadlevel_plot_chart (chart_ref (&instance->chart));
85 }
86
87 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
88    the reference count is now zero. */
89 static inline void
90 spreadlevel_plot_chart_unref (struct spreadlevel_plot_chart *instance)
91 {
92   chart_unref (&instance->chart);
93 }
94
95 /* Returns true if INSTANCE's reference count is greater than 1,
96    false otherwise. */
97 static inline bool
98 spreadlevel_plot_chart_is_shared (const struct spreadlevel_plot_chart *instance)
99 {
100   return chart_is_shared (&instance->chart);
101 }
102
103 static inline void
104 spreadlevel_plot_chart_submit (struct spreadlevel_plot_chart *instance)
105 {
106   chart_submit (&instance->chart);
107 }
108 \f
109 #endif