Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / data / variable.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2009, 2010, 2011 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 DATA_VARIABLE_H
18 #define DATA_VARIABLE_H 1
19
20 #include <stddef.h>
21 #include <stdbool.h>
22 #include "data/dict-class.h"
23 #include "data/missing-values.h"
24 #include "data/val-type.h"
25
26 union value;
27
28 /* Variables.
29    These functions should rarely be called directly: use
30    dict_create_var, dict_clone_var, or dict_delete_var
31    instead. */
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
36 /* Variable names. */
37 #define VAR_NAME_LEN 64 /* Maximum length of variable name, in bytes. */
38
39 const char *var_get_name (const struct variable *);
40 void var_set_name (struct variable *, const char *);
41 bool var_is_valid_name (const char *, bool issue_error);
42 bool var_is_plausible_name (const char *name, bool issue_error);
43 enum dict_class var_get_dict_class (const struct variable *);
44
45 int compare_vars_by_name (const void *, const void *, const void *);
46 unsigned hash_var_by_name (const void *, const void *);
47
48 int compare_var_ptrs_by_name (const void *, const void *, const void *);
49 unsigned hash_var_ptr_by_name (const void *, const void *);
50
51 int compare_var_ptrs_by_dict_index (const void *, const void *, const void *);
52
53 /* Types and widths of values associated with a variable. */
54 enum val_type var_get_type (const struct variable *);
55 int var_get_width (const struct variable *);
56 void var_set_width (struct variable *, int width);
57
58 bool var_is_numeric (const struct variable *);
59 bool var_is_alpha (const struct variable *);
60
61 /* Variables' missing values. */
62 const struct missing_values *var_get_missing_values (const struct variable *);
63 void var_set_missing_values (struct variable *, const struct missing_values *);
64 void var_clear_missing_values (struct variable *);
65 bool var_has_missing_values (const struct variable *);
66
67 bool var_is_value_missing (const struct variable *, const union value *,
68                            enum mv_class);
69 bool var_is_num_missing (const struct variable *, double, enum mv_class);
70 bool var_is_str_missing (const struct variable *, const uint8_t[], enum mv_class);
71
72 /* Value labels. */
73 const char *var_lookup_value_label (const struct variable *,
74                                     const union value *);
75 struct string;
76 void var_append_value_name (const struct variable *, const union value *,
77                             struct string *);
78
79 const char *
80 var_get_value_name (const struct variable *v, const union value *value);
81
82
83 bool var_has_value_labels (const struct variable *);
84 const struct val_labs *var_get_value_labels (const struct variable *);
85 void var_set_value_labels (struct variable *, const struct val_labs *);
86
87 bool var_add_value_label (struct variable *,
88                           const union value *, const char *);
89 void var_replace_value_label (struct variable *,
90                               const union value *, const char *);
91 void var_clear_value_labels (struct variable *);
92
93 /* Print and write formats. */
94 const struct fmt_spec *var_get_print_format (const struct variable *);
95 void var_set_print_format (struct variable *, const struct fmt_spec *);
96 const struct fmt_spec *var_get_write_format (const struct variable *);
97 void var_set_write_format (struct variable *, const struct fmt_spec *);
98 void var_set_both_formats (struct variable *, const struct fmt_spec *);
99
100 struct fmt_spec var_default_formats (int width);
101
102 /* Variable labels. */
103 const char *var_to_string (const struct variable *);
104 const char *var_get_label (const struct variable *);
105 void var_set_label (struct variable *, const char *);
106 void var_clear_label (struct variable *);
107 bool var_has_label (const struct variable *);
108
109 /* How data is measured. */
110 enum measure
111   {
112     MEASURE_NOMINAL = 0,
113     MEASURE_ORDINAL = 1,
114     MEASURE_SCALE = 2,
115     n_MEASURES
116   };
117
118 bool measure_is_valid (enum measure);
119 enum measure var_get_measure (const struct variable *);
120 void var_set_measure (struct variable *, enum measure);
121
122 enum measure var_default_measure (enum val_type);
123
124 /* GUI display width. */
125 int var_get_display_width (const struct variable *);
126 void var_set_display_width (struct variable *, int display_width);
127
128 int var_default_display_width (int width);
129
130 /* Alignment of data for display. */
131 enum alignment
132   {
133     ALIGN_LEFT = 0,
134     ALIGN_RIGHT = 1,
135     ALIGN_CENTRE = 2,
136     n_ALIGN
137   };
138
139 bool alignment_is_valid (enum alignment);
140 enum alignment var_get_alignment (const struct variable *);
141 void var_set_alignment (struct variable *, enum alignment);
142
143 enum alignment var_default_alignment (enum val_type);
144
145 /* Whether variables' values should be preserved from case to
146    case. */
147 bool var_get_leave (const struct variable *);
148 void var_set_leave (struct variable *, bool leave);
149 bool var_must_leave (const struct variable *);
150
151 /* Short names. */
152 size_t var_get_short_name_cnt (const struct variable *);
153 const char *var_get_short_name (const struct variable *, size_t idx);
154 void var_set_short_name (struct variable *, size_t, const char *);
155 void var_clear_short_names (struct variable *);
156
157 /* Relationship with dictionary. */
158 size_t var_get_dict_index (const struct variable *);
159 size_t var_get_case_index (const struct variable *);
160
161 /* Variable auxiliary data. */
162 void *var_get_aux (const struct variable *);
163 void *var_attach_aux (const struct variable *,
164                       void *aux, void (*aux_dtor) (struct variable *));
165 void var_clear_aux (struct variable *);
166 void *var_detach_aux (struct variable *);
167 void var_dtor_free (struct variable *);
168
169 /* Custom attributes. */
170 struct attrset *var_get_attributes (const struct variable *);
171 void var_set_attributes (struct variable *, const struct attrset *);
172 bool var_has_attributes (const struct variable *);
173
174 /* Encoding. */
175 const char *var_get_encoding (const struct variable *);
176
177 /* Function types. */
178 typedef bool var_predicate_func (const struct variable *);
179
180 #endif /* data/variable.h */