e6f6a0b2926ffc77403bfc082ff3783c3f85b6f5
[pspp-builds.git] / src / data / missing-values.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2005 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #if !missing_values_h
21 #define missing_values_h 1
22
23 #include <stdbool.h>
24 #include "value.h"
25
26 /* Types of user-missing values.
27    Invisible--use access functions defined below instead. */
28 enum mv_type 
29   {
30     MV_NONE = 0,                /* No user-missing values. */
31     MV_1 = 1,                   /* One user-missing value. */
32     MV_2 = 2,                   /* Two user-missing values. */
33     MV_3 = 3,                   /* Three user-missing values. */
34     MV_RANGE = 4,               /* A range of user-missing values. */
35     MV_RANGE_1 = 5              /* A range plus an individual value. */
36   };
37
38 /* Missing values.
39    Opaque--use access functions defined below. */
40 struct missing_values 
41   {
42     unsigned type;              /* Number and type of missing values. */
43     int width;                  /* 0=numeric, otherwise string width. */
44     union value values[3];      /* Missing values.  [y,z] are the range. */
45   };
46
47
48 void mv_init (struct missing_values *, int width);
49 void mv_set_type(struct missing_values *mv, enum mv_type type);
50
51 void mv_copy (struct missing_values *, const struct missing_values *);
52 bool mv_is_empty (const struct missing_values *);
53 int mv_get_width (const struct missing_values *);
54
55 bool mv_add_value (struct missing_values *, const union value *);
56 bool mv_add_str (struct missing_values *, const char[]);
57 bool mv_add_num (struct missing_values *, double);
58 bool mv_add_num_range (struct missing_values *, double low, double high);
59
60 bool mv_has_value (const struct missing_values *);
61 void mv_pop_value (struct missing_values *, union value *);
62 void mv_peek_value (const struct missing_values *mv, union value *v, int idx);
63 void mv_replace_value (struct missing_values *mv, const union value *v, int idx);
64
65 int  mv_n_values (const struct missing_values *mv);
66
67
68 bool mv_has_range (const struct missing_values *);
69 void mv_pop_range (struct missing_values *, double *low, double *high);
70 void mv_peek_range (const struct missing_values *, double *low, double *high);
71
72 bool mv_is_resizable (const struct missing_values *, int width);
73 void mv_resize (struct missing_values *, int width);
74
75 typedef bool mv_is_missing_func (const struct missing_values *,
76                                  const union value *);
77
78 /* Is a value system or user missing? */
79 bool mv_is_value_missing (const struct missing_values *, const union value *);
80 bool mv_is_num_missing (const struct missing_values *, double);
81 bool mv_is_str_missing (const struct missing_values *, const char[]);
82
83 /* Is a value user missing? */
84 bool mv_is_value_user_missing (const struct missing_values *,
85                                const union value *);
86 bool mv_is_num_user_missing (const struct missing_values *, double);
87 bool mv_is_str_user_missing (const struct missing_values *, const char[]);
88
89 /* Is a value system missing? */
90 bool mv_is_value_system_missing (const struct missing_values *,
91                                  const union value *);
92
93 #endif /* missing-values.h */