libgeda
|
00001 /* gEDA - GPL Electronic Design Automation 00002 * libgeda - gEDA's library 00003 * Copyright (C) 1998-2000 Ales Hvezda 00004 * Copyright (C) 2007-2010 Peter Clifton 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00028 #include <config.h> 00029 00030 #include <glib-object.h> 00031 00032 #include "geda_list.h" 00033 00034 #ifdef HAVE_LIBDMALLOC 00035 #include <dmalloc.h> 00036 #endif 00037 00038 00039 enum { 00040 CHANGED, 00041 LAST_SIGNAL 00042 }; 00043 00044 static guint geda_list_signals[ LAST_SIGNAL ] = { 0 }; 00045 static GObjectClass *geda_list_parent_class = NULL; 00046 00047 00056 static void geda_list_instance_init( GTypeInstance *instance, gpointer g_class ) 00057 { 00058 GedaList *list = (GedaList *)instance; 00059 00060 /* Strictly un-necessary, as the memory is zero'd after allocation */ 00061 list->glist = NULL; 00062 } 00063 00064 00073 static void geda_list_finalize( GObject *object ) 00074 { 00075 GedaList *list = GEDA_LIST( object ); 00076 g_list_free( list->glist ); 00077 00078 G_OBJECT_CLASS( geda_list_parent_class )->finalize( object ); 00079 } 00080 00081 00091 static void geda_list_class_init( gpointer g_class, gpointer g_class_data ) 00092 { 00093 GedaListClass *klass = GEDA_LIST_CLASS( g_class ); 00094 GObjectClass *gobject_class = G_OBJECT_CLASS( klass ); 00095 geda_list_parent_class = g_type_class_peek_parent( klass ); 00096 00097 gobject_class->finalize = geda_list_finalize; 00098 00099 geda_list_signals[ CHANGED ] = 00100 g_signal_new ("changed", 00101 G_OBJECT_CLASS_TYPE( gobject_class ), 00102 0 /*signal_flags */, 00103 0 /*class_offset */, 00104 NULL, /* accumulator */ 00105 NULL, /* accu_data */ 00106 g_cclosure_marshal_VOID__VOID, 00107 G_TYPE_NONE, 00108 0 /* n_params */ 00109 ); 00110 } 00111 00112 00122 GType geda_list_get_type(void) 00123 { 00124 static GType type = 0; 00125 if (type == 0) { 00126 static const GTypeInfo info = { 00127 sizeof (GedaListClass), 00128 NULL, /* base_init */ 00129 NULL, /* base_finalize */ 00130 geda_list_class_init, /* class_init */ 00131 NULL, /* class_finalize */ 00132 NULL, /* class_data */ 00133 sizeof (GedaList), 00134 0, /* n_preallocs */ 00135 geda_list_instance_init /* instance_init */ 00136 }; 00137 type = g_type_register_static (G_TYPE_OBJECT, "GedaList", &info, 0); 00138 } 00139 return type; 00140 } 00141 00142 00150 GedaList *geda_list_new( void ) { 00151 return g_object_new( GEDA_TYPE_LIST, NULL ); 00152 } 00153 00154 00163 void geda_list_add( GedaList *list, gpointer item ) 00164 { 00165 list->glist = g_list_append(list->glist, item ); 00166 g_signal_emit( list, geda_list_signals[ CHANGED ], 0 ); 00167 } 00168 00169 00179 void geda_list_add_glist( GedaList *list, GList *items ) 00180 { 00181 GList *glist_copy = g_list_copy( items ); 00182 list->glist = g_list_concat(list->glist, glist_copy ); 00183 g_signal_emit( list, geda_list_signals[ CHANGED ], 0 ); 00184 } 00185 00186 00197 void geda_list_remove( GedaList *list, gpointer item ) 00198 { 00199 if (g_list_find(list->glist, item) == NULL) 00200 return; 00201 00202 list->glist = g_list_remove(list->glist, item); 00203 g_signal_emit( list, geda_list_signals[ CHANGED ], 0 ); 00204 } 00205 00206 00214 void geda_list_remove_all( GedaList *list ) 00215 { 00216 g_list_free(list->glist); 00217 list->glist = NULL; 00218 g_signal_emit( list, geda_list_signals[ CHANGED ], 0 ); 00219 } 00220