1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000 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_VARIABLE_H
18 #define DATA_VARIABLE_H 1
22 #include <data/dict-class.h>
23 #include <data/missing-values.h>
24 #include <data/val-type.h>
29 These functions should rarely be called directly: use
30 dict_create_var, dict_clone_var, or dict_delete_var
32 struct variable *var_create (const char *name, int width);
33 struct variable *var_clone (const struct variable *);
34 void var_destroy (struct variable *);
35 struct variable *var_create_internal (int case_idx);
39 #define VAR_NAME_LEN 64 /* Maximum length of variable name, in bytes. */
41 const char *var_get_name (const struct variable *);
42 void var_set_name (struct variable *, const char *);
43 bool var_is_valid_name (const char *, bool issue_error);
44 bool var_is_plausible_name (const char *name, bool issue_error);
45 enum dict_class var_get_dict_class (const struct variable *);
47 int compare_vars_by_name (const void *, const void *, const void *);
48 unsigned hash_var_by_name (const void *, const void *);
50 int compare_var_ptrs_by_name (const void *, const void *, const void *);
51 unsigned hash_var_ptr_by_name (const void *, const void *);
53 int compare_var_ptrs_by_dict_index (const void *, const void *, const void *);
55 /* Types and widths of values associated with a variable. */
56 enum val_type var_get_type (const struct variable *);
57 int var_get_width (const struct variable *);
58 void var_set_width (struct variable *, int width);
60 bool var_is_numeric (const struct variable *);
61 bool var_is_alpha (const struct variable *);
62 bool var_is_short_string (const struct variable *);
63 bool var_is_long_string (const struct variable *);
65 size_t var_get_value_cnt (const struct variable *);
67 /* Variables' missing values. */
68 const struct missing_values *var_get_missing_values (const struct variable *);
69 void var_set_missing_values (struct variable *, const struct missing_values *);
70 void var_clear_missing_values (struct variable *);
71 bool var_has_missing_values (const struct variable *);
73 bool var_is_value_missing (const struct variable *, const union value *,
75 bool var_is_num_missing (const struct variable *, double, enum mv_class);
76 bool var_is_str_missing (const struct variable *, const char[], enum mv_class);
79 const char *var_lookup_value_label (const struct variable *,
82 void var_append_value_name (const struct variable *, const union value *,
86 var_get_value_name (const struct variable *v, const union value *value);
89 bool var_has_value_labels (const struct variable *);
90 const struct val_labs *var_get_value_labels (const struct variable *);
91 void var_set_value_labels (struct variable *, const struct val_labs *);
93 bool var_add_value_label (struct variable *,
94 const union value *, const char *);
95 void var_replace_value_label (struct variable *,
96 const union value *, const char *);
97 void var_clear_value_labels (struct variable *);
99 /* Print and write formats. */
100 const struct fmt_spec *var_get_print_format (const struct variable *);
101 void var_set_print_format (struct variable *, const struct fmt_spec *);
102 const struct fmt_spec *var_get_write_format (const struct variable *);
103 void var_set_write_format (struct variable *, const struct fmt_spec *);
104 void var_set_both_formats (struct variable *, const struct fmt_spec *);
106 struct fmt_spec var_default_formats (int width);
108 /* Variable labels. */
109 const char *var_to_string (const struct variable *);
110 const char *var_get_label (const struct variable *);
111 void var_set_label (struct variable *, const char *);
112 void var_clear_label (struct variable *);
113 bool var_has_label (const struct variable *);
115 /* How data is measured. */
124 bool measure_is_valid (enum measure);
125 enum measure var_get_measure (const struct variable *);
126 void var_set_measure (struct variable *, enum measure);
128 enum measure var_default_measure (enum val_type);
130 /* GUI display width. */
131 int var_get_display_width (const struct variable *);
132 void var_set_display_width (struct variable *, int display_width);
134 int var_default_display_width (int width);
136 /* Alignment of data for display. */
145 bool alignment_is_valid (enum alignment);
146 enum alignment var_get_alignment (const struct variable *);
147 void var_set_alignment (struct variable *, enum alignment);
149 enum alignment var_default_alignment (enum val_type);
151 /* Whether variables' values should be preserved from case to
153 bool var_get_leave (const struct variable *);
154 void var_set_leave (struct variable *, bool leave);
155 bool var_must_leave (const struct variable *);
158 size_t var_get_short_name_cnt (const struct variable *);
159 const char *var_get_short_name (const struct variable *, size_t idx);
160 void var_set_short_name (struct variable *, size_t, const char *);
161 void var_clear_short_names (struct variable *);
163 /* Relationship with dictionary. */
164 size_t var_get_dict_index (const struct variable *);
165 size_t var_get_case_index (const struct variable *);
167 /* Variable auxiliary data. */
168 void *var_get_aux (const struct variable *);
169 void *var_attach_aux (const struct variable *,
170 void *aux, void (*aux_dtor) (struct variable *));
171 void var_clear_aux (struct variable *);
172 void *var_detach_aux (struct variable *);
173 void var_dtor_free (struct variable *);
175 /* Observed categorical values. */
176 struct cat_vals *var_get_obs_vals (const struct variable *);
177 void var_set_obs_vals (const struct variable *, struct cat_vals *);
178 bool var_has_obs_vals (const struct variable *);
180 /* Custom attributes. */
181 struct attrset *var_get_attributes (const struct variable *);
182 void var_set_attributes (struct variable *, const struct attrset *);
183 bool var_has_attributes (const struct variable *);
185 /* Function types. */
186 typedef bool var_predicate_func (const struct variable *);
188 #endif /* data/variable.h */