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);
}
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)
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
{
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);
+}
bool dataset_set_source (struct dataset *, struct casereader *);
struct casereader *dataset_steal_source (struct dataset *);
-void dataset_set_callback (struct dataset *, void (*cb) (void *), void *);
-
void dataset_set_default_syntax_encoding (struct dataset *, const char *);
const char *dataset_get_default_syntax_encoding (const struct dataset *);
+
+struct dataset_callbacks
+ {
+ /* Called whenever a procedure completes execution or whenever the
+ dictionary within the dataset is modified (though not when it is
+ replaced by a new dictionary). */
+ void (*changed) (void *aux);
+
+ /* Called whenever a transformation is added or removed. NON_EMPTY is true
+ if after the change there is at least one transformation, false if there
+ are no transformations. */
+ void (*transformations_changed) (bool non_empty, void *aux);
+ };
+
+void dataset_set_callbacks (struct dataset *, const struct dataset_callbacks *,
+ void *aux);
\f
/* Transformations. */
\f
/* Procedures. */
-typedef void transformation_change_callback_func (bool non_empty, void *aux);
-
-
-void dataset_add_transform_change_callback (struct dataset *,
- transformation_change_callback_func *, void *);
-
void proc_discard_output (struct dataset *ds);
bool proc_execute (struct dataset *ds);
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
static void
psppire_data_window_init (PsppireDataWindow *de)
{
+ static const struct dataset_callbacks cbs =
+ {
+ set_unsaved, /* changed */
+ transformation_change_callback, /* transformations_changed */
+ };
+
PsppireVarStore *vs;
PsppireDict *dict = NULL;
g_signal_connect_swapped (the_data_store, "cases-deleted",
G_CALLBACK (set_unsaved), de);
- dataset_set_callback (the_dataset, set_unsaved, de);
+ dataset_set_callbacks (the_dataset, &cbs, de);
connect_help (de->builder);
g_signal_connect_swapped (de->data_editor, "data-available-changed",
G_CALLBACK (set_paste_menuitem_sensitivity), de);
- dataset_add_transform_change_callback (the_dataset,
- transformation_change_callback,
- de);
-
-
vs = the_var_store;
g_assert(vs); /* Traps a possible bug in w32 build */