1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 2007, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
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.
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.
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/>. */
17 #ifndef DATA_DICTIONARY_H
18 #define DATA_DICTIONARY_H 1
22 #include "data/case.h"
23 #include "data/dict-class.h"
28 /* Creating dictionaries. */
29 struct dictionary *dict_create (const char *encoding);
30 struct dictionary *dict_clone (const struct dictionary *);
33 /* Clearing and destroying dictionaries. */
34 void dict_clear (struct dictionary *);
35 void dict_destroy (struct dictionary *);
37 /* Common ways to access variables. */
38 struct variable *dict_lookup_var (const struct dictionary *, const char *);
39 struct variable *dict_lookup_var_assert (const struct dictionary *,
41 struct variable *dict_get_var (const struct dictionary *, size_t position);
42 size_t dict_get_var_cnt (const struct dictionary *);
44 /* Other access to variables. */
45 bool dict_contains_var (const struct dictionary *, const struct variable *);
46 void dict_get_vars (const struct dictionary *,
47 const struct variable ***vars, size_t *cnt,
48 enum dict_class exclude);
49 void dict_get_vars_mutable (const struct dictionary *,
50 struct variable ***vars, size_t *cnt,
51 enum dict_class exclude);
53 /* Creating variables. */
54 struct variable *dict_create_var (struct dictionary *, const char *,
56 struct variable *dict_create_var_assert (struct dictionary *, const char *,
58 struct variable *dict_clone_var (struct dictionary *, const struct variable *);
59 struct variable *dict_clone_var_assert (struct dictionary *,
60 const struct variable *);
61 struct variable *dict_clone_var_as (struct dictionary *,
62 const struct variable *, const char *);
63 struct variable *dict_clone_var_as_assert (struct dictionary *,
64 const struct variable *,
67 /* Deleting variables. */
68 void dict_delete_var (struct dictionary *, struct variable *);
69 void dict_delete_vars (struct dictionary *,
70 struct variable *const *, size_t count);
71 void dict_delete_consecutive_vars (struct dictionary *,
72 size_t idx, size_t count);
73 void dict_delete_scratch_vars (struct dictionary *);
75 /* Changing the order of variables. */
76 void dict_reorder_var (struct dictionary *, struct variable *,
78 void dict_reorder_vars (struct dictionary *,
79 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 char *dict_make_unique_var_name (const struct dictionary *, const char *hint,
87 unsigned long int *num_start);
89 /* Weight variable. */
90 double dict_get_case_weight (const struct dictionary *,
91 const struct ccase *, bool *);
92 struct variable *dict_get_weight (const struct dictionary *);
93 void dict_set_weight (struct dictionary *, struct variable *);
95 /* Filter variable. */
96 struct variable *dict_get_filter (const struct dictionary *);
97 void dict_set_filter (struct dictionary *, struct variable *);
99 /* Case limit (N OF CASES). */
100 casenumber dict_get_case_limit (const struct dictionary *);
101 void dict_set_case_limit (struct dictionary *, casenumber);
103 /* Size of cases for this dictionary. */
104 const struct caseproto *dict_get_proto (const struct dictionary *);
105 int dict_get_next_value_idx (const struct dictionary *);
106 size_t dict_get_case_size (const struct dictionary *);
108 /* Making this dictionary's cases smaller (if some variables were
110 size_t dict_count_values (const struct dictionary *,
111 unsigned int exclude_classes);
112 void dict_compact_values (struct dictionary *);
113 struct caseproto *dict_get_compacted_proto (const struct dictionary *,
114 unsigned int exclude_classes);
116 /* SPLIT FILE variables. */
117 const struct variable *const *dict_get_split_vars (const struct dictionary *);
118 size_t dict_get_split_cnt (const struct dictionary *);
119 void dict_set_split_vars (struct dictionary *,
120 struct variable *const *, size_t cnt);
123 const char *dict_get_label (const struct dictionary *);
124 void dict_set_label (struct dictionary *, const char *);
127 #define DOC_LINE_LENGTH 80 /* Fixed length of document lines. */
129 const struct string_array *dict_get_documents (const struct dictionary *);
130 void dict_set_documents (struct dictionary *, const struct string_array *);
131 void dict_set_documents_string (struct dictionary *, const char *);
132 void dict_clear_documents (struct dictionary *);
134 bool dict_add_document_line (struct dictionary *, const char *,
136 size_t dict_get_document_line_cnt (const struct dictionary *);
137 const char *dict_get_document_line (const struct dictionary *, size_t);
140 bool dict_create_vector (struct dictionary *, const char *name,
141 struct variable **, size_t cnt);
142 void dict_create_vector_assert (struct dictionary *, const char *name,
143 struct variable **, size_t cnt);
144 const struct vector *dict_get_vector (const struct dictionary *, size_t idx);
145 size_t dict_get_vector_cnt (const struct dictionary *);
146 const struct vector *dict_lookup_vector (const struct dictionary *,
148 void dict_clear_vectors (struct dictionary *);
150 /* Multiple response sets. */
151 const struct mrset *dict_get_mrset (const struct dictionary *, size_t idx);
152 size_t dict_get_n_mrsets (const struct dictionary *);
153 const struct mrset *dict_lookup_mrset (const struct dictionary *,
156 bool dict_add_mrset (struct dictionary *, struct mrset *);
157 bool dict_delete_mrset (struct dictionary *, const char *name);
158 void dict_clear_mrsets (struct dictionary *);
161 struct attrset *dict_get_attributes (const struct dictionary *);
162 void dict_set_attributes (struct dictionary *, const struct attrset *);
163 bool dict_has_attributes (const struct dictionary *);
166 const char *dict_get_encoding (const struct dictionary *d);
168 bool dict_id_is_valid (const struct dictionary *, const char *id,
171 /* Internal variables. */
172 struct variable *dict_create_internal_var (int case_idx, int width);
173 void dict_destroy_internal_var (struct variable *);
175 /* Functions to be called upon dictionary changes. */
176 struct dict_callbacks
178 void (*var_added) (struct dictionary *, int, void *);
179 void (*var_deleted) (struct dictionary *, const struct variable *,
180 int dict_index, int case_index, void *);
181 void (*var_changed) (struct dictionary *, int, void *);
182 void (*var_resized) (struct dictionary *, int, int, void *);
183 void (*weight_changed) (struct dictionary *, int, void *);
184 void (*filter_changed) (struct dictionary *, int, void *);
185 void (*split_changed) (struct dictionary *, void *);
186 void (*var_display_width_changed) (struct dictionary *, int, void *);
189 void dict_set_callbacks (struct dictionary *, const struct dict_callbacks *,
191 void dict_copy_callbacks (struct dictionary *, const struct dictionary *);
193 void dict_set_change_callback (struct dictionary *d,
194 void (*changed) (struct dictionary *, void*),
198 /* Debug use only. */
199 void dict_dump (const struct dictionary *);
201 #endif /* data/dictionary.h */