-/*
- 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
- 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
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <string.h>
#include <data/case.h>
#include <data/data-in.h>
#include <data/datasheet.h>
+#include <data/casereader.h>
#include <math/sort.h>
#include <libpspp/misc.h>
#include "xalloc.h"
-#include "xallocsa.h"
+#include "xmalloca.h"
/* --- prototypes --- */
static void psppire_case_file_class_init (PsppireCaseFileClass *class);
object_class->finalize = psppire_case_file_finalize;
signals [CASE_CHANGED] =
- g_signal_new ("case_changed",
+ g_signal_new ("case-changed",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_FIRST,
0,
signals [CASE_INSERTED] =
- g_signal_new ("case_inserted",
+ g_signal_new ("case-inserted",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_FIRST,
0,
signals [CASES_DELETED] =
- g_signal_new ("cases_deleted",
+ g_signal_new ("cases-deleted",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_FIRST,
0,
{
PsppireCaseFile *cf = PSPPIRE_CASE_FILE (object);
- datasheet_destroy (cf->datasheet);
+ if ( cf->accessible)
+ datasheet_destroy (cf->datasheet);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
psppire_case_file_init (PsppireCaseFile *cf)
{
cf->datasheet = NULL;
+ cf->accessible = FALSE;
}
* Creates a new #PsppireCaseFile.
*/
PsppireCaseFile*
-psppire_case_file_new (void)
+psppire_case_file_new (const struct casereader *reader)
{
PsppireCaseFile *cf = g_object_new (G_TYPE_PSPPIRE_CASE_FILE, NULL);
- cf->datasheet = datasheet_create (NULL);
+ cf->datasheet = datasheet_create (casereader_clone (reader));
+ cf->accessible = TRUE;
return cf;
}
-void
-psppire_case_file_replace_datasheet (PsppireCaseFile *cf, struct datasheet *ds)
-{
- cf->datasheet = ds;
-}
-
-
-
gboolean
psppire_case_file_delete_cases (PsppireCaseFile *cf, gint n_cases, gint first)
{
psppire_case_file_get_case_count (const PsppireCaseFile *cf)
{
g_return_val_if_fail (cf, FALSE);
+ g_return_val_if_fail (cf->accessible, FALSE);
if ( ! cf->datasheet)
return 0;
union value *value, int width)
{
bool allocated;
-
+
g_return_val_if_fail (cf, false);
g_return_val_if_fail (cf->datasheet, false);
g_return_val_if_fail (idx < datasheet_get_column_cnt (cf->datasheet), false);
- if (value == NULL)
+ if (value == NULL)
{
value = xnmalloc (value_cnt_from_width (width), sizeof *value);
allocated = true;
allocated = false;
if (!datasheet_get_value (cf->datasheet, casenum, idx, value, width))
{
- if (allocated)
+ if (allocated)
free (value);
value = NULL;
}
g_return_val_if_fail (idx < datasheet_get_column_cnt (cf->datasheet), FALSE);
width = fmt_var_width (fmt);
- value = xallocsa (value_cnt_from_width (width) * sizeof *value);
+ value = xmalloca (value_cnt_from_width (width) * sizeof *value);
ok = (datasheet_get_value (cf->datasheet, casenum, idx, value, width)
&& data_in (input, fmt->type, 0, 0, value, width)
&& datasheet_put_value (cf->datasheet, casenum, idx, value, width));
if (ok)
g_signal_emit (cf, signals [CASE_CHANGED], 0, casenum);
- freesa (value);
+ freea (value);
return TRUE;
}
{
union value *values;
g_return_val_if_fail (cf, FALSE);
+ g_return_val_if_fail (cf->accessible, FALSE);
if ( ! cf->datasheet )
cf->datasheet = datasheet_create (NULL);
return datasheet_get_row (cf->datasheet, casenum, c);
}
+
+
+
+struct casereader *
+psppire_case_file_make_reader (PsppireCaseFile *cf)
+{
+ struct casereader *r = datasheet_make_reader (cf->datasheet);
+ cf->accessible = FALSE;
+ return r;
+}
+