23 |
#include <stdlib.h> |
#include <stdlib.h> |
24 |
#include "str.h" |
#include "str.h" |
25 |
|
|
26 |
|
|
27 |
/* Initializes MV as a set of missing values for a variable of |
/* Initializes MV as a set of missing values for a variable of |
28 |
the given WIDTH. Although only numeric variables and short |
the given WIDTH. Although only numeric variables and short |
29 |
string variables may have missing values, WIDTH may be any |
string variables may have missing values, WIDTH may be any |
36 |
mv->width = width; |
mv->width = width; |
37 |
} |
} |
38 |
|
|
39 |
|
void |
40 |
|
mv_set_type(struct missing_values *mv, enum mv_type type) |
41 |
|
{ |
42 |
|
mv->type = type; |
43 |
|
} |
44 |
|
|
45 |
|
|
46 |
/* Copies SRC to MV. */ |
/* Copies SRC to MV. */ |
47 |
void |
void |
48 |
mv_copy (struct missing_values *mv, const struct missing_values *src) |
mv_copy (struct missing_values *mv, const struct missing_values *src) |
49 |
{ |
{ |
50 |
|
assert(src); |
51 |
|
|
52 |
*mv = *src; |
*mv = *src; |
53 |
} |
} |
54 |
|
|
145 |
/* Returns true if MV contains an individual value, |
/* Returns true if MV contains an individual value, |
146 |
false if MV is empty (or contains only a range). */ |
false if MV is empty (or contains only a range). */ |
147 |
bool |
bool |
148 |
mv_has_value (struct missing_values *mv) |
mv_has_value (const struct missing_values *mv) |
149 |
{ |
{ |
150 |
switch (mv->type) |
switch (mv->type) |
151 |
{ |
{ |
173 |
*v = mv->values[mv->type & 3]; |
*v = mv->values[mv->type & 3]; |
174 |
} |
} |
175 |
|
|
176 |
|
/* Stores a value in *V. |
177 |
|
MV must contain an individual value (as determined by |
178 |
|
mv_has_value()). |
179 |
|
IDX is the zero based index of the value to get |
180 |
|
*/ |
181 |
|
void |
182 |
|
mv_peek_value (const struct missing_values *mv, union value *v, int idx) |
183 |
|
{ |
184 |
|
assert (idx >= 0 ) ; |
185 |
|
assert (idx < 3); |
186 |
|
|
187 |
|
assert (mv_has_value (mv)); |
188 |
|
*v = mv->values[idx]; |
189 |
|
} |
190 |
|
|
191 |
|
void |
192 |
|
mv_replace_value (struct missing_values *mv, const union value *v, int idx) |
193 |
|
{ |
194 |
|
assert (idx >= 0) ; |
195 |
|
assert (idx < mv_n_values(mv)); |
196 |
|
|
197 |
|
mv->values[idx] = *v; |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
int |
203 |
|
mv_n_values (const struct missing_values *mv) |
204 |
|
{ |
205 |
|
assert(mv_has_value(mv)); |
206 |
|
return mv->type & 3; |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
/* Returns true if MV contains a numeric range, |
/* Returns true if MV contains a numeric range, |
211 |
false if MV is empty (or contains only individual values). */ |
false if MV is empty (or contains only individual values). */ |
212 |
bool |
bool |
213 |
mv_has_range (struct missing_values *mv) |
mv_has_range (const struct missing_values *mv) |
214 |
{ |
{ |
215 |
switch (mv->type) |
switch (mv->type) |
216 |
{ |
{ |
239 |
mv->type &= 3; |
mv->type &= 3; |
240 |
} |
} |
241 |
|
|
242 |
|
|
243 |
|
/* Returns the numeric range from MV into *LOW and |
244 |
|
*HIGH. MV must contain a individual range (as determined by |
245 |
|
mv_has_range()). */ |
246 |
|
void |
247 |
|
mv_peek_range (const struct missing_values *mv, double *low, double *high) |
248 |
|
{ |
249 |
|
assert (mv_has_range (mv)); |
250 |
|
*low = mv->values[1].f; |
251 |
|
*high = mv->values[2].f; |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
/* Returns true if values[IDX] is in use when the `type' member |
/* Returns true if values[IDX] is in use when the `type' member |
256 |
is set to TYPE (in struct missing_values), |
is set to TYPE (in struct missing_values), |
257 |
false otherwise. */ |
false otherwise. */ |