Improve the way we handle the various parsing "states". Until now
[pspp-builds.git] / src / procedure.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 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 #if !vfm_h
21 #define vfm_h 1
22
23 #include <time.h>
24 #include <stdbool.h>
25
26 struct ccase;
27 typedef struct write_case_data *write_case_data;
28 typedef bool write_case_func (write_case_data);
29 \f
30 /* The current active file, from which cases are read. */
31 extern struct case_source *vfm_source;
32
33 /* A case source. */
34 struct case_source 
35   {
36     const struct case_source_class *class;      /* Class. */
37     void *aux;          /* Auxiliary data. */
38   };
39
40 /* A case source class. */
41 struct case_source_class
42   {
43     const char *name;                   /* Identifying name. */
44     
45     /* Returns the exact number of cases that READ will pass to
46        WRITE_CASE, if known, or -1 otherwise. */
47     int (*count) (const struct case_source *);
48
49     /* Reads the cases one by one into C and for each one calls
50        WRITE_CASE passing the given AUX data.
51        Returns true if successful, false if an I/O error occurred. */
52     bool (*read) (struct case_source *,
53                   struct ccase *c,
54                   write_case_func *write_case, write_case_data aux);
55
56     /* Destroys the source. */
57     void (*destroy) (struct case_source *);
58   };
59
60 extern const struct case_source_class storage_source_class;
61
62 struct dictionary;
63 struct case_source *create_case_source (const struct case_source_class *,
64                                         void *);
65 void free_case_source (struct case_source *);
66
67 int case_source_is_class (const struct case_source *,
68                           const struct case_source_class *);
69
70 struct casefile *storage_source_get_casefile (struct case_source *);
71 struct case_source *storage_source_create (struct casefile *);
72 \f
73 /* The replacement active file, to which cases are written. */
74 extern struct case_sink *vfm_sink;
75
76 /* A case sink. */
77 struct case_sink 
78   {
79     const struct case_sink_class *class;        /* Class. */
80     void *aux;          /* Auxiliary data. */
81     size_t value_cnt;   /* Number of `union value's in case. */
82   };
83
84 /* A case sink class. */
85 struct case_sink_class
86   {
87     const char *name;                   /* Identifying name. */
88     
89     /* Opens the sink for writing. */
90     void (*open) (struct case_sink *);
91                   
92     /* Writes a case to the sink. */
93     bool (*write) (struct case_sink *, const struct ccase *);
94     
95     /* Closes and destroys the sink. */
96     void (*destroy) (struct case_sink *);
97
98     /* Closes the sink and returns a source that can read back
99        the cases that were written, perhaps transformed in some
100        way.  The sink must still be separately destroyed by
101        calling destroy(). */
102     struct case_source *(*make_source) (struct case_sink *);
103   };
104
105 extern const struct case_sink_class storage_sink_class;
106 extern const struct case_sink_class null_sink_class;
107
108 struct case_sink *create_case_sink (const struct case_sink_class *,
109                                     const struct dictionary *,
110                                     void *);
111 void case_sink_open (struct case_sink *);
112 void case_sink_write (struct case_sink *, const struct ccase *);
113 void case_sink_destroy (struct case_sink *);
114 void free_case_sink (struct case_sink *);
115 \f
116 /* Number of cases to lag. */
117 extern int n_lag;
118
119 bool procedure (bool (*proc_func) (struct ccase *, void *aux), void *aux);
120 bool procedure_with_splits (void (*begin_func) (void *aux),
121                             bool (*proc_func) (struct ccase *, void *aux),
122                             void (*end_func) (void *aux),
123                             void *aux);
124 struct ccase *lagged_case (int n_before);
125 \f
126 bool multipass_procedure_with_splits (bool (*) (const struct casefile *,
127                                                 void *),
128                                       void *aux);
129 \f
130 time_t vfm_last_invocation (void);
131
132 #endif /* !vfm_h */