1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU 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, see <http://www.gnu.org/licenses/>. */
19 #include <data/casewriter.h>
20 #include <data/casewriter-provider.h>
24 #include <libpspp/taint.h>
28 struct casewriter_translator
30 struct casewriter *subwriter;
32 void (*translate) (const struct ccase *input, struct ccase *output,
34 bool (*destroy) (void *aux);
38 static struct casewriter_class casewriter_translator_class;
41 casewriter_create_translator (struct casewriter *subwriter,
42 size_t translated_value_cnt,
43 void (*translate) (const struct ccase *input,
46 bool (*destroy) (void *aux),
49 struct casewriter_translator *ct = xmalloc (sizeof *ct);
50 struct casewriter *writer;
51 ct->subwriter = casewriter_rename (subwriter);
52 ct->translate = translate;
53 ct->destroy = destroy;
55 writer = casewriter_create (translated_value_cnt,
56 &casewriter_translator_class, ct);
57 taint_propagate (casewriter_get_taint (ct->subwriter),
58 casewriter_get_taint (writer));
63 casewriter_translator_write (struct casewriter *writer UNUSED,
64 void *ct_, struct ccase *c)
66 struct casewriter_translator *ct = ct_;
69 ct->translate (c, &tmp, ct->aux);
70 casewriter_write (ct->subwriter, &tmp);
74 casewriter_translator_destroy (struct casewriter *writer UNUSED, void *ct_)
76 struct casewriter_translator *ct = ct_;
77 casewriter_destroy (ct->subwriter);
78 ct->destroy (ct->aux);
82 static struct casereader *
83 casewriter_translator_convert_to_reader (struct casewriter *writer UNUSED,
86 struct casewriter_translator *ct = ct_;
87 struct casereader *reader = casewriter_make_reader (ct->subwriter);
89 ct->destroy (ct->aux);
93 static struct casewriter_class casewriter_translator_class =
95 casewriter_translator_write,
96 casewriter_translator_destroy,
97 casewriter_translator_convert_to_reader,