From ff0f5192a578cb9297dc57c88e84096feabf9491 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 22 Jun 2013 07:23:16 +0200 Subject: [PATCH] dictionary.c: Added a WHAT argument to dict_var_changed callback Defined some bitwise constants to indicate which aspect of a variable has changed. Added an argument to the dict_var_changed callback taking an argument which contains a combination of these types. This is used in later commits to avoid the callback implementation having to guess what exactly changed. --- src/data/dictionary.c | 2 +- src/data/vardict.h | 2 +- src/data/variable.c | 29 +++++++++++++++-------------- src/data/variable.h | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 04c082fca7..e3622655c5 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1594,7 +1594,7 @@ dict_has_attributes (const struct dictionary *d) /* Called from variable.c to notify the dictionary that some property of the variable has changed */ void -dict_var_changed (const struct variable *v) +dict_var_changed (const struct variable *v, unsigned int what UNUSED) { if ( var_has_vardict (v)) { diff --git a/src/data/vardict.h b/src/data/vardict.h index 809c564c86..ad87c82cfa 100644 --- a/src/data/vardict.h +++ b/src/data/vardict.h @@ -39,7 +39,7 @@ bool var_has_vardict (const struct variable *); void var_clear_vardict (struct variable *); /* Called by variable.c, defined in dictionary.c. */ -void dict_var_changed (const struct variable *v); +void dict_var_changed (const struct variable *v, unsigned int what); void dict_var_resized (const struct variable *v, int old_width); void dict_var_display_width_changed (const struct variable *v); diff --git a/src/data/variable.c b/src/data/variable.c index f4da2c4da0..6c6f6cedc7 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -275,7 +275,7 @@ var_set_width (struct variable *v, int new_width) v->width = new_width; dict_var_resized (v, old_width); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_WIDTH); } /* Returns true if variable V is numeric, false otherwise. */ @@ -326,7 +326,7 @@ void var_set_missing_values (struct variable *v, const struct missing_values *miss) { var_set_missing_values_quiet (v, miss); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_MISSING_VALUES); } /* Sets variable V to have no user-missing values. */ @@ -414,7 +414,7 @@ void var_set_value_labels (struct variable *v, const struct val_labs *vls) { var_set_value_labels_quiet (v, vls); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_LABEL); } @@ -549,7 +549,7 @@ void var_set_print_format (struct variable *v, const struct fmt_spec *print) { var_set_print_format_quiet (v, print); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_FORMAT); } /* Returns V's write format specification. */ @@ -581,7 +581,7 @@ void var_set_write_format (struct variable *v, const struct fmt_spec *write) { var_set_write_format_quiet (v, write); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_FORMAT); } @@ -592,8 +592,9 @@ var_set_write_format (struct variable *v, const struct fmt_spec *write) void var_set_both_formats (struct variable *v, const struct fmt_spec *format) { - var_set_print_format (v, format); - var_set_write_format (v, format); + var_set_print_format_quiet (v, format); + var_set_write_format_quiet (v, format); + dict_var_changed (v, VAR_TRAIT_FORMAT); } /* Returns the default print and write format for a variable of @@ -725,7 +726,7 @@ var_set_label (struct variable *v, const char *label, bool issue_warning) { bool truncated = var_set_label_quiet (v, label, issue_warning); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_LABEL); return truncated; } @@ -795,7 +796,7 @@ void var_set_measure (struct variable *v, enum measure measure) { var_set_measure_quiet (v, measure); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_MEASURE); } @@ -831,7 +832,7 @@ void var_set_display_width (struct variable *v, int new_width) { var_set_display_width_quiet (v, new_width); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_DISPLAY_WIDTH); } @@ -892,7 +893,7 @@ void var_set_alignment (struct variable *v, enum alignment alignment) { var_set_alignment_quiet (v, alignment); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_ALIGNMENT); } @@ -930,7 +931,7 @@ void var_set_leave (struct variable *v, bool leave) { var_set_leave_quiet (v, leave); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_LEAVE); } @@ -1002,7 +1003,7 @@ var_set_short_name (struct variable *var, size_t idx, const char *short_name) var->short_names[idx] = utf8_to_upper (short_name); } - dict_var_changed (var); + dict_var_changed (var, VAR_TRAIT_NAME); } /* Clears V's short names. */ @@ -1064,7 +1065,7 @@ void var_set_attributes (struct variable *v, const struct attrset *attrs) { var_set_attributes_quiet (v, attrs); - dict_var_changed (v); + dict_var_changed (v, VAR_TRAIT_ATTRIBUTES); } diff --git a/src/data/variable.h b/src/data/variable.h index aef0d87c5b..9d348d5920 100644 --- a/src/data/variable.h +++ b/src/data/variable.h @@ -23,6 +23,21 @@ #include "data/missing-values.h" #include "data/val-type.h" +/* Bitfields to identify traits of a variable */ + +#define VAR_TRAIT_NAME 0x0001 +#define VAR_TRAIT_WIDTH 0x0002 +#define VAR_TRAIT_FORMAT 0x0004 +#define VAR_TRAIT_LABEL 0x0008 +#define VAR_TRAIT_VALUE_LABELS 0x0010 +#define VAR_TRAIT_MISSING_VALUES 0x0020 +#define VAR_TRAIT_ALIGNMENT 0x0040 +#define VAR_TRAIT_MEASURE 0x0080 +#define VAR_TRAIT_DISPLAY_WIDTH 0x0100 +#define VAR_TRAIT_LEAVE 0x0200 +#define VAR_TRAIT_POSITION 0x0400 +#define VAR_TRAIT_ATTRIBUTES 0x0800 + union value; /* Variables. -- 2.30.2