dictionary.c: Added a WHAT argument to dict_var_changed callback
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 22 Jun 2013 05:23:16 +0000 (07:23 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 22 Jun 2013 10:31:09 +0000 (12:31 +0200)
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
src/data/vardict.h
src/data/variable.c
src/data/variable.h

index 04c082fca7854a3513baa4553a43fbf788b4a75e..e3622655c5fae685b14d9f0b52c5c348a9462132 100644 (file)
@@ -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))
     {
index 809c564c86bbdf5e5c9375215a22a19a19feb636..ad87c82cfa78d835d47798bbc30b5b0634e4faf5 100644 (file)
@@ -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);
 
index f4da2c4da09a17e9c3a20a25fddf380eaba45497..6c6f6cedc7d8fa9758b23ca0fc55d816aa068240 100644 (file)
@@ -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);
 }
 
 
index aef0d87c5ba78f6420fc1a0d2f637ec599ff1838..9d348d5920788213e36d642320348ae81509ed81 100644 (file)
 #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.