1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 2007 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 (void);
30 struct dictionary *dict_clone (const struct dictionary *);
33 /* Clearing and destroying dictionaries. */
34 void dict_clear (struct dictionary *);
35 void dict_clear_aux (struct dictionary *);
36 void dict_destroy (struct dictionary *);
38 /* Common ways to access variables. */
39 struct variable *dict_lookup_var (const struct dictionary *, const char *);
40 struct variable *dict_lookup_var_assert (const struct dictionary *,
42 struct variable *dict_get_var (const struct dictionary *, size_t position);
43 size_t dict_get_var_cnt (const struct dictionary *);
45 /* Other access to variables. */
46 bool dict_contains_var (const struct dictionary *, const struct variable *);
47 void dict_get_vars (const struct dictionary *,
48 const struct variable ***vars, size_t *cnt,
49 enum dict_class exclude);
50 void dict_get_vars_mutable (const struct dictionary *,
51 struct variable ***vars, size_t *cnt,
52 enum dict_class exclude);
54 /* Creating variables. */
55 struct variable *dict_create_var (struct dictionary *, const char *,
57 struct variable *dict_create_var_assert (struct dictionary *, const char *,
59 struct variable *dict_clone_var (struct dictionary *, const struct variable *,
61 struct variable *dict_clone_var_assert (struct dictionary *,
62 const struct variable *, const char *);
64 /* Deleting variables. */
65 void dict_delete_var (struct dictionary *, struct variable *);
66 void dict_delete_vars (struct dictionary *,
67 struct variable *const *, size_t count);
68 void dict_delete_consecutive_vars (struct dictionary *,
69 size_t idx, size_t count);
70 void dict_delete_scratch_vars (struct dictionary *);
72 /* Changing the order of variables. */
73 void dict_reorder_var (struct dictionary *, struct variable *,
75 void dict_reorder_vars (struct dictionary *,
76 struct variable *const *, size_t count);
78 /* Changing variable names. */
79 void dict_rename_var (struct dictionary *, struct variable *, const char *);
80 bool dict_rename_vars (struct dictionary *,
81 struct variable **, char **new_names,
82 size_t count, char **err_name);
84 /* Weight variable. */
85 double dict_get_case_weight (const struct dictionary *,
86 const struct ccase *, bool *);
87 struct variable *dict_get_weight (const struct dictionary *);
88 void dict_set_weight (struct dictionary *, struct variable *);
90 /* Filter variable. */
91 struct variable *dict_get_filter (const struct dictionary *);
92 void dict_set_filter (struct dictionary *, struct variable *);
94 /* Case limit (N OF CASES). */
95 casenumber dict_get_case_limit (const struct dictionary *);
96 void dict_set_case_limit (struct dictionary *, casenumber);
98 /* Size of cases for this dictionary. */
99 int dict_get_next_value_idx (const struct dictionary *);
100 size_t dict_get_case_size (const struct dictionary *);
102 /* Making this dictionary's cases smaller (if some variables were
104 size_t dict_count_values (const struct dictionary *,
105 unsigned int exclude_classes);
106 void dict_compact_values (struct dictionary *);
108 /* SPLIT FILE variables. */
109 const struct variable *const *dict_get_split_vars (const struct dictionary *);
110 size_t dict_get_split_cnt (const struct dictionary *);
111 void dict_set_split_vars (struct dictionary *,
112 struct variable *const *, size_t cnt);
113 void dict_unset_split_var (struct dictionary *, struct variable *);
116 const char *dict_get_label (const struct dictionary *);
117 void dict_set_label (struct dictionary *, const char *);
120 #define DOC_LINE_LENGTH 80 /* Fixed length of document lines. */
122 const char *dict_get_documents (const struct dictionary *);
123 void dict_set_documents (struct dictionary *, const char *);
124 void dict_clear_documents (struct dictionary *);
126 void dict_add_document_line (struct dictionary *, const char *);
127 size_t dict_get_document_line_cnt (const struct dictionary *);
128 void dict_get_document_line (const struct dictionary *,
129 size_t, struct string *);
132 bool dict_create_vector (struct dictionary *, const char *name,
133 struct variable **, size_t cnt);
134 void dict_create_vector_assert (struct dictionary *, const char *name,
135 struct variable **, size_t cnt);
136 const struct vector *dict_get_vector (const struct dictionary *, size_t idx);
137 size_t dict_get_vector_cnt (const struct dictionary *);
138 const struct vector *dict_lookup_vector (const struct dictionary *,
140 void dict_clear_vectors (struct dictionary *);
142 /* Functions to be called upon dictionary changes. */
143 struct dict_callbacks
145 void (*var_added) (struct dictionary *, int, void *);
146 void (*var_deleted) (struct dictionary *, int, int, int, void *);
147 void (*var_changed) (struct dictionary *, int, void *);
148 void (*var_resized) (struct dictionary *, int, int, void *);
149 void (*weight_changed) (struct dictionary *, int, void *);
150 void (*filter_changed) (struct dictionary *, int, void *);
151 void (*split_changed) (struct dictionary *, void *);
154 void dict_set_callbacks (struct dictionary *, const struct dict_callbacks *,
156 void dict_copy_callbacks (struct dictionary *, const struct dictionary *);
158 /* Debug use only. */
159 void dict_dump (const struct dictionary *);
161 #endif /* data/dictionary.h */