Added custom psppire-selector widget.
[pspp-builds.git] / src / data / variable.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 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 #if !variable_h
20 #define variable_h 1
21
22 #include <stddef.h>
23 #include <stdbool.h>
24 #include <data/missing-values.h>
25
26 union value;
27
28 /* Variable type. */
29 enum var_type
30   {
31     VAR_NUMERIC,                /* A numeric variable. */
32     VAR_STRING                  /* A string variable. */
33   };
34
35 bool var_type_is_valid (enum var_type);
36 enum var_type var_type_from_width (int width);
37
38 /* Variables. */
39 struct variable *var_create (const char *name, int width);
40 struct variable *var_clone (const struct variable *);
41 void var_destroy (struct variable *);
42
43 /* Variable names.
44    Long variable names can be used in most contexts, but a few
45    procedures and file formats are limited to short names. */
46 #define SHORT_NAME_LEN 8
47 #define LONG_NAME_LEN 64
48
49 const char *var_get_name (const struct variable *);
50 void var_set_name (struct variable *, const char *);
51 bool var_is_valid_name (const char *, bool issue_error);
52 bool var_is_plausible_name (const char *name, bool issue_error);
53
54 int compare_vars_by_name (const void *, const void *, const void *);
55 unsigned hash_var_by_name (const void *, const void *);
56
57 int compare_var_ptrs_by_name (const void *, const void *, const void *);
58 unsigned hash_var_ptr_by_name (const void *, const void *);
59
60 /* Variable types and widths. */
61 enum var_type var_get_type (const struct variable *);
62 int var_get_width (const struct variable *);
63 void var_set_width (struct variable *, int width);
64
65 typedef bool var_predicate_func (const struct variable *);
66
67 bool var_is_numeric (const struct variable *);
68 bool var_is_alpha (const struct variable *);
69 bool var_is_short_string (const struct variable *);
70 bool var_is_long_string (const struct variable *);
71 size_t var_get_value_cnt (const struct variable *);
72
73 /* Variables' missing values. */
74 const struct missing_values *var_get_missing_values (const struct variable *);
75 void var_set_missing_values (struct variable *, const struct missing_values *);
76 void var_clear_missing_values (struct variable *);
77 bool var_has_missing_values (const struct variable *);
78
79 bool var_is_value_missing (const struct variable *, const union value *,
80                            enum mv_class);
81 bool var_is_num_missing (const struct variable *, double, enum mv_class);
82 bool var_is_str_missing (const struct variable *, const char[], enum mv_class);
83
84 /* Value labels. */
85 const struct val_labs *var_get_value_labels (const struct variable *);
86 bool var_has_value_labels (const struct variable *);
87 void var_set_value_labels (struct variable *, const struct val_labs *);
88 bool var_add_value_label (struct variable *,
89                           const union value *, const char *);
90 void var_replace_value_label (struct variable *,
91                               const union value *, const char *);
92 void var_clear_value_labels (struct variable *);
93 const char *var_lookup_value_label (const struct variable *,
94                                     const union value *);
95 const char *var_get_value_name (const struct variable *, const union value *);
96
97 /* Print and write formats. */
98 const struct fmt_spec *var_get_print_format (const struct variable *);
99 void var_set_print_format (struct variable *, const struct fmt_spec *);
100 const struct fmt_spec *var_get_write_format (const struct variable *);
101 void var_set_write_format (struct variable *, const struct fmt_spec *);
102 void var_set_both_formats (struct variable *, const struct fmt_spec *);
103
104 /* Variable labels. */
105 const char *var_to_string (const struct variable *);
106 const char *var_get_label (const struct variable *);
107 void var_set_label (struct variable *, const char *);
108 void var_clear_label (struct variable *);
109 bool var_has_label (const struct variable *);
110
111 /* How data is measured. */
112 enum measure
113   {
114     MEASURE_NOMINAL = 0,
115     MEASURE_ORDINAL = 1,
116     MEASURE_SCALE = 2,
117     n_MEASURES
118   };
119
120 bool measure_is_valid (enum measure);
121 enum measure var_get_measure (const struct variable *);
122 void var_set_measure (struct variable *, enum measure);
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 /* Alignment of data for display. */
129 enum alignment 
130   {
131     ALIGN_LEFT = 0,
132     ALIGN_RIGHT = 1,
133     ALIGN_CENTRE = 2,
134     n_ALIGN
135   };
136
137 bool alignment_is_valid (enum alignment);
138 enum alignment var_get_alignment (const struct variable *);
139 void var_set_alignment (struct variable *, enum alignment);
140
141 /* Whether variables' values should be preserved from case to
142    case. */
143 bool var_get_leave (const struct variable *);
144 void var_set_leave (struct variable *, bool leave);
145 bool var_must_leave (const struct variable *);
146
147 /* Short names. */
148 const char *var_get_short_name (const struct variable *);
149 void var_set_short_name (struct variable *, const char *);
150 void var_clear_short_name (struct variable *);
151
152 /* Relationship with dictionary. */
153 size_t var_get_dict_index (const struct variable *);
154 size_t var_get_case_index (const struct variable *);
155
156 /* Variable auxiliary data. */
157 void *var_get_aux (const struct variable *);
158 void *var_attach_aux (struct variable *,
159                       void *aux, void (*aux_dtor) (struct variable *));
160 void var_clear_aux (struct variable *);
161 void *var_detach_aux (struct variable *);
162 void var_dtor_free (struct variable *);
163
164 /* Observed categorical values. */
165 struct cat_vals *var_get_obs_vals (const struct variable *);
166 void var_set_obs_vals (struct variable *, struct cat_vals *);
167 bool var_has_obs_vals (const struct variable *);
168
169 /* Classes of variables. */
170 enum dict_class 
171   {
172     DC_ORDINARY,                /* Ordinary identifier. */
173     DC_SYSTEM,                  /* System variable. */
174     DC_SCRATCH                  /* Scratch variable. */
175   };
176
177 enum dict_class dict_class_from_id (const char *name);
178 const char *dict_class_to_name (enum dict_class dict_class);
179
180 #endif /* !variable.h */