};
static struct measure_guesser *
-measure_guesser_create (struct dictionary *dict)
+measure_guesser_create__ (struct dictionary *dict)
{
struct mg_var *mgvs = NULL;
size_t n_mgvs = 0;
return mg;
}
+/* Scans through DS's dictionary for variables that have an unknown measurement
+ level. For those, if the measurement level can be guessed based on the
+ variable's type and format, sets a default. If that's enough, returns NULL.
+ If any remain whose levels are unknown and can't be guessed that way,
+ creates and returns a structure that the caller should pass to
+ measure_guesser_add_case() or measure_guesser_run() for guessing a
+ measurement level based on the data. */
+struct measure_guesser *
+measure_guesser_create (struct dataset *ds)
+{
+ return measure_guesser_create__ (dataset_dict (ds));
+}
+
+/* Adds data from case C to MG. */
static void
measure_guesser_add_case (struct measure_guesser *mg, const struct ccase *c)
{
}
}
-static void
+/* Destroys MG. */
+void
measure_guesser_destroy (struct measure_guesser *mg)
{
if (!mg)
free (mg);
}
+/* Adds final measurement levels based on MG, after all the cases have been
+ added. */
static void
measure_guesser_commit (struct measure_guesser *mg)
{
}
}
-bool
-measure_guesser_is_needed (struct dataset *ds)
-{
- struct measure_guesser *mg = measure_guesser_create (dataset_dict (ds));
- if (mg)
- {
- measure_guesser_destroy (mg);
- return true;
- }
- return false;
-}
-
+/* Passes the cases in READER through MG and uses the data in the cases to set
+ measurement levels for the variables where they were still unknown. */
void
-measure_guesser_run (struct dataset *ds, const struct casereader *reader)
+measure_guesser_run (struct measure_guesser *mg,
+ const struct casereader *reader)
{
- struct measure_guesser *mg = measure_guesser_create (dataset_dict (ds));
- if (!mg)
- return;
-
struct casereader *r = casereader_clone (reader);
while (mg->n_vars > 0)
{
casereader_destroy (r);
measure_guesser_commit (mg);
- measure_guesser_destroy (mg);
}
\f
static enum trns_result
static void
add_measurement_level_trns (struct dataset *ds, struct dictionary *dict)
{
- struct measure_guesser *mg = measure_guesser_create (dict);
+ struct measure_guesser *mg = measure_guesser_create__ (dict);
if (mg)
add_transformation (ds, &mg_trns_class, mg);
}
bool dataset_end_of_command (struct dataset *);
\f
-bool measure_guesser_is_needed (struct dataset *);
-void measure_guesser_run (struct dataset *, const struct casereader *);
+struct measure_guesser *measure_guesser_create (struct dataset *);
+void measure_guesser_run (struct measure_guesser *, const struct casereader *);
+void measure_guesser_destroy (struct measure_guesser *);
\f
const struct ccase *lagged_case (const struct dataset *ds, int n_before);
void dataset_need_lag (struct dataset *ds, int n_before);
int
cmd_ctables (struct lexer *lexer, struct dataset *ds)
{
- struct casereader *input;
- if (measure_guesser_is_needed (ds))
+ struct casereader *input = NULL;
+
+ struct measure_guesser *mg = measure_guesser_create (ds);
+ if (mg)
{
input = proc_open (ds);
- measure_guesser_run (ds, input);
+ measure_guesser_run (mg, input);
+ measure_guesser_destroy (mg);
}
- else
- input = NULL;
size_t n_vars = dict_get_n_vars (dataset_dict (ds));
enum ctables_vlabel *vlabels = xnmalloc (n_vars, sizeof *vlabels);