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