186dd6f1d09ca17721f0524630346c28d92881d3
[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     /* Returns the exact number of cases that READ will pass to
50        WRITE_CASE, if known, or -1 otherwise. */
51     int (*count) (const struct case_source *);
52
53     /* Reads all the cases and calls WRITE_CASE passing the given
54        AUX data for each one. */
55     void (*read) (struct case_source *, write_case_func *, write_case_data);
56
57     /* Destroys the source. */
58     void (*destroy) (struct case_source *);
59   };
60
61 extern const struct case_source_class memory_source_class;
62 extern const struct case_source_class disk_source_class;
63 extern const struct case_source_class data_list_source_class;
64 extern const struct case_source_class file_type_source_class;
65 extern const struct case_source_class input_program_source_class;
66 extern const struct case_source_class get_source_class;
67 extern const struct case_source_class import_source_class;
68 extern const struct case_source_class sort_source_class;
69
70 struct case_source *create_case_source (const struct case_source_class *,
71                                         void *);
72 int case_source_is_complex (const struct case_source *);
73 int case_source_is_class (const struct case_source *,
74                           const struct case_source_class *);
75 struct case_list *memory_source_get_cases (const struct case_source *);
76 void memory_source_set_cases (const struct case_source *,
77                                      struct case_list *);
78 \f
79 /* The replacement active file, to which cases are written. */
80 extern struct case_sink *vfm_sink;
81
82 /* A case sink. */
83 struct case_sink 
84   {
85     const struct case_sink_class *class;        /* Class. */
86     void *aux;                                  /* Auxiliary data. */
87   };
88
89 /* A case sink class. */
90 struct case_sink_class
91   {
92     const char *name;                   /* Identifying name. */
93     
94     /* Creates the sink and opens it for writing. */
95     void (*open) (struct case_sink *);
96                   
97     /* Writes a case to the sink. */
98     void (*write) (struct case_sink *, struct ccase *);
99     
100     /* Closes and destroys the sink. */
101     void (*destroy) (struct case_sink *);
102
103     /* Closes and destroys the sink and returns a source that can
104        read back the cases that were written, perhaps transformed
105        in some way. */
106     struct case_source *(*make_source) (struct case_sink *);
107   };
108
109 extern const struct case_sink_class memory_sink_class;
110 extern const struct case_sink_class disk_sink_class;
111 extern const struct case_sink_class sort_sink_class;
112
113 struct case_sink *create_case_sink (const struct case_sink_class *, void *);
114 \f
115 /* Number of cases to lag. */
116 extern int n_lag;
117
118 void procedure (void (*beginfunc) (void *aux),
119                 int (*procfunc) (struct ccase *curcase, void *aux),
120                 void (*endfunc) (void *aux),
121                 void *aux);
122 struct ccase *lagged_case (int n_before);
123 void compact_case (struct ccase *dest, const struct ccase *src);
124 void write_active_file_to_disk (void);
125
126 void process_active_file (void (*beginfunc) (void *),
127                           int (*casefunc) (struct ccase *curcase, void *),
128                           void (*endfunc) (void *),
129                           void *aux);
130 void process_active_file_output_case (void);
131
132 #endif /* !vfm_h */