8a14edc0d0e5f5b0ae62a6d2854332597466073f
[pspp-builds.git] / src / data / missing-values.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2005 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    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, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 #if !missing_values_h
20 #define missing_values_h 1
21
22 #include <stdbool.h>
23 #include "value.h"
24
25 /* Missing values.
26    Opaque--use access functions defined below. */
27 struct missing_values
28   {
29     int type;                   /* Types of missing values, one of MVT_*. */
30     int width;                  /* 0=numeric, otherwise string width. */
31     union value values[3];      /* Missing values.  [y,z] are the range. */
32   };
33
34 /* Classes of missing values. */
35 enum mv_class
36   {
37     MV_NEVER = 0,               /* Never considered missing. */
38     MV_USER = 1,                /* Missing if value is user-missing. */
39     MV_SYSTEM = 2,              /* Missing if value is system-missing. */
40     MV_ANY = MV_USER | MV_SYSTEM /* Missing if it is user or system-missing. */
41   };
42
43 void mv_init (struct missing_values *, int width);
44 void mv_clear (struct missing_values *);
45
46 void mv_copy (struct missing_values *, const struct missing_values *);
47 bool mv_is_empty (const struct missing_values *);
48 int mv_get_width (const struct missing_values *);
49
50 bool mv_add_value (struct missing_values *, const union value *);
51 bool mv_add_str (struct missing_values *, const char[]);
52 bool mv_add_num (struct missing_values *, double);
53 bool mv_add_num_range (struct missing_values *, double low, double high);
54
55 bool mv_has_value (const struct missing_values *);
56 void mv_pop_value (struct missing_values *, union value *);
57 void mv_peek_value (const struct missing_values *mv, union value *v, int idx);
58 void mv_replace_value (struct missing_values *mv, const union value *v, int idx);
59
60 int  mv_n_values (const struct missing_values *mv);
61
62
63 bool mv_has_range (const struct missing_values *);
64 void mv_pop_range (struct missing_values *, double *low, double *high);
65 void mv_peek_range (const struct missing_values *, double *low, double *high);
66
67 bool mv_is_resizable (const struct missing_values *, int width);
68 void mv_resize (struct missing_values *, int width);
69
70 typedef bool mv_is_missing_func (const struct missing_values *,
71                                  const union value *);
72
73 /* Is a value missing? */
74 bool mv_is_value_missing (const struct missing_values *, const union value *,
75                           enum mv_class);
76 bool mv_is_num_missing (const struct missing_values *, double, enum mv_class);
77 bool mv_is_str_missing (const struct missing_values *, const char[],
78                         enum mv_class);
79
80 #endif /* missing-values.h */