1 /* PSPP - computes sample statistics.
2 Copyright (C) 2007 Free Software Foundation, Inc.
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.
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.
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
19 /* Definitions needed to implement a new type of casereader.
20 Code that only uses casereaders does not need this header.
22 Two functions to create casereaders are supplied:
24 - casereader_create_sequential, to create a casereader
25 for a data source that is naturally sequential. The
26 casereader layer will automatically, as needed,
27 simulate the ability to access cases randomly.
29 - casereader_create_random, to create a casereader for a
30 data source that supports random access to cases. (This
31 function is in fact implemented as a set of wrappers
32 around casereader_create_sequential.)
34 Which function is used has no effect on the set of operations
35 that may be performed on the resulting casereader, only on how
36 the casereader is implemented internally. */
38 #ifndef DATA_CASEREADER_PROVIDER_H
39 #define DATA_CASEREADER_PROVIDER_H 1
41 #include <data/casereader.h>
43 /* Casereader class for sequential data sources. */
44 struct casereader_class
48 Reads the next case from READER into case C, which the
49 casereader must create and which the client is responsible
50 for destroying. If successful, returns true and advances
51 READER to the next case, so that the next call to this
52 function will read the next case. The case just read will
53 never be read again by a call to this function for READER.
55 At end of file or upon an I/O error, returns false. After
56 false is returned once, this function will not be called
57 again for the given READER.
59 If an I/O error occurs, this function should call
60 casereader_force_error on READER. */
61 bool (*read) (struct casereader *reader, void *aux, struct ccase *c);
67 If an I/O error is detected during destruction, this
68 function should call casereader_force_error on READER. */
69 void (*destroy) (struct casereader *reader, void *aux);
71 /* Optional: if convenient and efficiently implementable,
72 supply this function as an optimization for use by
73 casereader_clone. (But it might be easier to use the
74 random-access casereader wrapper instead.)
76 Creates and returns a clone of READER. The clone must
77 read the same case data in the same sequence as READER,
78 starting from the same position. The only allowable
79 exception to this rule is that I/O errors may force the
80 clone or the original casereader to stop reading after
81 differing numbers of cases.
83 The clone should have a clone of READER's taint object,
84 accomplished by passing casereader_get_taint (READER) to
86 struct casereader *(*clone) (struct casereader *reader, void *aux);
88 /* Optional: if convenient and efficiently implementable,
89 supply as an optimization for use by casereader_peek.
90 (But it might be easier to use the random-access
91 casereader wrapper instead.)
93 Reads the case at 0-based offset IDX from the beginning of
94 READER into case C, which the casereader must create and
95 which the client is responsible for destroying.
97 At end of file or upon an I/O error, returns false. If
98 this function returns false, then it will never be called
99 again for an equal or greater value of IDX, and the "read"
100 member function will never be called to advance as far as
101 IDX cases further into the casereader. That is, returning
102 false indicates that the casereader has fewer than IDX
105 If an I/O error occurs, this function should call
106 casereader_force_error on READER. */
107 bool (*peek) (struct casereader *reader, void *aux, casenumber idx,
112 casereader_create_sequential (const struct taint *,
113 size_t value_cnt, casenumber case_cnt,
114 const struct casereader_class *, void *);
116 /* Casereader class for random-access data sources. */
117 struct casereader_random_class
121 Reads the case at 0-based offset IDX from the beginning of
122 READER into case C, which the casereader must create and
123 which the client is responsible for destroying.
125 At end of file or upon an I/O error, returns false. If
126 this function returns false, then it will never be called
127 again for an equal or greater value of IDX, and the "read"
128 member function will never be called to advance as far as
129 IDX cases further into the casereader. That is, returning
130 false indicates that the casereader has fewer than IDX
133 If an I/O error occurs, this function should call
134 casereader_force_error on READER. */
135 bool (*read) (struct casereader *reader, void *aux, casenumber idx,
142 If an I/O error is detected during destruction, this
143 function should call casereader_force_error on READER. */
144 void (*destroy) (struct casereader *reader, void *aux);
148 A call to this function tells the callee that the CNT
149 cases at the beginning of READER will never be read again.
150 The casereader implementation should free any resources
151 associated with those cases. After this function returns,
152 the IDX argument in future calls to the "read" function
153 will be relative to remaining cases. */
154 void (*advance) (struct casereader *reader, void *aux, casenumber cnt);
158 casereader_create_random (size_t value_cnt, casenumber case_cnt,
159 const struct casereader_random_class *, void *aux);
161 #endif /* data/casereader-provider.h */