8298af465da9d88640fe813f6a12309c6effd036
[pspp-builds.git] / src / data / casewriter-provider.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2006 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #ifndef DATA_CASEWRITER_PROVIDER_H
18 #define DATA_CASEWRITER_PROVIDER_H 1
19
20 #include <data/casewriter.h>
21
22 struct casewriter_class
23   {
24     /* Mandatory.
25
26        Writes case C to WRITER.  Destroys C before returning.
27
28        If an I/O error occurs, this function should call
29        casewriter_force_error on WRITER.  Some I/O error
30        detection may be deferred to the "destroy" member function
31        (e.g. writes to disk need not be flushed by "write") . */
32     void (*write) (struct casewriter *writer, void *aux, struct ccase *c);
33
34     /* Mandatory.
35
36        Finalizes output and destroys WRITER.
37
38        If an I/O error is detected while finalizing output
39        (e.g. while flushing output to disk), this function should
40        call casewriter_force_error on WRITER. */
41     void (*destroy) (struct casewriter *writer, void *aux);
42
43     /* Optional: supply if practical and desired by clients.
44
45        Finalizes output to WRITER, destroys WRITER, and in its
46        place returns a casereader that can be used to read back
47        the data written to WRITER.  WRITER will not be used again
48        after calling this function, even as an argument to
49        casewriter_destroy.
50
51        If an I/O error is detected while finalizing output
52        (e.g. while flushing output to disk), this function should
53        call casewriter_force_error on WRITER.  The caller will
54        ensure that the error is propagated to the returned
55        casereader. */
56     struct casereader *(*convert_to_reader) (struct casewriter *, void *aux);
57   };
58
59 struct casewriter *casewriter_create (size_t value_cnt,
60                                       const struct casewriter_class *, void *);
61
62 #endif /* data/casewriter-provider.h */