This fit the usage model in every case in practice.
/* Prepares and returns a "struct case_map_stage" for producing a case map for
DICT. Afterward, the caller may delete, reorder, or rename variables within
- DICT at will before using case_map_stage_get_case_map() to produce the case
+ DICT at will before using case_map_stage_to_case_map() to produce the case
map.
The caller must *not* add new variables to DICT. */
NOT_REACHED ();
}
-/* Produces a case map from STAGE, which must have been previously created with
- case_map_stage_create(). The case map maps from the original case index of
- the variables in STAGE's dictionary to their current case indexes.
-
- Returns the new case map, or a null pointer if no mapping is required (that
- is, no variables were deleted or reordered). */
-struct case_map *
+static struct case_map *
case_map_stage_get_case_map (const struct case_map_stage *stage)
{
size_t n_vars = dict_get_n_vars (stage->dict);
return map;
}
+/* Produces a case map from STAGE, which must have been previously created with
+ case_map_stage_create(). The case map maps from the original case index of
+ the variables in STAGE's dictionary to their current case indexes.
+
+ Returns the new case map, or a null pointer if no mapping is required (that
+ is, no variables were deleted or reordered).
+
+ Destroys STAGE. */
+struct case_map *
+case_map_stage_to_case_map (struct case_map_stage *stage)
+{
+ struct case_map *map = case_map_stage_get_case_map (stage);
+ case_map_stage_destroy (stage);
+ return map;
+}
+
/* Creates and returns a case map for mapping variables in OLD to
variables in NEW based on their name. For every variable in
NEW, there must be a variable in OLD with the same name, type,
a modified version of the same dictionary. */
struct case_map_stage *case_map_stage_create (const struct dictionary *);
void case_map_stage_destroy (struct case_map_stage *);
-struct case_map *case_map_stage_get_case_map (const struct case_map_stage *);
+struct case_map *case_map_stage_to_case_map (struct case_map_stage *);
/* For mapping cases for one dictionary to another based on
variable names within the dictionary. */
struct dataset *ds; /* Underlying dataset. */
struct fh_lock *lock; /* Exclusive access to file handle. */
struct dictionary *dict; /* Dictionary for subwriter. */
- struct case_map *compactor; /* Compacts into dictionary. */
struct casewriter *subwriter; /* Data output. */
};
writer->dict = dict_clone (dictionary);
struct case_map_stage *stage = case_map_stage_create (writer->dict);
dict_delete_scratch_vars (writer->dict);
- writer->compactor = case_map_stage_get_case_map (stage);
- case_map_stage_destroy (stage);
- writer->subwriter = autopaging_writer_create (dict_get_proto (writer->dict));
+ writer->subwriter = case_map_create_output_translator (
+ case_map_stage_to_case_map (stage),
+ autopaging_writer_create (dict_get_proto (writer->dict)));
casewriter = casewriter_create (dict_get_proto (writer->dict),
&dataset_writer_casewriter_class, writer);
struct ccase *c)
{
struct dataset_writer *writer = writer_;
- casewriter_write (writer->subwriter,
- case_map_execute (writer->compactor, c));
+ casewriter_write (writer->subwriter, c);
}
/* Closes WRITER. */
struct case_map_stage *stage = case_map_stage_create (ds->dict);
dict_delete_vars (ds->dict, vars, n);
ds->source = case_map_create_input_translator (
- case_map_stage_get_case_map (stage), ds->source);
- case_map_stage_destroy (stage);
+ case_map_stage_to_case_map (stage), ds->source);
caseinit_clear (ds->caseinit);
caseinit_mark_as_preinited (ds->caseinit, ds->dict);
}
struct case_map_stage *stage = case_map_stage_create (ds->dict);
dict_reorder_vars (ds->dict, vars, n);
ds->source = case_map_create_input_translator (
- case_map_stage_get_case_map (stage), ds->source);
- case_map_stage_destroy (stage);
+ case_map_stage_to_case_map (stage), ds->source);
caseinit_clear (ds->caseinit);
caseinit_mark_as_preinited (ds->caseinit, ds->dict);
}
struct case_map_stage *stage = case_map_stage_create (pd);
dict_delete_scratch_vars (pd);
ds->sink = case_map_create_output_translator (
- case_map_stage_get_case_map (stage),
+ case_map_stage_to_case_map (stage),
autopaging_writer_create (dict_get_proto (pd)));
- case_map_stage_destroy (stage);
dict_unref (pd);
}
else
goto error;
}
- map = case_map_stage_get_case_map (stage);
- case_map_stage_destroy (stage);
+ map = case_map_stage_to_case_map (stage);
if (map != NULL)
reader = case_map_create_input_translator (map, reader);
goto error;
fh_unref (handle);
- struct case_map *map = case_map_stage_get_case_map (stage);
- case_map_stage_destroy (stage);
- if (map != NULL)
- writer = case_map_create_output_translator (map, writer);
+ writer = case_map_create_output_translator (
+ case_map_stage_to_case_map (stage), writer);
dict_unref (dict);
casereader_transfer (proc_open_filtering (ds, !retain_unselected), writer);
goto error;
}
- map = case_map_stage_get_case_map (stage);
- case_map_stage_destroy (stage);
- if (map != NULL)
- writer = case_map_create_output_translator (map, writer);
+ writer = case_map_create_output_translator (
+ case_map_stage_to_case_map (stage), writer);
dict_unref (dict);
fh_unref (handle);
}
reader = case_map_create_input_translator (
- case_map_stage_get_case_map (stage), reader);
- case_map_stage_destroy (stage);
+ case_map_stage_to_case_map (stage), reader);
if (!strcmp (output_format, "csv") || !strcmp (output_format, "txt"))
{