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