X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fmissing-values.h;h=8123beeda158cb8a5ab0d0b6a009155843cdd5ca;hb=d639cfd7d10a38c87ebde13d0c0cf53f8d5b0084;hp=4f87f54360ff3aa19616489ef1c9a0848a219620;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp diff --git a/src/data/missing-values.h b/src/data/missing-values.h index 4f87f54360..8123beeda1 100644 --- a/src/data/missing-values.h +++ b/src/data/missing-values.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2009, 2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,11 +14,33 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#if !missing_values_h -#define missing_values_h 1 +/* User-missing values. + + struct missing_values is an opaque type that represents a set + of user-missing values associated with a variable. Valid sets + of missing values depend on variable width: + + - Numeric variables may have up to 3 discrete numeric + user-missing values, or a range of numeric values, or a + range plus one discrete value. + + - String variables may have up to 3 discrete string + user-missing values. (However, for long string + variables all bytes after the first MV_MAX_STRING must + be spaces.) +*/ + +#ifndef DATA_MISSING_VALUES_H +#define DATA_MISSING_VALUES_H 1 #include -#include "value.h" +#include "data/value.h" + +struct pool; + +/* Missing values for long string variables after the first + MV_MAX_STRING bytes must be all spaces. */ +#define MV_MAX_STRING 8 /* Missing values. Opaque--use access functions defined below. */ @@ -26,53 +48,67 @@ struct missing_values { int type; /* Types of missing values, one of MVT_*. */ int width; /* 0=numeric, otherwise string width. */ - union value values[3]; /* Missing values. [y,z] are the range. */ + union value values[3]; /* Missing values. [1], [2] are the range. */ }; -/* Classes of missing values. */ +/* Classes of missing values. + + These are useful as individual values and as masks, and they are used both + ways. */ enum mv_class { - MV_NEVER = 0, /* Never considered missing. */ - MV_USER = 1, /* Missing if value is user-missing. */ - MV_SYSTEM = 2, /* Missing if value is system-missing. */ - MV_ANY = MV_USER | MV_SYSTEM /* Missing if it is user or system-missing. */ + MV_USER = 1, /* User-missing. */ + MV_SYSTEM = 2 /* System-missing. */ +#define MV_ANY (MV_USER | MV_SYSTEM) }; +/* Is a value missing? */ +enum mv_class mv_is_value_missing (const struct missing_values *, + const union value *); +enum mv_class mv_is_num_missing (const struct missing_values *, double); +enum mv_class mv_is_str_missing (const struct missing_values *, + const uint8_t[]); +enum mv_class mv_is_value_missing_varwidth (const struct missing_values *, + const union value *, + int value_width); + +/* Initializing missing value sets. */ void mv_init (struct missing_values *, int width); +void mv_init_pool (struct pool *pool, struct missing_values *, int width); +void mv_destroy (struct missing_values *); +void mv_copy (struct missing_values *, const struct missing_values *); void mv_clear (struct missing_values *); -void mv_copy (struct missing_values *, const struct missing_values *); +/* Changing width of a missing value set. */ +bool mv_is_resizable (const struct missing_values *, int width); +void mv_resize (struct missing_values *, int width); + +/* Basic property inspection. */ +bool mv_is_acceptable (const union value *, int width); bool mv_is_empty (const struct missing_values *); int mv_get_width (const struct missing_values *); -bool mv_add_value (struct missing_values *, const union value *); -bool mv_add_str (struct missing_values *, const char[]); -bool mv_add_num (struct missing_values *, double); -bool mv_add_num_range (struct missing_values *, double low, double high); - +/* Inspecting discrete values. */ +int mv_n_values (const struct missing_values *); bool mv_has_value (const struct missing_values *); -void mv_pop_value (struct missing_values *, union value *); -void mv_peek_value (const struct missing_values *mv, union value *v, int idx); -void mv_replace_value (struct missing_values *mv, const union value *v, int idx); - -int mv_n_values (const struct missing_values *mv); - +const union value *mv_get_value (const struct missing_values *, int idx); +/* Inspecting ranges. */ bool mv_has_range (const struct missing_values *); -void mv_pop_range (struct missing_values *, double *low, double *high); -void mv_peek_range (const struct missing_values *, double *low, double *high); +void mv_get_range (const struct missing_values *, double *low, double *high); -bool mv_is_resizable (const struct missing_values *, int width); -void mv_resize (struct missing_values *, int width); +/* Adding and modifying discrete values. */ +bool mv_add_value (struct missing_values *, const union value *); +bool mv_add_str (struct missing_values *, const uint8_t[], size_t len); +bool mv_add_num (struct missing_values *, double); +void mv_pop_value (struct missing_values *, union value *); +bool mv_replace_value (struct missing_values *, const union value *, int idx); -typedef bool mv_is_missing_func (const struct missing_values *, - const union value *); +/* Adding and modifying ranges. */ +bool mv_add_range (struct missing_values *, double low, double high); +void mv_pop_range (struct missing_values *, double *low, double *high); -/* Is a value missing? */ -bool mv_is_value_missing (const struct missing_values *, const union value *, - enum mv_class); -bool mv_is_num_missing (const struct missing_values *, double, enum mv_class); -bool mv_is_str_missing (const struct missing_values *, const char[], - enum mv_class); +/* Formatting. */ +char *mv_to_string (const struct missing_values *, const char *encoding); -#endif /* missing-values.h */ +#endif /* data/missing-values.h */