/* PSPPIRE --- A Graphical User Interface for PSPP Copyright (C) 2004 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 the Free Software Foundation; either version 2 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. 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "pspp-object.h" #include "pspp-dict.h" /* --- prototypes --- */ static void pspp_dict_class_init (PSPP_DictClass *class); static void pspp_dict_init (PSPP_Dict *accel_group); static void pspp_dict_finalize (GObject *object); /* --- variables --- */ static GObjectClass *parent_class = NULL; /* --- functions --- */ /** * pspp_dict_get_type: * @returns: the type ID for accelerator groups. */ GType pspp_dict_get_type (void) { static GType object_type = 0; if (!object_type) { static const GTypeInfo object_info = { sizeof (PSPP_DictClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pspp_dict_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (PSPP_Dict), 0, /* n_preallocs */ (GInstanceInitFunc) pspp_dict_init, }; object_type = g_type_register_static (G_TYPE_PSPP_OBJECT, "PSPP_Dict", &object_info, 0); } return object_type; } #if 0 static guint signal_subject_changed = 0 ; #endif static void pspp_dict_class_init (PSPP_DictClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); parent_class = g_type_class_peek_parent (class); object_class->finalize = pspp_dict_finalize; #if 0 signal_subject_changed = g_signal_new ("subject_changed", G_OBJECT_CLASS_TYPE (class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); #endif } static void pspp_dict_finalize (GObject *object) { PSPP_Dict *accel_group = PSPP_DICT (object); guint i; /* g_free (accel_group->priv_accels); */ G_OBJECT_CLASS (parent_class)->finalize (object); } static void pspp_dict_init (PSPP_Dict *pspp_dict) { pspp_dict->array = g_ptr_array_new(); } /** * pspp_dict_new: * @returns: a new #PSPP_Dict object * * Creates a new #PSPP_Dict. */ PSPP_Dict* pspp_dict_new (void) { return g_object_new (G_TYPE_PSPP_DICT, NULL); } void pspp_dict_delete_var(PSPP_Dict *d, gint idx) { struct variable *var; g_assert(d); g_assert(G_IS_PSPP_DICT(d)); /* Do nothing if it's out of bounds */ if ( idx >= d->array->len) return; var = g_ptr_array_index(d->array,idx); g_ptr_array_remove_index(d->array,idx); g_free(var); g_signal_emit_by_name(d, "changed"); } void pspp_dict_set_name(PSPP_Dict* d, gint idx, const gchar *name) { struct variable *var; g_assert(d); g_assert(G_IS_PSPP_DICT(d)); if ( idx < d->array->len) { /* This is an existing variable? */ var = g_ptr_array_index(d->array,idx); } else { /* new variable */ var = g_malloc(sizeof(struct variable)); g_ptr_array_add(d->array,var); } strncpy(var->name,name,9); g_signal_emit_by_name(d, "changed"); }