d1d6daeb52261a9c730cd82c2f8c61e41c438ac4
[pspp-builds.git] / src / data / case-sink.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #ifndef CASE_SINK_H
21 #define CASE_SINK_H 1
22
23 #include <stdbool.h>
24 #include <stddef.h>
25
26 struct ccase;
27 struct dictionary;
28
29 /* A case sink. */
30 struct case_sink 
31   {
32     const struct case_sink_class *class;        /* Class. */
33     void *aux;          /* Auxiliary data. */
34     size_t value_cnt;   /* Number of `union value's in case. */
35   };
36
37 /* A case sink class. */
38 struct case_sink_class
39   {
40     const char *name;                   /* Identifying name. */
41     
42     /* Opens the sink for writing. */
43     void (*open) (struct case_sink *);
44                   
45     /* Writes a case to the sink. */
46     bool (*write) (struct case_sink *, const struct ccase *);
47     
48     /* Closes and destroys the sink. */
49     void (*destroy) (struct case_sink *);
50
51     /* Closes the sink and returns a source that can read back
52        the cases that were written, perhaps transformed in some
53        way.  The sink must still be separately destroyed by
54        calling destroy(). */
55     struct case_source *(*make_source) (struct case_sink *);
56   };
57
58 extern const struct case_sink_class null_sink_class;
59
60 struct case_sink *create_case_sink (const struct case_sink_class *,
61                                     const struct dictionary *,
62                                     void *);
63 void free_case_sink (struct case_sink *);
64
65 #endif /* case-sink.h */