Add datasheet.
[pspp-builds.git] / src / data / casefilter.c
index d88af50a565f52e29f4cce396bdd6684c9159bb5..2c6336d658ca84fc2d850d75e2e21fdd4de9c9ba 100644 (file)
@@ -1,6 +1,5 @@
 /* PSPP - computes sample statistics.
    Copyright (C) 2006 Free Software Foundation, Inc.
-   Written by John Darrington <john@darrington.wattle.id.au>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -28,9 +27,9 @@
 #include <data/variable.h>
 #include <data/missing-values.h>
 
-struct casefilter 
+struct casefilter
  {
-   bool exclude_user_missing;
+   enum mv_class class;
 
    const struct variable **vars;
    int n_vars;
@@ -38,12 +37,12 @@ struct casefilter
 
 
 /* Returns true iff the entire case should be skipped */
-bool 
+bool
 casefilter_skip_case (const struct casefilter *filter, const struct ccase *c)
 {
   int i;
 
-  for (i = 0; i < filter->n_vars; ++i) 
+  for (i = 0; i < filter->n_vars; ++i)
     {
       if ( casefilter_variable_missing (filter, c, filter->vars[i]))
        return true;
@@ -53,39 +52,30 @@ casefilter_skip_case (const struct casefilter *filter, const struct ccase *c)
 }
 
 /* Returns true iff the variable V in case C is missing */
-bool 
-casefilter_variable_missing (const struct casefilter *filter, 
-                            const struct ccase *c, 
+bool
+casefilter_variable_missing (const struct casefilter *filter,
+                            const struct ccase *c,
                             const struct variable *var)
 {
-  const union value *val = case_data (c, var->fv) ;
-      
-  if ( val->f == SYSMIS ) 
-    return true;
-
-  if ( filter->exclude_user_missing && 
-       mv_is_value_user_missing (&var->miss, val) ) 
-    return true;
-
-  return false;
+  const union value *val = case_data (c, var) ;
+  return var_is_value_missing (var, val, filter->class);
 }
 
-/* Create a new casefilter.
-   If EXCL is true, then the filter  user missing values to be missing, 
-   otherwise they are considered at their face value.
+/* Create a new casefilter that drops cases in which any of the
+   N_VARS variables in VARS are in the given CLASS of missing values.
    VARS is an array of variables which if *any* of them are missing.
    N_VARS is the size of VARS.
  */
-struct casefilter * 
-casefilter_create (bool excl, struct variable **vars, int n_vars)
+struct casefilter *
+casefilter_create (enum mv_class class, const struct variable **vars, int n_vars)
 {
   int i;
   struct casefilter * filter = xmalloc (sizeof (*filter)) ;
 
-  filter->exclude_user_missing = excl ;
+  filter->class = class;
   filter->vars = xnmalloc (n_vars, sizeof (*filter->vars) );
 
-  for ( i = 0 ; i < n_vars ; ++i ) 
+  for ( i = 0 ; i < n_vars ; ++i )
     filter->vars[i] = vars[i];
 
   filter->n_vars = n_vars ;
@@ -96,27 +86,25 @@ casefilter_create (bool excl, struct variable **vars, int n_vars)
 
 /* Add the variables in VARS to the list of variables for which the
    filter considers. N_VARS is the size of VARS */
-void 
-casefilter_add_variables (struct casefilter *filter, 
-                          struct variable **vars, int n_vars)
+void
+casefilter_add_variables (struct casefilter *filter,
+                         const struct variable *const *vars, int n_vars)
 {
   int i;
 
   filter->vars = xnrealloc (filter->vars, filter->n_vars + n_vars,
                           sizeof (*filter->vars) );
-                          
-  for ( i = 0 ; i < n_vars ; ++i ) 
+
+  for ( i = 0 ; i < n_vars ; ++i )
     filter->vars[i + filter->n_vars] = vars[i];
 
   filter->n_vars += n_vars ;
 }
 
 /* Destroy the filter FILTER */
-void 
+void
 casefilter_destroy (struct casefilter *filter)
 {
   free (filter->vars);
   free (filter);
 }
-
-