9ba1ca9fa983da67102537eaa9df4484cd0acc7d
[pspp-builds.git] / src / data / case-source.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_SOURCE_H
21 #define CASE_SOURCE_H 1
22
23 #include <stdbool.h>
24
25 struct ccase;
26
27 typedef struct write_case_data *write_case_data;
28 typedef bool write_case_func (write_case_data);
29
30 /* A case source. */
31 struct case_source 
32   {
33     const struct case_source_class *class;      /* Class. */
34     void *aux;          /* Auxiliary data. */
35   };
36
37 /* A case source class. */
38 struct case_source_class
39   {
40     const char *name;                   /* Identifying name. */
41     
42     /* Returns the exact number of cases that READ will pass to
43        WRITE_CASE, if known, or -1 otherwise. */
44     int (*count) (const struct case_source *);
45
46     /* Reads the cases one by one into C and for each one calls
47        WRITE_CASE passing the given AUX data.
48        Returns true if successful, false if an I/O error occurred. */
49     bool (*read) (struct case_source *,
50                   struct ccase *c,
51                   write_case_func *write_case, write_case_data aux);
52
53     /* Destroys the source. */
54     void (*destroy) (struct case_source *);
55   };
56
57
58 struct case_source *create_case_source (const struct case_source_class *,
59                                         void *);
60 void free_case_source (struct case_source *);
61
62 bool case_source_is_class (const struct case_source *,
63                           const struct case_source_class *);
64
65 #endif /* case-source.h */