1 /* PSPP - computes sample statistics.
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <data/casereader.h>
25 #include <data/casereader-provider.h>
26 #include <libpspp/taint.h>
30 struct casereader_translator
32 struct casereader *subreader;
34 void (*translate) (const struct ccase *input, struct ccase *output,
36 bool (*destroy) (void *aux);
40 static struct casereader_class casereader_translator_class;
43 casereader_create_translator (struct casereader *subreader,
44 size_t output_value_cnt,
45 void (*translate) (const struct ccase *input,
48 bool (*destroy) (void *aux),
51 struct casereader_translator *ct = xmalloc (sizeof *ct);
52 struct casereader *reader;
53 ct->subreader = casereader_rename (subreader);
54 ct->translate = translate;
55 ct->destroy = destroy;
57 reader = casereader_create_sequential (
58 NULL, output_value_cnt, casereader_get_case_cnt (ct->subreader),
59 &casereader_translator_class, ct);
60 taint_propagate (casereader_get_taint (ct->subreader),
61 casereader_get_taint (reader));
66 casereader_translator_read (struct casereader *reader UNUSED,
67 void *ct_, struct ccase *c)
69 struct casereader_translator *ct = ct_;
72 if (casereader_read (ct->subreader, &tmp))
74 ct->translate (&tmp, c, ct->aux);
82 casereader_translator_destroy (struct casereader *reader UNUSED, void *ct_)
84 struct casereader_translator *ct = ct_;
85 casereader_destroy (ct->subreader);
86 ct->destroy (ct->aux);
90 static struct casereader_class casereader_translator_class =
92 casereader_translator_read,
93 casereader_translator_destroy,