X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fdata%2Fcasewriter-translator.c;h=c750c7c73b21f69cdfd852bebfb4b7d3de39d40e;hb=a22595e846a457b5d51ae0fa358784d777eac706;hp=0f47f76ba83f3c6b494916768299be8cacdb436c;hpb=ed88deded6a59254dd55883308c4c20966efc77e;p=pspp
diff --git a/src/data/casewriter-translator.c b/src/data/casewriter-translator.c
index 0f47f76ba8..c750c7c73b 100644
--- a/src/data/casewriter-translator.c
+++ b/src/data/casewriter-translator.c
@@ -1,51 +1,66 @@
-/* PSPP - computes sample statistics.
- Copyright (C) 2007 Free Software Foundation, Inc.
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 2007, 2009, 2011 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 the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see . */
#include
-#include
-#include
+#include "data/casewriter.h"
+#include "data/casewriter-provider.h"
#include
-#include
+#include "libpspp/taint.h"
-#include "xalloc.h"
+#include "gl/xalloc.h"
struct casewriter_translator
{
struct casewriter *subwriter;
- void (*translate) (const 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, 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.
+
+ After this function is called, SUBWRITER must not ever again
+ be referenced directly. It will be destroyed automatically
+ when the translating casewriter is destroyed. */
struct casewriter *
casewriter_create_translator (struct casewriter *subwriter,
- void (*translate) (const 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)
+ void *aux)
{
struct casewriter_translator *ct = xmalloc (sizeof *ct);
struct casewriter *writer;
@@ -53,7 +68,8 @@ casewriter_create_translator (struct casewriter *subwriter,
ct->translate = translate;
ct->destroy = destroy;
ct->aux = aux;
- writer = casewriter_create (&casewriter_translator_class, ct);
+ writer = casewriter_create (translated_proto,
+ &casewriter_translator_class, ct);
taint_propagate (casewriter_get_taint (ct->subwriter),
casewriter_get_taint (writer));
return writer;
@@ -61,17 +77,16 @@ casewriter_create_translator (struct casewriter *subwriter,
static void
casewriter_translator_write (struct casewriter *writer UNUSED,
- void *ct_, struct ccase *c)
+ 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
-casewriter_translator_destroy (struct casewriter *writer UNUSED, void *ct_)
+casewriter_translator_destroy (struct casewriter *writer UNUSED, void *ct_)
{
struct casewriter_translator *ct = ct_;
casewriter_destroy (ct->subwriter);
@@ -90,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,