Applied patch #5653, which adds callbacks to dataset whenever its dictionary or
[pspp-builds.git] / src / data / dictionary.c
index a5a36527c3d2803d48a686f02e82070c078de42c..d29939aca55a8043cec67cf12d3bf676c91f4b02 100644 (file)
@@ -82,6 +82,15 @@ dict_set_callbacks (struct dictionary *dict,
 }
 
 
+/* Shallow copy the callbacks from SRC to DEST */
+void
+dict_copy_callbacks (struct dictionary *dest,
+                    const struct dictionary *src)
+{
+  dest->callbacks = src->callbacks;
+  dest->cb_data = src->cb_data;
+}
+
 /* Creates and returns a new dictionary. */
 struct dictionary *
 dict_create (void)
@@ -166,6 +175,9 @@ dict_clear (struct dictionary *d)
 
   for (i = 0; i < d->var_cnt; i++)
     {
+      if (d->callbacks && d->callbacks->var_deleted )
+       d->callbacks->var_deleted (d, i, d->cb_data);
+
       var_clear_vardict (d->var[i]);
       var_destroy (d->var[i]);
     }
@@ -400,8 +412,12 @@ static void
 set_var_dict_index (struct variable *v, int dict_index)
 {
   struct vardict_info vdi = *var_get_vardict (v);
+  struct dictionary *d = vdi.dict;
   vdi.dict_index = dict_index;
   var_set_vardict (v, &vdi);
+
+  if ( d->callbacks && d->callbacks->var_changed )
+    d->callbacks->var_changed (d, dict_index, d->cb_data);
 }
 
 /* Sets the case_index in V's vardict to DICT_INDEX. */
@@ -537,20 +553,20 @@ dict_reorder_var (struct dictionary *d, struct variable *v, size_t new_index)
    listed in ORDER in that order at the beginning of D.  The
    other variables in D, if any, retain their relative
    positions. */
-void 
+void
 dict_reorder_vars (struct dictionary *d,
-                   struct variable *const *order, size_t count) 
+                   struct variable *const *order, size_t count)
 {
   struct variable **new_var;
   size_t i;
-  
+
   assert (d != NULL);
   assert (count == 0 || order != NULL);
   assert (count <= d->var_cnt);
 
   new_var = xnmalloc (d->var_cnt, sizeof *new_var);
   memcpy (new_var, order, count * sizeof *new_var);
-  for (i = 0; i < count; i++) 
+  for (i = 0; i < count; i++)
     {
       size_t index = var_get_dict_index (order[i]);
       assert (d->var[index] == order[i]);
@@ -698,7 +714,7 @@ dict_get_case_weight (const struct dictionary *d, const struct ccase *c,
   else 
     {
       double w = case_num (c, d->weight);
-      if (w < 0.0 || var_is_num_missing (d->weight, w))
+      if (w < 0.0 || var_is_num_missing (d->weight, w, MV_ANY))
         w = 0.0;
       if ( w == 0.0 && *warn_on_invalid ) {
          *warn_on_invalid = false;