4f87f54360ff3aa19616489ef1c9a0848a219620
[pspp-builds.git] / src / data / missing-values.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2005 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 #if !missing_values_h
18 #define missing_values_h 1
19
20 #include <stdbool.h>
21 #include "value.h"
22
23 /* Missing values.
24    Opaque--use access functions defined below. */
25 struct missing_values
26   {
27     int type;                   /* Types of missing values, one of MVT_*. */
28     int width;                  /* 0=numeric, otherwise string width. */
29     union value values[3];      /* Missing values.  [y,z] are the range. */
30   };
31
32 /* Classes of missing values. */
33 enum mv_class
34   {
35     MV_NEVER = 0,               /* Never considered missing. */
36     MV_USER = 1,                /* Missing if value is user-missing. */
37     MV_SYSTEM = 2,              /* Missing if value is system-missing. */
38     MV_ANY = MV_USER | MV_SYSTEM /* Missing if it is user or system-missing. */
39   };
40
41 void mv_init (struct missing_values *, int width);
42 void mv_clear (struct missing_values *);
43
44 void mv_copy (struct missing_values *, const struct missing_values *);
45 bool mv_is_empty (const struct missing_values *);
46 int mv_get_width (const struct missing_values *);
47
48 bool mv_add_value (struct missing_values *, const union value *);
49 bool mv_add_str (struct missing_values *, const char[]);
50 bool mv_add_num (struct missing_values *, double);
51 bool mv_add_num_range (struct missing_values *, double low, double high);
52
53 bool mv_has_value (const struct missing_values *);
54 void mv_pop_value (struct missing_values *, union value *);
55 void mv_peek_value (const struct missing_values *mv, union value *v, int idx);
56 void mv_replace_value (struct missing_values *mv, const union value *v, int idx);
57
58 int  mv_n_values (const struct missing_values *mv);
59
60
61 bool mv_has_range (const struct missing_values *);
62 void mv_pop_range (struct missing_values *, double *low, double *high);
63 void mv_peek_range (const struct missing_values *, double *low, double *high);
64
65 bool mv_is_resizable (const struct missing_values *, int width);
66 void mv_resize (struct missing_values *, int width);
67
68 typedef bool mv_is_missing_func (const struct missing_values *,
69                                  const union value *);
70
71 /* Is a value missing? */
72 bool mv_is_value_missing (const struct missing_values *, const union value *,
73                           enum mv_class);
74 bool mv_is_num_missing (const struct missing_values *, double, enum mv_class);
75 bool mv_is_str_missing (const struct missing_values *, const char[],
76                         enum mv_class);
77
78 #endif /* missing-values.h */