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