Beginning of VFM cleanup.
[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., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #if !vfm_h
21 #define vfm_h 1
22
23 #include <time.h>
24
25 /* This is the time at which vfm was last invoked. */
26 extern time_t last_vfm_invocation;
27
28 /* This is the case that is to be filled in by input programs. */
29 extern struct ccase *temp_case;
30
31 typedef struct write_case_data *write_case_data;
32 typedef int write_case_func (write_case_data);
33 \f
34 /* The current active file, from which cases are read. */
35 extern struct case_source *vfm_source;
36
37 /* A case source. */
38 struct case_source 
39   {
40     const struct case_source_class *class;      /* Class. */
41     void *aux;                                  /* Auxiliary data. */
42   };
43
44 /* A case source class. */
45 struct case_source_class
46   {
47     const char *name;                   /* Identifying name. */
48     
49     /* Reads all the cases and calls WRITE_CASE passing the given
50        AUX data for each one. */
51     void (*read) (struct case_source *, write_case_func *, write_case_data);
52
53     /* Destroys the source. */
54     void (*destroy) (struct case_source *);
55   };
56
57 extern const struct case_source_class memory_source_class;
58 extern const struct case_source_class disk_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 case_source *create_case_source (const struct case_source_class *,
67                                         void *);
68 int case_source_is_complex (const struct case_source *);
69 int case_source_is_class (const struct case_source *,
70                           const struct case_source_class *);
71 struct case_list *memory_source_get_cases (const struct case_source *);
72 void memory_source_set_cases (const struct case_source *,
73                                      struct case_list *);
74 \f
75 /* The replacement active file, to which cases are written. */
76 extern struct case_sink *vfm_sink;
77
78 /* A case sink. */
79 struct case_sink 
80   {
81     const struct case_sink_class *class;        /* Class. */
82     void *aux;                                  /* Auxiliary data. */
83   };
84
85 /* A case sink class. */
86 struct case_sink_class
87   {
88     const char *name;                   /* Identifying name. */
89     
90     /* Creates the sink and opens it for writing. */
91     void (*open) (struct case_sink *);
92                   
93     /* Writes a case to the sink. */
94     void (*write) (struct case_sink *, struct ccase *);
95     
96     /* Closes and destroys the sink. */
97     void (*destroy) (struct case_sink *);
98
99     /* Closes and destroys the sink and returns a source that can
100        read back the cases that were written, perhaps transformed
101        in some way. */
102     struct case_source *(*make_source) (struct case_sink *);
103   };
104
105 extern const struct case_sink_class memory_sink_class;
106 extern const struct case_sink_class disk_sink_class;
107 extern const struct case_sink_class sort_sink_class;
108
109 struct case_sink *create_case_sink (const struct case_sink_class *, void *);
110 \f
111 /* Number of cases to lag. */
112 extern int n_lag;
113
114 void procedure (void (*beginfunc) (void *aux),
115                 int (*procfunc) (struct ccase *curcase, void *aux),
116                 void (*endfunc) (void *aux),
117                 void *aux);
118 struct ccase *lagged_case (int n_before);
119 void compact_case (struct ccase *dest, const struct ccase *src);
120 void write_active_file_to_disk (void);
121
122 void process_active_file (void (*beginfunc) (void *),
123                           int (*casefunc) (struct ccase *curcase, void *),
124                           void (*endfunc) (void *),
125                           void *aux);
126 void process_active_file_output_case (void);
127
128 #endif /* !vfm_h */