X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-case-file.c;h=6c7942f551a0bfe34e86bd80c6d7b190c1098e8e;hb=cf63d499efd5e6ca3a7dcc6386b3b87bd31bfda9;hp=b16fd7cababb20f388c0bb73c0ccc1b8402183df;hpb=c2ccb0d20912f25021d9a6c24d9c2de1b81b87bf;p=pspp diff --git a/src/ui/gui/psppire-case-file.c b/src/ui/gui/psppire-case-file.c index b16fd7caba..6c7942f551 100644 --- a/src/ui/gui/psppire-case-file.c +++ b/src/ui/gui/psppire-case-file.c @@ -1,7 +1,6 @@ -/* +/* PSPPIRE --- A Graphical User Interface for PSPP Copyright (C) 2006 Free Software Foundation - Written by John Darrington 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 @@ -18,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - +#include #include #include @@ -29,6 +28,7 @@ #include #include +#include "flexifile-factory.h" #include #include #include @@ -43,7 +43,7 @@ static void psppire_case_file_finalize (GObject *object); /* --- variables --- */ static GObjectClass *parent_class = NULL; -enum {CASE_CHANGED, +enum {CASE_CHANGED, CASE_INSERTED, CASES_DELETED, n_SIGNALS}; @@ -99,7 +99,7 @@ psppire_case_file_class_init (PsppireCaseFileClass *class) 0, NULL, NULL, g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, + G_TYPE_NONE, 1, G_TYPE_INT); @@ -111,7 +111,7 @@ psppire_case_file_class_init (PsppireCaseFileClass *class) 0, NULL, NULL, g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, + G_TYPE_NONE, 1, G_TYPE_INT); @@ -123,7 +123,7 @@ psppire_case_file_class_init (PsppireCaseFileClass *class) 0, NULL, NULL, gtkextra_VOID__INT_INT, - G_TYPE_NONE, + G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); } @@ -132,8 +132,8 @@ static void psppire_case_file_finalize (GObject *object) { PsppireCaseFile *cf = PSPPIRE_CASE_FILE (object); - - if ( cf->flexifile) + + if ( cf->flexifile) casefile_destroy(cf->flexifile); G_OBJECT_CLASS (parent_class)->finalize (object); @@ -145,11 +145,12 @@ psppire_case_file_init (PsppireCaseFile *cf) cf->flexifile = 0; } + /** * psppire_case_file_new: * @returns: a new #PsppireCaseFile object - * - * Creates a new #PsppireCaseFile. + * + * Creates a new #PsppireCaseFile. */ PsppireCaseFile* psppire_case_file_new (gint val_cnt) @@ -162,6 +163,23 @@ psppire_case_file_new (gint val_cnt) } +/** + * psppire_case_file_new_from_flexifile: + * @returns: a new #PsppireCaseFile object + * + * Creates a new #PsppireCaseFile from an existing flexifile + */ +PsppireCaseFile* +psppire_case_file_new_from_flexifile (struct flexifile *ff) +{ + PsppireCaseFile *cf = g_object_new (G_TYPE_PSPPIRE_CASE_FILE, NULL); + + cf->flexifile = (struct casefile *) ff; + + return cf; +} + + gboolean psppire_case_file_delete_cases(PsppireCaseFile *cf, gint n_cases, gint first) { @@ -179,7 +197,7 @@ psppire_case_file_delete_cases(PsppireCaseFile *cf, gint n_cases, gint first) /* Insert case CC into the case file before POSN */ gboolean -psppire_case_file_insert_case(PsppireCaseFile *cf, +psppire_case_file_insert_case(PsppireCaseFile *cf, struct ccase *cc, gint posn) { @@ -189,19 +207,19 @@ psppire_case_file_insert_case(PsppireCaseFile *cf, g_return_val_if_fail(cf->flexifile, FALSE); result = flexifile_insert_case(FLEXIFILE(cf->flexifile), cc, posn); - - if ( result ) + + if ( result ) g_signal_emit(cf, signal[CASE_INSERTED], 0, posn); else g_warning("Cannot insert case at position %d\n", posn); - + return result; } /* Append a case to the case file */ gboolean -psppire_case_file_append_case(PsppireCaseFile *cf, +psppire_case_file_append_case(PsppireCaseFile *cf, struct ccase *c) { bool result ; @@ -213,9 +231,9 @@ psppire_case_file_append_case(PsppireCaseFile *cf, posn = casefile_get_case_cnt(cf->flexifile); result = casefile_append(cf->flexifile, c); - + g_signal_emit(cf, signal[CASE_INSERTED], 0, posn); - + return result; } @@ -224,8 +242,8 @@ inline gint psppire_case_file_get_case_count(const PsppireCaseFile *cf) { g_return_val_if_fail(cf, FALSE); - - if ( ! cf->flexifile) + + if ( ! cf->flexifile) return 0; return casefile_get_case_cnt(cf->flexifile); @@ -237,7 +255,7 @@ psppire_case_file_get_case_count(const PsppireCaseFile *cf) const union value * psppire_case_file_get_value(const PsppireCaseFile *cf, gint casenum, gint idx) { - const union value *v; + const union value *v; struct ccase c; g_return_val_if_fail(cf, NULL); @@ -247,8 +265,7 @@ psppire_case_file_get_value(const PsppireCaseFile *cf, gint casenum, gint idx) flexifile_get_case(FLEXIFILE(cf->flexifile), casenum, &c); - v = case_data(&c, idx); - + v = case_data_idx(&c, idx); case_destroy(&c); return v; @@ -278,13 +295,13 @@ psppire_case_file_set_value(PsppireCaseFile *cf, gint casenum, gint idx, if ( ! flexifile_get_case(FLEXIFILE(cf->flexifile), casenum, &cc) ) return FALSE; - if ( width == 0 ) + if ( width == 0 ) bytes = MAX_SHORT_STRING; else bytes = DIV_RND_UP(width, MAX_SHORT_STRING) * MAX_SHORT_STRING ; /* Cast away const in flagrant abuse of the casefile */ - memcpy((union value *)case_data(&cc, idx), v, bytes); + memcpy((union value *)case_data_idx(&cc, idx), v, bytes); g_signal_emit(cf, signal[CASE_CHANGED], 0, casenum); @@ -296,7 +313,7 @@ psppire_case_file_set_value(PsppireCaseFile *cf, gint casenum, gint idx, /* Set the IDXth value of case C using D_IN */ gboolean psppire_case_file_data_in(PsppireCaseFile *cf, gint casenum, gint idx, - struct data_in *d_in) + struct substring input, const struct fmt_spec *fmt) { struct ccase cc ; @@ -309,9 +326,8 @@ psppire_case_file_data_in(PsppireCaseFile *cf, gint casenum, gint idx, return FALSE; /* Cast away const in flagrant abuse of the casefile */ - d_in->v = (union value *) case_data(&cc, idx); - - if ( ! data_in(d_in) ) + if (!data_in (input, fmt->type, 0, 0, + (union value *) case_data_idx(&cc, idx), fmt_var_width (fmt))) g_warning("Cant set value\n"); g_signal_emit(cf, signal[CASE_CHANGED], 0, casenum); @@ -323,42 +339,40 @@ psppire_case_file_data_in(PsppireCaseFile *cf, gint casenum, gint idx, void psppire_case_file_sort(PsppireCaseFile *cf, const struct sort_criteria *sc) { - struct ccase cc; gint c; + + struct casereader *reader = casefile_get_reader (cf->flexifile, NULL); struct casefile *cfile; - struct casereader *reader = casefile_get_reader(cf->flexifile); - const int value_cnt = casefile_get_value_cnt(cf->flexifile); - cfile = sort_execute(reader, sc); + struct casefile_factory *factory = flexifile_factory_create (); - casefile_destroy(cf->flexifile); + cfile = sort_execute(reader, sc, factory); - /* Copy casefile into flexifile */ + casefile_destroy(cf->flexifile); - reader = casefile_get_destructive_reader(cfile); - cf->flexifile = flexifile_create(value_cnt); - while(casereader_read(reader, &cc)) - casefile_append(cf->flexifile, &cc); - + cf->flexifile = cfile; /* FIXME: Need to have a signal to change a range of cases, instead of calling a signal many times */ - for ( c = 0 ; c < casefile_get_case_cnt(cf->flexifile) ; ++c ) + for ( c = 0 ; c < casefile_get_case_cnt(cf->flexifile) ; ++c ) g_signal_emit(cf, signal[CASE_CHANGED], 0, c); + + flexifile_factory_destroy (factory); } -/* Resize the cases in the casefile, by inserting N_VALUES into every +/* Resize the cases in the casefile, by inserting N_VALUES into every one of them. */ -gboolean -psppire_case_file_insert_values (PsppireCaseFile *cf, +gboolean +psppire_case_file_insert_values (PsppireCaseFile *cf, gint n_values, gint before) { g_return_val_if_fail(cf, FALSE); - if ( ! cf->flexifile ) + if ( ! cf->flexifile ) { cf->flexifile = flexifile_create(n_values); + return TRUE; } @@ -369,7 +383,7 @@ psppire_case_file_insert_values (PsppireCaseFile *cf, Returns true on success, false otherwise. */ gboolean -psppire_case_file_get_case (const PsppireCaseFile *cf, gint casenum, +psppire_case_file_get_case (const PsppireCaseFile *cf, gint casenum, struct ccase *c) { g_return_val_if_fail (cf, FALSE);