X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fcasewriter.c;h=eac02b16865e5b9348a3575af03e819982070114;hb=a1d8ce0ad176357cf250ec065e0bf1a4520a19e3;hp=9931b403741c12759270155db5c110e9c33e8875;hpb=f5c108becd49d78f4898cab11352291f5689d24e;p=pspp-builds.git diff --git a/src/data/casewriter.c b/src/data/casewriter.c index 9931b403..eac02b16 100644 --- a/src/data/casewriter.c +++ b/src/data/casewriter.c @@ -1,20 +1,18 @@ -/* PSPP - computes sample statistics. +/* PSPP - a program for statistical analysis. Copyright (C) 2007 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 @@ -37,6 +35,7 @@ struct casewriter { struct taint *taint; + size_t value_cnt; casenumber case_cnt; const struct casewriter_class *class; void *aux; @@ -49,6 +48,7 @@ static struct casewriter *create_casewriter_window (size_t value_cnt, void casewriter_write (struct casewriter *writer, struct ccase *c) { + assert (case_get_value_cnt (c) >= writer->value_cnt); writer->class->write (writer, writer->aux, c); } @@ -69,6 +69,14 @@ casewriter_destroy (struct casewriter *writer) return ok; } +/* Returns the number of `union value's in each case written to + WRITER. */ +size_t +casewriter_get_value_cnt (const struct casewriter *writer) +{ + return writer->value_cnt; +} + /* Destroys WRITER and in its place returns a casereader that can be used to read back the data written to WRITER. WRITER must not be used again after calling this function, even as an @@ -135,12 +143,15 @@ casewriter_get_taint (const struct casewriter *writer) } /* Creates and returns a new casewriter with the given CLASS and - auxiliary data AUX. */ + auxiliary data AUX. The casewriter accepts cases with + VALUE_CNT `union value's. */ struct casewriter * -casewriter_create (const struct casewriter_class *class, void *aux) +casewriter_create (size_t value_cnt, + const struct casewriter_class *class, void *aux) { struct casewriter *writer = xmalloc (sizeof *writer); writer->taint = taint_create (); + writer->value_cnt = value_cnt; writer->case_cnt = 0; writer->class = class; writer->aux = aux; @@ -198,7 +209,8 @@ static struct casewriter * create_casewriter_window (size_t value_cnt, casenumber max_in_core_cases) { struct casewindow *window = casewindow_create (value_cnt, max_in_core_cases); - struct casewriter *writer = casewriter_create (&casewriter_window_class, + struct casewriter *writer = casewriter_create (value_cnt, + &casewriter_window_class, window); taint_propagate (casewindow_get_taint (window), casewriter_get_taint (writer));