X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fcasewriter-translator.c;h=e80b9d68187b3f65e33b35051b0b6d891ca5f312;hb=5c3291dc396b795696e94f47780308fd7ace6fc4;hp=79694a4609469f6deee93f9eccfab44212ef7ef6;hpb=0553d00dca10c2d2beeffd88fd12120e43a01025;p=pspp-builds.git diff --git a/src/data/casewriter-translator.c b/src/data/casewriter-translator.c index 79694a46..e80b9d68 100644 --- a/src/data/casewriter-translator.c +++ b/src/data/casewriter-translator.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,18 +29,24 @@ struct casewriter_translator { struct casewriter *subwriter; - void (*translate) (struct ccase *input, struct ccase *output, void *aux); + struct ccase *(*translate) (struct ccase *, void *aux); bool (*destroy) (void *aux); void *aux; }; -static struct casewriter_class casewriter_translator_class; +static const struct casewriter_class casewriter_translator_class; /* Creates and returns a new casewriter whose cases are passed - through TRANSLATE, which must create case OUTPUT, with - OUTPUT_VALUE_CNT values, and populate it based on INPUT and - auxiliary data AUX. The translated cases are then written to - SUBWRITER. TRANSLATE must also destroy INPUT. + through TRANSLATE, based on INPUT and auxiliary data AUX. + (TRANSLATE may also return a null pointer, in which case no + case is written to the output.) The translated cases are then + written to SUBWRITER. + + The cases returned by TRANSLATE must match OUTPUT_PROTO. + + TRANSLATE takes ownership of each case passed to it. Thus, it + should either unref each case and return a new case, or + (unshare and then) modify and return the same case. When the translating casewriter is destroyed, DESTROY will be called to allow any state maintained by TRANSLATE to be freed. @@ -50,10 +56,9 @@ static struct casewriter_class casewriter_translator_class; when the translating casewriter is destroyed. */ struct casewriter * casewriter_create_translator (struct casewriter *subwriter, - size_t translated_value_cnt, - void (*translate) (struct ccase *input, - struct ccase *output, - void *aux), + const struct caseproto *translated_proto, + struct ccase *(*translate) (struct ccase *, + void *aux), bool (*destroy) (void *aux), void *aux) { @@ -63,7 +68,7 @@ casewriter_create_translator (struct casewriter *subwriter, ct->translate = translate; ct->destroy = destroy; ct->aux = aux; - writer = casewriter_create (translated_value_cnt, + writer = casewriter_create (translated_proto, &casewriter_translator_class, ct); taint_propagate (casewriter_get_taint (ct->subwriter), casewriter_get_taint (writer)); @@ -75,10 +80,9 @@ casewriter_translator_write (struct casewriter *writer UNUSED, void *ct_, struct ccase *c) { struct casewriter_translator *ct = ct_; - struct ccase tmp; - - ct->translate (c, &tmp, ct->aux); - casewriter_write (ct->subwriter, &tmp); + c = ct->translate (c, ct->aux); + if (c != NULL) + casewriter_write (ct->subwriter, c); } static void @@ -101,7 +105,7 @@ casewriter_translator_convert_to_reader (struct casewriter *writer UNUSED, return reader; } -static struct casewriter_class casewriter_translator_class = +static const struct casewriter_class casewriter_translator_class = { casewriter_translator_write, casewriter_translator_destroy,