Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / output / charts / roc-chart.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 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 #include <config.h>
18
19 #include "output/charts/roc-chart.h"
20
21 #include "data/casereader.h"
22 #include "language/stats/roc.h"
23 #include "output/chart-item-provider.h"
24
25 #include "gl/xalloc.h"
26
27 #include "gettext.h"
28 #define _(msgid) gettext (msgid)
29
30 struct roc_chart *
31 roc_chart_create (bool reference)
32 {
33   struct roc_chart *rc = xmalloc (sizeof *rc);
34   chart_item_init (&rc->chart_item, &roc_chart_class, NULL);
35   rc->reference = reference;
36   rc->vars = NULL;
37   rc->n_vars = 0;
38   rc->allocated_vars = 0;
39   return rc;
40 }
41
42 void
43 roc_chart_add_var (struct roc_chart *rc, const char *var_name,
44                    const struct casereader *cutpoint_reader)
45 {
46   struct roc_var *rv;
47
48   if (rc->n_vars >= rc->allocated_vars)
49     rc->vars = x2nrealloc (rc->vars, &rc->allocated_vars, sizeof *rc->vars);
50
51   rv = &rc->vars[rc->n_vars++];
52   rv->name = xstrdup (var_name);
53   rv->cutpoint_reader = casereader_clone (cutpoint_reader);
54 }
55
56 static void
57 roc_chart_destroy (struct chart_item *chart_item)
58 {
59   struct roc_chart *rc = UP_CAST (chart_item, struct roc_chart, chart_item);
60   size_t i;
61
62   for (i = 0; i < rc->n_vars; i++)
63     {
64       struct roc_var *rv = &rc->vars[i];
65       free (rv->name);
66       casereader_destroy (rv->cutpoint_reader);
67     }
68   free (rc->vars);
69   free (rc);
70 }
71
72 const struct chart_item_class roc_chart_class =
73   {
74     roc_chart_destroy
75   };