struct trns_chain *temporary_trns_chain;
struct dictionary *dict;
- /* Callback which occurs whenever the transformation chain(s) have
- been modified */
- transformation_change_callback_func *xform_callback;
- void *xform_callback_aux;
-
/* If true, cases are discarded instead of being written to
sink. */
bool discard_output;
bool ok; /* Error status. */
struct casereader_shim *shim; /* Shim on proc_open() casereader. */
- void (*callback) (void *); /* Callback for when the dataset changes */
+ const struct dataset_callbacks *callbacks;
void *cb_data;
/* Default encoding for reading syntax files. */
char *syntax_encoding;
};
+static void dataset_changed__ (struct dataset *);
+static void dataset_transformations_changed__ (struct dataset *,
+ bool non_empty);
+
static void add_case_limit_trns (struct dataset *ds);
static void add_filter_trns (struct dataset *ds);
static void update_last_proc_invocation (struct dataset *ds);
-static void
-dataset_set_unsaved (const struct dataset *ds)
-{
- if (ds->callback) ds->callback (ds->cb_data);
-}
-
static void
dict_callback (struct dictionary *d UNUSED, void *ds_)
{
struct dataset *ds = ds_;
- dataset_set_unsaved (ds);
+ dataset_changed__ (ds);
}
\f
/* Creates and returns a new dataset. The dataset initially has an empty
dict_destroy (ds->dict);
caseinit_destroy (ds->caseinit);
trns_chain_destroy (ds->permanent_trns_chain);
-
- if ( ds->xform_callback)
- ds->xform_callback (false, ds->xform_callback_aux);
+ dataset_transformations_changed__ (ds, false);
free (ds->syntax_encoding);
free (ds);
}
}
-/* Discards the active file dictionary, data, and transformations. */
+/* Discards the active dataset's dictionary, data, and transformations. */
void
dataset_clear (struct dataset *ds)
{
return dataset_source (ds) != NULL;
}
-/* Replaces the active file's data by READER. READER's cases must have an
+/* Replaces the active dataset's data by READER. READER's cases must have an
appropriate format for DS's dictionary. */
bool
dataset_set_source (struct dataset *ds, struct casereader *reader)
return reader;
}
-\f
+
void
-dataset_set_callback (struct dataset *ds, void (*cb) (void *), void *cb_data)
+dataset_set_callbacks (struct dataset *ds,
+ const struct dataset_callbacks *callbacks,
+ void *cb_data)
{
- ds->callback = cb;
+ ds->callbacks = callbacks;
ds->cb_data = cb_data;
}
{
return ds->syntax_encoding;
}
-
+\f
/* Returns the last time the data was read. */
time_t
time_of_last_procedure (struct dataset *ds)
ds->lag_cases[deque_push_front (&ds->lag)] = case_ref (c);
}
- /* Write case to replacement active file. */
+ /* Write case to replacement dataset. */
ds->cases_written++;
if (ds->sink != NULL)
casewriter_write (ds->sink,
/* Make sure transformations happen for every input case, in
case they have side effects, and ensure that the replacement
- active file gets all the cases it should. */
+ active dataset gets all the cases it should. */
while ((c = casereader_read (reader)) != NULL)
case_unref (c);
/* Must return false if the source casereader, a transformation,
or the sink casewriter signaled an error. (If a temporary
transformation signals an error, then the return value is
- false, but the replacement active file may still be
+ false, but the replacement active dataset may still be
untainted.) */
bool
proc_commit (struct dataset *ds)
assert (ds->proc_state == PROC_CLOSED);
ds->proc_state = PROC_COMMITTED;
- dataset_set_unsaved (ds);
+ dataset_changed__ (ds);
/* Free memory for lagged cases. */
while (!deque_is_empty (&ds->lag))
assert (ds->temporary_trns_chain == NULL);
chain = ds->permanent_trns_chain;
ds->cur_trns_chain = ds->permanent_trns_chain = trns_chain_create ();
-
- if ( ds->xform_callback)
- ds->xform_callback (false, ds->xform_callback_aux);
+ dataset_transformations_changed__ (ds, false);
return chain;
}
add_transformation (struct dataset *ds, trns_proc_func *proc, trns_free_func *free, void *aux)
{
trns_chain_append (ds->cur_trns_chain, NULL, proc, free, aux);
- if ( ds->xform_callback)
- ds->xform_callback (true, ds->xform_callback_aux);
+ dataset_transformations_changed__ (ds, true);
}
/* Adds a transformation that processes a case with PROC and
trns_free_func *free, void *aux)
{
trns_chain_append (ds->cur_trns_chain, finalize, proc, free, aux);
-
- if ( ds->xform_callback)
- ds->xform_callback (true, ds->xform_callback_aux);
+ dataset_transformations_changed__ (ds, true);
}
/* Returns the index of the next transformation.
trns_chain_finalize (ds->permanent_trns_chain);
ds->temporary_trns_chain = ds->cur_trns_chain = trns_chain_create ();
-
- if ( ds->xform_callback)
- ds->xform_callback (true, ds->xform_callback_aux);
+ dataset_transformations_changed__ (ds, true);
}
}
trns_chain_destroy (ds->temporary_trns_chain);
ds->temporary_trns_chain = NULL;
-
- if ( ds->xform_callback)
- ds->xform_callback (!trns_chain_is_empty (ds->permanent_trns_chain),
- ds->xform_callback_aux);
-
+ dataset_transformations_changed__ (
+ ds, !trns_chain_is_empty (ds->permanent_trns_chain));
return true;
}
else
ok = trns_chain_destroy (ds->temporary_trns_chain) && ok;
ds->permanent_trns_chain = ds->cur_trns_chain = trns_chain_create ();
ds->temporary_trns_chain = NULL;
- if ( ds->xform_callback)
- ds->xform_callback (false, ds->xform_callback_aux);
+ dataset_transformations_changed__ (ds, false);
return ok;
}
\f
-
-void
-dataset_add_transform_change_callback (struct dataset *ds,
- transformation_change_callback_func *cb,
- void *aux)
-{
- ds->xform_callback = cb;
- ds->xform_callback_aux = aux;
-}
-
/* Causes output from the next procedure to be discarded, instead
of being preserved for use as input for the next procedure. */
void
}
-/* Checks whether DS has a corrupted active file. If so,
+/* Checks whether DS has a corrupted active dataset. If so,
discards it and returns false. If not, returns true without
doing anything. */
bool
{
ds->n_lag = MAX (ds->n_lag, n_before);
}
+\f
+static void
+dataset_changed__ (struct dataset *ds)
+{
+ if (ds->callbacks != NULL && ds->callbacks->changed != NULL)
+ ds->callbacks->changed (ds->cb_data);
+}
+
+static void
+dataset_transformations_changed__ (struct dataset *ds, bool non_empty)
+{
+ if (ds->callbacks != NULL && ds->callbacks->transformations_changed != NULL)
+ ds->callbacks->transformations_changed (non_empty, ds->cb_data);
+}