Patch #6262. New developers guide and resulting fixes and cleanups.
[pspp-builds.git] / src / data / procedure.c
index 60be6b47efac3440e2173436ddeb9b7bf4f70eed..278077e7db93bf3e8786308c85adcac9fe55f78a 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 
 #include <data/case.h>
+#include <data/case-map.h>
 #include <data/caseinit.h>
 #include <data/casereader.h>
 #include <data/casereader-provider.h>
 #include <data/procedure.h>
 #include <data/transformations.h>
 #include <data/variable.h>
-#include <libpspp/alloc.h>
 #include <libpspp/deque.h>
 #include <libpspp/misc.h>
 #include <libpspp/str.h>
 #include <libpspp/taint.h>
 
+#include "xalloc.h"
 
 struct dataset {
   /* Cases are read from source,
@@ -55,13 +56,6 @@ struct dataset {
   struct trns_chain *temporary_trns_chain;
   struct dictionary *dict;
 
-  /* Callback which occurs when a procedure provides a new source for
-     the dataset */
-  replace_source_callback *replace_source ;
-
-  /* Callback which occurs whenever the DICT is replaced by a new one */
-  replace_dictionary_callback *replace_dict;
-
   /* Callback which occurs whenever the transformation chain(s) have
      been modified */
   transformation_change_callback_func *xform_callback;
@@ -75,9 +69,9 @@ struct dataset {
      added to. */
   struct trns_chain *cur_trns_chain;
 
-  /* The compactor used to compact a case, if necessary;
+  /* The case map used to compact a case, if necessary;
      otherwise a null pointer. */
-  struct dict_compactor *compactor;
+  struct case_map *compactor;
 
   /* Time at which proc was last invoked. */
   time_t last_proc_invocation;
@@ -174,7 +168,7 @@ proc_open (struct dataset *ds)
       size_t compacted_value_cnt = dict_count_values (pd, 1u << DC_SCRATCH);
       bool should_compact = compacted_value_cnt < dict_get_next_value_idx (pd);
       ds->compactor = (should_compact
-                       ? dict_make_compactor (pd, 1u << DC_SCRATCH)
+                       ? case_map_to_compact_dict (pd, 1u << DC_SCRATCH)
                        : NULL);
       ds->sink = autopaging_writer_create (compacted_value_cnt);
     }
@@ -258,10 +252,7 @@ proc_casereader_read (struct casereader *reader UNUSED, void *ds_,
         {
           struct ccase tmp;
           if (ds->compactor != NULL)
-            {
-              case_create (&tmp, casewriter_get_value_cnt (ds->sink));
-              dict_compactor_compact (ds->compactor, &tmp, c);
-            }
+            case_map_execute (ds->compactor, c, &tmp);
           else
             case_clone (&tmp, c);
           casewriter_write (ds->sink, &tmp);
@@ -326,7 +317,7 @@ proc_commit (struct dataset *ds)
       /* Finish compacting. */
       if (ds->compactor != NULL)
         {
-          dict_compactor_destroy (ds->compactor);
+          case_map_destroy (ds->compactor);
           ds->compactor = NULL;
 
           dict_delete_scratch_vars (ds->dict);
@@ -343,7 +334,6 @@ proc_commit (struct dataset *ds)
       ds->discard_output = false;
     }
   ds->sink = NULL;
-  if ( ds->replace_source) ds->replace_source (ds->source);
 
   caseinit_clear (ds->caseinit);
   caseinit_mark_as_preinited (ds->caseinit, ds->dict);
@@ -500,7 +490,6 @@ proc_cancel_temporary_transformations (struct dataset *ds)
       dict_destroy (ds->dict);
       ds->dict = ds->permanent_dict;
       ds->permanent_dict = NULL;
-      if (ds->replace_dict) ds->replace_dict (ds->dict);
 
       trns_chain_destroy (ds->temporary_trns_chain);
       ds->temporary_trns_chain = NULL;
@@ -534,13 +523,11 @@ proc_cancel_all_transformations (struct dataset *ds)
 \f
 /* Initializes procedure handling. */
 struct dataset *
-create_dataset (transformation_change_callback_func *cb, void *aux)
+create_dataset (void)
 {
   struct dataset *ds = xzalloc (sizeof(*ds));
   ds->dict = dict_create ();
   ds->caseinit = caseinit_create ();
-  ds->xform_callback = cb;
-  ds->xform_callback_aux = aux;
   proc_cancel_all_transformations (ds);
   return ds;
 }
@@ -591,7 +578,6 @@ proc_discard_active_file (struct dataset *ds)
 
   casereader_destroy (ds->source);
   ds->source = NULL;
-  if ( ds->replace_source) ds->replace_source (NULL);
 
   proc_cancel_all_transformations (ds);
 }
@@ -610,7 +596,6 @@ proc_set_active_file (struct dataset *ds,
 
   dict_destroy (ds->dict);
   ds->dict = dict;
-  if ( ds->replace_dict) ds->replace_dict (dict);
 
   proc_set_active_file_data (ds, source);
 }
@@ -622,7 +607,6 @@ proc_set_active_file_data (struct dataset *ds, struct casereader *reader)
 {
   casereader_destroy (ds->source);
   ds->source = reader;
-  if (ds->replace_source) ds->replace_source (reader);
 
   caseinit_clear (ds->caseinit);
   caseinit_mark_as_preinited (ds->caseinit, ds->dict);
@@ -638,6 +622,17 @@ proc_has_active_file (const struct dataset *ds)
   return ds->source != NULL;
 }
 
+/* Returns the active file data source from DS, or a null pointer
+   if DS has no data source, and removes it from DS. */
+struct casereader *
+proc_extract_active_file_data (struct dataset *ds)
+{
+  struct casereader *reader = ds->source;
+  ds->source = NULL;
+
+  return reader;
+}
+
 /* Checks whether DS has a corrupted active file.  If so,
    discards it and returns false.  If not, returns true without
    doing anything. */
@@ -669,10 +664,10 @@ static trns_free_func case_limit_trns_free;
 static void
 add_case_limit_trns (struct dataset *ds)
 {
-  size_t case_limit = dict_get_case_limit (ds->dict);
+  casenumber case_limit = dict_get_case_limit (ds->dict);
   if (case_limit != 0)
     {
-      size_t *cases_remaining = xmalloc (sizeof *cases_remaining);
+      casenumber *cases_remaining = xmalloc (sizeof *cases_remaining);
       *cases_remaining = case_limit;
       add_transformation (ds, case_limit_trns_proc, case_limit_trns_free,
                           cases_remaining);