dd47dcd41ac19bbc6cb53f9c874c3ed7e697c958
[pspp-builds.git] / src / data / datasheet.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2007 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 #ifndef DATA_DATASHEET_H
20 #define DATA_DATASHEET_H 1
21
22 #include <data/case.h>
23 #include <data/value.h>
24
25 struct casereader;
26
27 /* A datasheet is a 2-d array of data that may be stored in
28    memory or on disk.  It efficiently supports data storage and
29    retrieval, as well as adding, removing, and rearranging both
30    rows and columns.  */
31
32 struct datasheet *datasheet_create (struct casereader *);
33 void datasheet_destroy (struct datasheet *);
34 struct datasheet *datasheet_rename (struct datasheet *);
35
36 bool datasheet_error (const struct datasheet *);
37 void datasheet_force_error (struct datasheet *);
38 const struct taint *datasheet_get_taint (const struct datasheet *);
39
40 struct casereader *datasheet_make_reader (struct datasheet *);
41
42 /* Columns. */
43 size_t datasheet_get_column_cnt (const struct datasheet *);
44 bool datasheet_insert_columns (struct datasheet *,
45                                const union value[], size_t cnt,
46                                size_t before);
47 void datasheet_delete_columns (struct datasheet *, size_t start, size_t cnt);
48 void datasheet_move_columns (struct datasheet *,
49                              size_t old_start, size_t new_start,
50                              size_t cnt);
51
52 /* Rows. */
53 casenumber datasheet_get_row_cnt (const struct datasheet *);
54 bool datasheet_insert_rows (struct datasheet *,
55                             casenumber before, struct ccase[],
56                             casenumber cnt);
57 void datasheet_delete_rows (struct datasheet *,
58                             casenumber first, casenumber cnt);
59 void datasheet_move_rows (struct datasheet *,
60                           size_t old_start, size_t new_start,
61                           size_t cnt);
62
63 /* Data. */
64 bool datasheet_get_row (const struct datasheet *, casenumber, struct ccase *);
65 bool datasheet_put_row (struct datasheet *, casenumber, struct ccase *);
66 bool datasheet_get_value (const struct datasheet *, casenumber, size_t column,
67                           union value *, int width);
68 bool datasheet_put_value (struct datasheet *, casenumber, size_t column,
69                           const union value *, int width);
70
71 /* Testing. */
72 struct mc_options;
73
74 struct datasheet_test_params
75   {
76     /* Parameters. */
77     int max_rows;
78     int max_cols;
79     int backing_rows;
80     int backing_cols;
81
82     /* State. */
83     int next_value;
84   };
85
86 struct mc_results *datasheet_test (struct mc_options *options, void *params);
87
88 #endif /* data/datasheet.h */