Change "union value" to dynamically allocate long strings.
[pspp-builds.git] / src / data / datasheet.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2007, 2009 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU 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, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef DATA_DATASHEET_H
18 #define DATA_DATASHEET_H 1
19
20 #include <data/case.h>
21 #include <data/value.h>
22
23 struct caseproto;
24 struct casereader;
25
26 /* A datasheet is a 2-d array of "union value"s that may be
27    stored in memory or on disk.  It efficiently supports data
28    storage and retrieval, as well as adding, removing, and
29    rearranging both rows and columns.  */
30
31 struct datasheet *datasheet_create (struct casereader *);
32 void datasheet_destroy (struct datasheet *);
33 struct datasheet *datasheet_rename (struct datasheet *);
34
35 const struct caseproto *datasheet_get_proto (const struct datasheet *);
36 int datasheet_get_column_width (const struct datasheet *, size_t column);
37
38 bool datasheet_error (const struct datasheet *);
39 void datasheet_force_error (struct datasheet *);
40 const struct taint *datasheet_get_taint (const struct datasheet *);
41
42 struct casereader *datasheet_make_reader (struct datasheet *);
43
44 /* Columns. */
45 size_t datasheet_get_n_columns (const struct datasheet *);
46 bool datasheet_insert_column (struct datasheet *,
47                               const union value *, int width, size_t before);
48 void datasheet_delete_columns (struct datasheet *, size_t start, size_t cnt);
49 void datasheet_move_columns (struct datasheet *,
50                              size_t old_start, size_t new_start,
51                              size_t cnt);
52 bool datasheet_resize_column (struct datasheet *, size_t column, int new_width,
53                               void (*resize_cb) (const union value *,
54                                                  union value *, void *aux),
55                               void *aux);
56
57 /* Rows. */
58 casenumber datasheet_get_n_rows (const struct datasheet *);
59 bool datasheet_insert_rows (struct datasheet *,
60                             casenumber before, struct ccase *[],
61                             casenumber cnt);
62 void datasheet_delete_rows (struct datasheet *,
63                             casenumber first, casenumber cnt);
64 void datasheet_move_rows (struct datasheet *,
65                           size_t old_start, size_t new_start,
66                           size_t cnt);
67
68 /* Data. */
69 struct ccase *datasheet_get_row (const struct datasheet *, casenumber);
70 bool datasheet_put_row (struct datasheet *, casenumber, struct ccase *);
71 bool datasheet_get_value (const struct datasheet *, casenumber, size_t column,
72                           union value *);
73 bool datasheet_put_value (struct datasheet *, casenumber, size_t column,
74                           const union value *);
75
76
77 unsigned int hash_datasheet (const struct datasheet *ds);
78 struct datasheet *clone_datasheet (const struct datasheet *ds);
79
80 #endif /* data/datasheet.h */