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