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