Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / data / dictionary.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004, 2007 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 DICTIONARY_H
18 #define DICTIONARY_H
19
20 #include <stdbool.h>
21 #include <stddef.h>
22
23 /* Dictionary. */
24
25 struct variable;
26 struct dictionary;
27 struct string;
28
29 struct dict_callbacks
30  {
31   void (*var_added) (struct dictionary *, int, void *);
32   void (*var_deleted) (struct dictionary *, int, void *);
33   void (*var_changed) (struct dictionary *, int, void *);
34   void (*weight_changed) (struct dictionary *, int, void *);
35   void (*filter_changed) (struct dictionary *, int, void *);
36   void (*split_changed) (struct dictionary *, void *);
37  };
38
39
40 struct dictionary *dict_create (void);
41 struct dictionary *dict_clone (const struct dictionary *);
42 void dict_set_callbacks (struct dictionary *, const struct dict_callbacks *,
43                          void *);
44 void dict_copy_callbacks (struct dictionary *, const struct dictionary *);
45
46
47 void dict_clear (struct dictionary *);
48 void dict_clear_aux (struct dictionary *);
49 void dict_destroy (struct dictionary *);
50
51 size_t dict_get_var_cnt (const struct dictionary *);
52 struct variable *dict_get_var (const struct dictionary *, size_t idx);
53 inline void dict_get_vars (const struct dictionary *,
54                     const struct variable ***vars, size_t *cnt,
55                     unsigned exclude_classes);
56 void dict_get_vars_mutable (const struct dictionary *,
57                     struct variable ***vars, size_t *cnt,
58                     unsigned exclude_classes);
59
60 struct variable *dict_create_var (struct dictionary *, const char *,
61                                   int width);
62
63 struct variable *dict_create_var_assert (struct dictionary *, const char *,
64                                   int width);
65 struct variable *dict_clone_var (struct dictionary *, const struct variable *,
66                                  const char *);
67 struct variable *dict_clone_var_assert (struct dictionary *,
68                                         const struct variable *, const char *);
69
70 struct variable *dict_lookup_var (const struct dictionary *, const char *);
71 struct variable *dict_lookup_var_assert (const struct dictionary *,
72                                          const char *);
73 bool dict_contains_var (const struct dictionary *, const struct variable *);
74 void dict_delete_var (struct dictionary *, struct variable *);
75 void dict_delete_vars (struct dictionary *,
76                        struct variable *const *, size_t count);
77 void dict_delete_consecutive_vars (struct dictionary *d,
78                                    size_t idx, size_t count);
79 void dict_delete_scratch_vars (struct dictionary *);
80 void dict_reorder_var (struct dictionary *d, struct variable *v,
81                        size_t new_index);
82 void dict_reorder_vars (struct dictionary *,
83                         struct variable *const *, size_t count);
84 void dict_rename_var (struct dictionary *, struct variable *, const char *);
85 bool dict_rename_vars (struct dictionary *,
86                        struct variable **, char **new_names,
87                        size_t count, char **err_name);
88
89 struct ccase;
90 struct variable *dict_get_weight (const struct dictionary *);
91 double dict_get_case_weight (const struct dictionary *,
92                              const struct ccase *, bool *);
93 void dict_set_weight (struct dictionary *, struct variable *);
94
95 struct variable *dict_get_filter (const struct dictionary *);
96 void dict_set_filter (struct dictionary *, struct variable *);
97
98 size_t dict_get_case_limit (const struct dictionary *);
99 void dict_set_case_limit (struct dictionary *, size_t);
100
101 int dict_get_next_value_idx (const struct dictionary *);
102 size_t dict_get_case_size (const struct dictionary *);
103
104 void dict_compact_values (struct dictionary *);
105 size_t dict_get_compacted_value_cnt (const struct dictionary *);
106 int *dict_get_compacted_dict_index_to_case_index (const struct dictionary *);
107 bool dict_compacting_would_shrink (const struct dictionary *);
108 bool dict_compacting_would_change (const struct dictionary *);
109
110 struct dict_compactor *dict_make_compactor (const struct dictionary *);
111 void dict_compactor_compact (const struct dict_compactor *,
112                              struct ccase *, const struct ccase *);
113 void dict_compactor_destroy (struct dict_compactor *);
114
115 const struct variable *const *dict_get_split_vars (const struct dictionary *);
116 size_t dict_get_split_cnt (const struct dictionary *);
117 void dict_set_split_vars (struct dictionary *,
118                           struct variable *const *, size_t cnt);
119 void dict_unset_split_var (struct dictionary *d,
120                            struct variable *v);
121
122 const char *dict_get_label (const struct dictionary *);
123 void dict_set_label (struct dictionary *, const char *);
124
125 /* Fixed length of lines in dictionary documents. */
126 #define DOC_LINE_LENGTH 80
127
128 const char *dict_get_documents (const struct dictionary *);
129 void dict_set_documents (struct dictionary *, const char *);
130 void dict_clear_documents (struct dictionary *);
131 void dict_add_document_line (struct dictionary *, const char *);
132 size_t dict_get_document_line_cnt (const struct dictionary *);
133 void dict_get_document_line (const struct dictionary *,
134                              size_t, struct string *);
135
136 bool dict_create_vector (struct dictionary *,
137                          const char *name,
138                          struct variable **, size_t cnt);
139 void dict_create_vector_assert (struct dictionary *,
140                                 const char *name,
141                                 struct variable **, size_t cnt);
142 const struct vector *dict_get_vector (const struct dictionary *,
143                                       size_t idx);
144 size_t dict_get_vector_cnt (const struct dictionary *);
145 const struct vector *dict_lookup_vector (const struct dictionary *,
146                                          const char *name);
147 void dict_clear_vectors (struct dictionary *);
148
149 void dict_assign_short_names (struct dictionary *);
150
151 /* Called only from variable.c */
152 void dict_var_changed (const struct variable *v);
153
154 #endif /* dictionary.h */