+/* Returns V's index within its dictionary, the value
+ for which "dict_get_var (dict, index)" will return V.
+ V must be in a dictionary. */
+size_t
+var_get_dict_index (const struct variable *v)
+{
+ assert (var_has_vardict (v));
+ return vardict_get_dict_index (v->vardict);
+}
+
+/* Returns V's index within the case represented by its
+ dictionary, that is, the value for which "case_data_idx (case,
+ index)" will return the data for V in that case.
+ V must be in a dictionary. */
+size_t
+var_get_case_index (const struct variable *v)
+{
+ assert (var_has_vardict (v));
+ return vardict_get_case_index (v->vardict);
+}
+\f
+/* Returns variable V's attribute set. The caller may examine or
+ modify the attribute set, but must not destroy it. Destroying
+ V, or calling var_set_attributes() on V, will also destroy its
+ attribute set. */
+struct attrset *
+var_get_attributes (const struct variable *v)
+{
+ return CONST_CAST (struct attrset *, &v->attributes);
+}
+
+/* Replaces variable V's attributes set by a copy of ATTRS. */
+static void
+var_set_attributes_quiet (struct variable *v, const struct attrset *attrs)
+{
+ attrset_destroy (&v->attributes);
+ attrset_clone (&v->attributes, attrs);
+}
+
+/* Replaces variable V's attributes set by a copy of ATTRS. */
+void
+var_set_attributes (struct variable *v, const struct attrset *attrs)
+{
+ struct variable *ov = var_clone (v);
+ var_set_attributes_quiet (v, attrs);
+ dict_var_changed (v, VAR_TRAIT_ATTRIBUTES, ov);
+}
+
+
+/* Returns true if V has any custom attributes, false if it has none. */
+bool
+var_has_attributes (const struct variable *v)
+{
+ return attrset_count (&v->attributes) > 0;
+}
+\f
+
+/* Creates and returns a clone of OLD_VAR. Most properties of
+ the new variable are copied from OLD_VAR, except:
+
+ - The variable's short name is not copied, because there is
+ no reason to give a new variable with potentially a new
+ name the same short name.
+
+ - The new variable is not added to OLD_VAR's dictionary by
+ default. Use dict_clone_var, instead, to do that.
+*/
+struct variable *
+var_clone (const struct variable *old_var)
+{
+ struct variable *new_var = var_create (var_get_name (old_var),
+ var_get_width (old_var));
+
+ var_set_missing_values_quiet (new_var, var_get_missing_values (old_var));
+ var_set_print_format_quiet (new_var, var_get_print_format (old_var));
+ var_set_write_format_quiet (new_var, var_get_write_format (old_var));
+ var_set_value_labels_quiet (new_var, var_get_value_labels (old_var));
+ var_set_label_quiet (new_var, var_get_label (old_var), false);
+ var_set_measure_quiet (new_var, var_get_measure (old_var));
+ var_set_display_width_quiet (new_var, var_get_display_width (old_var));
+ var_set_alignment_quiet (new_var, var_get_alignment (old_var));
+ var_set_leave_quiet (new_var, var_get_leave (old_var));
+ var_set_attributes_quiet (new_var, var_get_attributes (old_var));
+
+ return new_var;
+}
+
+
+
+/* Returns the encoding of values of variable VAR. (This is actually a
+ property of the dictionary.) Returns null if no specific encoding has been
+ set. */
+const char *
+var_get_encoding (const struct variable *var)
+{
+ return (var_has_vardict (var)
+ ? dict_get_encoding (vardict_get_dictionary (var->vardict))
+ : NULL);
+}
+\f
+/* Returns V's vardict structure. */
+struct vardict_info *
+var_get_vardict (const struct variable *v)
+{
+ return CONST_CAST (struct vardict_info *, v->vardict);
+}
+
+/* Sets V's vardict data to VARDICT. */
+void
+var_set_vardict (struct variable *v, struct vardict_info *vardict)
+{
+ v->vardict = vardict;
+}
+
+/* Returns true if V has vardict data. */
+bool
+var_has_vardict (const struct variable *v)
+{
+ return v->vardict != NULL;
+}
+
+/* Clears V's vardict data. */
+void
+var_clear_vardict (struct variable *v)
+{
+ v->vardict = NULL;
+}