projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Applied patch #5653, which adds callbacks to dataset whenever its dictionary or
[pspp-builds.git]
/
src
/
ui
/
gui
/
psppire-case-file.c
diff --git
a/src/ui/gui/psppire-case-file.c
b/src/ui/gui/psppire-case-file.c
index 7e16087eb93ae7bfe2057d72fdc49cb3d9e48136..ef1edfc28823480abb552ba482c28ea3900e5672 100644
(file)
--- 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
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
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
@@
-29,6
+28,7
@@
#include <data/case.h>
#include <ui/flexifile.h>
#include <data/case.h>
#include <ui/flexifile.h>
+#include "flexifile-factory.h"
#include <data/casefile.h>
#include <data/data-in.h>
#include <math/sort.h>
#include <data/casefile.h>
#include <data/data-in.h>
#include <math/sort.h>
@@
-43,7
+43,7
@@
static void psppire_case_file_finalize (GObject *object);
/* --- variables --- */
static GObjectClass *parent_class = NULL;
/* --- variables --- */
static GObjectClass *parent_class = NULL;
-enum {CASE_CHANGED,
+enum {CASE_CHANGED,
CASE_INSERTED,
CASES_DELETED,
n_SIGNALS};
CASE_INSERTED,
CASES_DELETED,
n_SIGNALS};
@@
-94,36
+94,36
@@
psppire_case_file_class_init (PsppireCaseFileClass *class)
signal[CASE_CHANGED] =
g_signal_new ("case_changed",
signal[CASE_CHANGED] =
g_signal_new ("case_changed",
- G_TYPE_FROM_CLASS(class),
+ G_TYPE_FROM_CLASS
(class),
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__INT,
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__INT,
- G_TYPE_NONE,
+ G_TYPE_NONE,
1,
G_TYPE_INT);
signal[CASE_INSERTED] =
g_signal_new ("case_inserted",
1,
G_TYPE_INT);
signal[CASE_INSERTED] =
g_signal_new ("case_inserted",
- G_TYPE_FROM_CLASS(class),
+ G_TYPE_FROM_CLASS
(class),
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__INT,
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__INT,
- G_TYPE_NONE,
+ G_TYPE_NONE,
1,
G_TYPE_INT);
signal[CASES_DELETED] =
g_signal_new ("cases_deleted",
1,
G_TYPE_INT);
signal[CASES_DELETED] =
g_signal_new ("cases_deleted",
- G_TYPE_FROM_CLASS(class),
+ G_TYPE_FROM_CLASS
(class),
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
gtkextra_VOID__INT_INT,
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
gtkextra_VOID__INT_INT,
- G_TYPE_NONE,
+ G_TYPE_NONE,
2,
G_TYPE_INT, G_TYPE_INT);
}
2,
G_TYPE_INT, G_TYPE_INT);
}
@@
-132,9
+132,9
@@
static void
psppire_case_file_finalize (GObject *object)
{
PsppireCaseFile *cf = PSPPIRE_CASE_FILE (object);
psppire_case_file_finalize (GObject *object)
{
PsppireCaseFile *cf = PSPPIRE_CASE_FILE (object);
-
- if ( cf->flexifile)
- casefile_destroy(cf->flexifile);
+
+ if ( cf->flexifile)
+ casefile_destroy
(cf->flexifile);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@
-145,148
+145,154
@@
psppire_case_file_init (PsppireCaseFile *cf)
cf->flexifile = 0;
}
cf->flexifile = 0;
}
+
/**
* psppire_case_file_new:
* @returns: a new #PsppireCaseFile object
/**
* psppire_case_file_new:
* @returns: a new #PsppireCaseFile object
- *
- * Creates a new #PsppireCaseFile.
+ *
+ * Creates a new #PsppireCaseFile.
*/
PsppireCaseFile*
*/
PsppireCaseFile*
-psppire_case_file_new (
gint val_cnt
)
+psppire_case_file_new (
void
)
{
PsppireCaseFile *cf = g_object_new (G_TYPE_PSPPIRE_CASE_FILE, NULL);
{
PsppireCaseFile *cf = g_object_new (G_TYPE_PSPPIRE_CASE_FILE, NULL);
- cf->flexifile = flexifile_create (val_cnt);
-
return cf;
}
return cf;
}
+void
+psppire_case_file_replace_flexifile (PsppireCaseFile *cf, struct flexifile *ff)
+{
+ cf->flexifile = (struct casefile *) ff;
+}
+
+
+
gboolean
gboolean
-psppire_case_file_delete_cases(PsppireCaseFile *cf, gint n_cases, gint first)
+psppire_case_file_delete_cases
(PsppireCaseFile *cf, gint n_cases, gint first)
{
int result;
{
int result;
- g_return_val_if_fail(cf, FALSE);
- g_return_val_if_fail(cf->flexifile, FALSE);
+ g_return_val_if_fail
(cf, FALSE);
+ g_return_val_if_fail
(cf->flexifile, FALSE);
- result = flexifile_delete_cases
(FLEXIFILE
(cf->flexifile), n_cases, first);
+ result = flexifile_delete_cases
(FLEXIFILE
(cf->flexifile), n_cases, first);
- g_signal_emit(cf, signal[CASES_DELETED], 0, n_cases, first);
+ g_signal_emit
(cf, signal[CASES_DELETED], 0, n_cases, first);
return result;
}
/* Insert case CC into the case file before POSN */
gboolean
return result;
}
/* 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)
{
bool result ;
struct ccase *cc,
gint posn)
{
bool result ;
- g_return_val_if_fail(cf, FALSE);
- g_return_val_if_fail(cf->flexifile, FALSE);
+ g_return_val_if_fail (cf, FALSE);
+ g_return_val_if_fail (cf->flexifile, FALSE);
+
+ result = flexifile_insert_case (FLEXIFILE (cf->flexifile), cc, posn);
- result = flexifile_insert_case(FLEXIFILE(cf->flexifile), cc, posn);
-
- if ( result )
- g_signal_emit(cf, signal[CASE_INSERTED], 0, posn);
+ if ( result )
+ g_signal_emit (cf, signal[CASE_INSERTED], 0, posn);
else
else
- g_warning("Cannot insert case at position %d\n", posn);
-
+ g_warning
("Cannot insert case at position %d\n", posn);
+
return result;
}
/* Append a case to the case file */
gboolean
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 ;
gint posn ;
struct ccase *c)
{
bool result ;
gint posn ;
- g_return_val_if_fail(cf, FALSE);
- g_return_val_if_fail(cf->flexifile, FALSE);
+ g_return_val_if_fail
(cf, FALSE);
+ g_return_val_if_fail
(cf->flexifile, FALSE);
- posn = casefile_get_case_cnt(cf->flexifile);
+ posn = casefile_get_case_cnt (cf->flexifile);
+
+ result = casefile_append (cf->flexifile, c);
+
+ g_signal_emit (cf, signal[CASE_INSERTED], 0, posn);
- result = casefile_append(cf->flexifile, c);
-
- g_signal_emit(cf, signal[CASE_INSERTED], 0, posn);
-
return result;
}
inline gint
return result;
}
inline gint
-psppire_case_file_get_case_count(const PsppireCaseFile *cf)
+psppire_case_file_get_case_count
(const PsppireCaseFile *cf)
{
{
- g_return_val_if_fail(cf, FALSE);
-
- if ( ! cf->flexifile)
+ g_return_val_if_fail
(cf, FALSE);
+
+ if ( ! cf->flexifile)
return 0;
return 0;
- return casefile_get_case_cnt(cf->flexifile);
+ return casefile_get_case_cnt
(cf->flexifile);
}
/* Return the IDXth value from case CASENUM.
The return value must not be freed or written to
*/
const union value *
}
/* Return the IDXth value from case CASENUM.
The return value must not be freed or written to
*/
const union value *
-psppire_case_file_get_value(const PsppireCaseFile *cf, gint casenum, gint idx)
+psppire_case_file_get_value
(const PsppireCaseFile *cf, gint casenum, gint idx)
{
{
- const union value *v;
+ const union value *v;
struct ccase c;
struct ccase c;
- g_return_val_if_fail(cf, NULL);
- g_return_val_if_fail(cf->flexifile, NULL);
+ g_return_val_if_fail
(cf, NULL);
+ g_return_val_if_fail
(cf->flexifile, NULL);
- g_return_val_if_fail
(idx < casefile_get_value_cnt
(cf->flexifile), NULL);
+ g_return_val_if_fail
(idx < casefile_get_value_cnt
(cf->flexifile), NULL);
- flexifile_get_case
(FLEXIFILE
(cf->flexifile), casenum, &c);
+ flexifile_get_case
(FLEXIFILE
(cf->flexifile), casenum, &c);
- v = case_data(&c, idx);
-
- case_destroy(&c);
+ v = case_data_idx (&c, idx);
+ case_destroy (&c);
return v;
}
void
return v;
}
void
-psppire_case_file_clear(PsppireCaseFile *cf)
+psppire_case_file_clear
(PsppireCaseFile *cf)
{
{
- casefile_destroy(cf->flexifile);
+ casefile_destroy
(cf->flexifile);
cf->flexifile = 0;
cf->flexifile = 0;
- g_signal_emit(cf, signal[CASES_DELETED], 0, 0, -1);
+ g_signal_emit
(cf, signal[CASES_DELETED], 0, 0, -1);
}
/* Set the IDXth value of case C to SYSMIS/EMPTY */
gboolean
}
/* Set the IDXth value of case C to SYSMIS/EMPTY */
gboolean
-psppire_case_file_set_value(PsppireCaseFile *cf, gint casenum, gint idx,
+psppire_case_file_set_value
(PsppireCaseFile *cf, gint casenum, gint idx,
union value *v, gint width)
{
struct ccase cc ;
int bytes;
union value *v, gint width)
{
struct ccase cc ;
int bytes;
- g_return_val_if_fail(cf, FALSE);
- g_return_val_if_fail(cf->flexifile, FALSE);
+ g_return_val_if_fail
(cf, FALSE);
+ g_return_val_if_fail
(cf->flexifile, FALSE);
- g_return_val_if_fail
(idx < casefile_get_value_cnt
(cf->flexifile), FALSE);
+ g_return_val_if_fail
(idx < casefile_get_value_cnt
(cf->flexifile), FALSE);
- if ( ! flexifile_get_case
(FLEXIFILE
(cf->flexifile), casenum, &cc) )
+ if ( ! flexifile_get_case
(FLEXIFILE
(cf->flexifile), casenum, &cc) )
return FALSE;
return FALSE;
- if ( width == 0 )
+ if ( width == 0 )
bytes = MAX_SHORT_STRING;
else
bytes = MAX_SHORT_STRING;
else
- bytes = DIV_RND_UP(width, MAX_SHORT_STRING) * MAX_SHORT_STRING ;
+ bytes = DIV_RND_UP
(width, MAX_SHORT_STRING) * MAX_SHORT_STRING ;
/* Cast away const in flagrant abuse of the casefile */
/* 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);
+ g_signal_emit
(cf, signal[CASE_CHANGED], 0, casenum);
return TRUE;
}
return TRUE;
}
@@
-295,84
+301,82
@@
psppire_case_file_set_value(PsppireCaseFile *cf, gint casenum, gint idx,
/* Set the IDXth value of case C using D_IN */
gboolean
/* Set the IDXth value of case C using D_IN */
gboolean
-psppire_case_file_data_in(PsppireCaseFile *cf, gint casenum, gint idx,
+psppire_case_file_data_in
(PsppireCaseFile *cf, gint casenum, gint idx,
struct substring input, const struct fmt_spec *fmt)
{
struct ccase cc ;
struct substring input, const struct fmt_spec *fmt)
{
struct ccase cc ;
- g_return_val_if_fail(cf, FALSE);
- g_return_val_if_fail(cf->flexifile, FALSE);
+ g_return_val_if_fail
(cf, FALSE);
+ g_return_val_if_fail
(cf->flexifile, FALSE);
- g_return_val_if_fail
(idx < casefile_get_value_cnt
(cf->flexifile), FALSE);
+ g_return_val_if_fail
(idx < casefile_get_value_cnt
(cf->flexifile), FALSE);
- if ( ! flexifile_get_case
(FLEXIFILE
(cf->flexifile), casenum, &cc) )
+ if ( ! flexifile_get_case
(FLEXIFILE
(cf->flexifile), casenum, &cc) )
return FALSE;
/* Cast away const in flagrant abuse of the casefile */
if (!data_in (input, fmt->type, 0, 0,
return FALSE;
/* Cast away const in flagrant abuse of the casefile */
if (!data_in (input, fmt->type, 0, 0,
- (union value *) case_data(&cc, idx), fmt_var_width (fmt)))
- g_warning("Cant set value\n");
+ (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);
+ g_signal_emit
(cf, signal[CASE_CHANGED], 0, casenum);
return TRUE;
}
void
return TRUE;
}
void
-psppire_case_file_sort(PsppireCaseFile *cf, const struct sort_criteria *sc)
+psppire_case_file_sort
(PsppireCaseFile *cf, const struct sort_criteria *sc)
{
{
- struct ccase cc;
gint c;
gint c;
- struct casefile *cfile;
+
struct casereader *reader = casefile_get_reader (cf->flexifile, NULL);
struct casereader *reader = casefile_get_reader (cf->flexifile, NULL);
-
const int value_cnt = casefile_get_value_cnt(cf->flexifile)
;
+
struct casefile *cfile
;
-
cfile = sort_execute(reader, sc
);
+
struct casefile_factory *factory = flexifile_factory_create (
);
- c
asefile_destroy(cf->flexifile
);
+ c
file = 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 */
/* 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 )
- g_signal_emit(cf, signal[CASE_CHANGED], 0, 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. */
one of them. */
-gboolean
-psppire_case_file_insert_values (PsppireCaseFile *cf,
+gboolean
+psppire_case_file_insert_values (PsppireCaseFile *cf,
gint n_values, gint before)
{
gint n_values, gint before)
{
- g_return_val_if_fail(cf, FALSE);
+ g_return_val_if_fail
(cf, FALSE);
- if ( ! cf->flexifile )
+ if ( ! cf->flexifile )
{
{
- cf->flexifile = flexifile_create(n_values);
+ cf->flexifile = flexifile_create (n_values);
+
return TRUE;
}
return TRUE;
}
- return flexifile_resize (FLEXIFILE(cf->flexifile), n_values, before);
+ return flexifile_resize (FLEXIFILE
(cf->flexifile), n_values, before);
}
/* Fills C with the CASENUMth case.
Returns true on success, false otherwise.
*/
gboolean
}
/* Fills C with the CASENUMth case.
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);
g_return_val_if_fail (cf->flexifile, FALSE);
struct ccase *c)
{
g_return_val_if_fail (cf, FALSE);
g_return_val_if_fail (cf->flexifile, FALSE);
- return flexifile_get_case (FLEXIFILE(cf->flexifile), casenum, c);
+ return flexifile_get_case (FLEXIFILE
(cf->flexifile), casenum, c);
}
}