1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2000 Ales V. Hvezda
4 * Copyright (C) 2007 Peter Clifton
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
24 #include <glib-object.h>
26 #include "geda_list.h"
28 #ifdef HAVE_LIBDMALLOC
38 static guint geda_list_signals
[ LAST_SIGNAL
] = { 0 };
39 static GObjectClass
*geda_list_parent_class
= NULL
;
42 /*! \brief GType instance initialiser for GedaList
44 * \par Function Description
45 * GType instance initialiser for GedaList.
47 * \param [in] instance The GedaList we are initialising.
48 * \param [in] g_class The class of the type the instance is created for.
50 static void geda_list_instance_init( GTypeInstance
*instance
, gpointer g_class
)
52 GedaList
*list
= (GedaList
*)instance
;
54 /* Strictly un-necessary, as the memory is zero'd after allocation */
59 /*! \brief GObject finalise handler
61 * \par Function Description
62 * Just before the GedaList GObject is finalized, free our
63 * allocated data, and then chain up to the parent's finalize handler.
65 * \param [in] widget The GObject being finalized.
67 static void geda_list_finalize( GObject
*object
)
69 GedaList
*list
= GEDA_LIST( object
);
70 g_list_free( list
->glist
);
72 G_OBJECT_CLASS( geda_list_parent_class
)->finalize( object
);
76 /*! \brief GType class initialiser for GedaList
78 * \par Function Description
79 * GType class initialiser for GedaList. We override our parents
80 * virtual class methods as needed and register our GObject signals.
82 * \param [in] klass The GedaList we are initialising
84 static void geda_list_class_init( gpointer g_class
, gpointer g_class_data
)
86 GedaListClass
*klass
= GEDA_LIST_CLASS( g_class
);
87 GObjectClass
*gobject_class
= G_OBJECT_CLASS( klass
);
88 geda_list_parent_class
= g_type_class_peek_parent( klass
);
90 gobject_class
->finalize
= geda_list_finalize
;
92 geda_list_signals
[ CHANGED
] =
93 g_signal_new ("changed",
94 G_OBJECT_CLASS_TYPE( gobject_class
),
97 NULL
, /* accumulator */
99 g_cclosure_marshal_VOID__VOID
,
106 /*! \brief Function to retrieve GedaList's GType identifier.
108 * \par Function Description
109 * Function to retrieve GedaList's GType identifier.
110 * Upon first call, this registers the GedaList in the GType system.
111 * Subsequently it returns the saved value from its first execution.
113 * \return the GType identifier associated with GedaList.
115 GType
geda_list_get_type(void)
117 static GType type
= 0;
119 static const GTypeInfo info
= {
120 sizeof (GedaListClass
),
121 NULL
, /* base_init */
122 NULL
, /* base_finalize */
123 geda_list_class_init
, /* class_init */
124 NULL
, /* class_finalize */
125 NULL
, /* class_data */
128 geda_list_instance_init
/* instance_init */
130 type
= g_type_register_static (G_TYPE_OBJECT
, "GedaList", &info
, 0);
136 /*! \brief Returns a pointer to a new GedaList object.
138 * \par Function Description
139 * Returns a pointer to a new GedaList object.
141 * \return pointer to the new GedaList object.
143 GedaList
*geda_list_new( void ) {
144 return g_object_new( GEDA_TYPE_LIST
, NULL
);
148 /*! \brief Adds the given item to the GedaList
150 * \par Function Description
151 * Adds the given item to the GedaList
153 * \param [in] list Pointer to the GedaList
154 * \param [in] item item to add to the GedaList.
156 void geda_list_add( GedaList
*list
, gpointer item
)
158 list
->glist
= g_list_append(list
->glist
, item
);
159 g_signal_emit( list
, geda_list_signals
[ CHANGED
], 0 );
163 /*! \brief Adds the given glist of items to the GedaList
165 * \par Function Description
166 * Adds the given glist of items to the GedaList
167 * A copy is made, so the original GList is not modified.
169 * \param [in] list Pointer to the GedaList
170 * \param [in] items GList of items to add to the GedaList.
172 void geda_list_add_glist( GedaList
*list
, GList
*items
)
174 GList
*glist_copy
= g_list_copy( items
);
175 list
->glist
= g_list_concat(list
->glist
, glist_copy
);
176 g_signal_emit( list
, geda_list_signals
[ CHANGED
], 0 );
180 /*! \brief Removes the given item from the GedaList
182 * \par Function Description
183 * Removes the given item from the GedaList.
184 * It's ok to call this function with an item which
185 * is not necessarily in the list.
187 * \param [in] list Pointer to the GedaList
188 * \param [in] item to remove from the GedaList.
190 void geda_list_remove( GedaList
*list
, gpointer item
)
192 if (g_list_find(list
->glist
, item
) == NULL
)
195 list
->glist
= g_list_remove(list
->glist
, item
);
196 g_signal_emit( list
, geda_list_signals
[ CHANGED
], 0 );
200 /*! \brief Removes all the items in the given GedaList.
202 * \par Function Description
203 * Removes all items in the given GedaList.
205 * \param [in] list Pointer to the GedaList
207 void geda_list_remove_all( GedaList
*list
)
209 g_list_free(list
->glist
);
211 g_signal_emit( list
, geda_list_signals
[ CHANGED
], 0 );