X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fcase-map.c;h=8d309580acca22bcaa811acccf8fe85963369523;hb=354747add9edd5203365db70f7ffa282621a0a08;hp=7a91f497ca9e66f7f5c76fbf9a5d5cd1653b016a;hpb=fd97d8bee5b125aa9d82d3a46685aac21282c051;p=pspp-builds.git diff --git a/src/data/case-map.c b/src/data/case-map.c index 7a91f497..8d309580 100644 --- a/src/data/case-map.c +++ b/src/data/case-map.c @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include #include @@ -36,6 +38,9 @@ struct case_map corresponding source index. */ }; +static void translate_case (struct ccase *, struct ccase *, void *map_); +static bool destroy_case_map (void *map_); + /* Creates and returns an empty map. */ static struct case_map * create_case_map (size_t n) @@ -102,6 +107,63 @@ case_map_get_value_cnt (const struct case_map *map) return map->value_cnt; } +/* Creates and returns a new casereader whose cases are produced + by reading from SUBREADER and executing the actions of MAP. + The casereader will have as many `union value's as MAP. When + the new casereader is destroyed, MAP will be destroyed too. + + After this function is called, SUBREADER must not ever again + be referenced directly. It will be destroyed automatically + when the returned casereader is destroyed. */ +struct casereader * +case_map_create_input_translator (struct case_map *map, + struct casereader *subreader) +{ + return casereader_create_translator (subreader, + case_map_get_value_cnt (map), + translate_case, + destroy_case_map, + map); +} + +/* Creates and returns a new casewriter. Cases written to the + new casewriter will be passed through MAP and written to + SUBWRITER. The casewriter will have as many `union value's as + MAP. When the new casewriter is destroyed, MAP will be + destroyed too. + + After this function is called, SUBWRITER must not ever again + be referenced directly. It will be destroyed automatically + when the returned casewriter is destroyed. */ +struct casewriter * +case_map_create_output_translator (struct case_map *map, + struct casewriter *subwriter) +{ + return casewriter_create_translator (subwriter, + case_map_get_value_cnt (map), + translate_case, + destroy_case_map, + map); +} + +/* Casereader/casewriter translation callback. */ +static void +translate_case (struct ccase *input, struct ccase *output, void *map_) +{ + struct case_map *map = map_; + case_map_execute (map, input, output); + case_destroy (input); +} + +/* Casereader/casewriter destruction callback. */ +static bool +destroy_case_map (void *map_) +{ + struct case_map *map = map_; + case_map_destroy (map); + return true; +} + /* Creates and returns a case_map that can be used to compact cases for dictionary D.