1 /* list.c generated by valac, the Vala compiler
2 * generated from list.vala, do not modify */
3
4 /* list.vala
5 *
6 * Copyright (C) 2007 Jürg Billeter
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * Author:
23 * Jürg Billeter <j@bitron.ch>
24 */
25
26 #include "valagee.h"
27 #include <glib-object.h>
28 #include <glib.h>
29
30 #define _vala_iterator_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterator_unref (var), NULL)))
31
32 struct _ValaListPrivate {
33 GType g_type;
34 GBoxedCopyFunc g_dup_func;
35 GDestroyNotify g_destroy_func;
36 };
37
38 static gint ValaList_private_offset;
39 static gpointer vala_list_parent_class = NULL;
40
41 static gpointer vala_list_real_get (ValaList* self,
42 gint index);
43 static void vala_list_real_set (ValaList* self,
44 gint index,
45 gconstpointer item);
46 static gint vala_list_real_index_of (ValaList* self,
47 gconstpointer item);
48 static void vala_list_real_insert (ValaList* self,
49 gint index,
50 gconstpointer item);
51 static gpointer vala_list_real_remove_at (ValaList* self,
52 gint index);
53 static gpointer vala_list_real_first (ValaList* self);
54 static gpointer vala_list_real_last (ValaList* self);
55 static void vala_list_real_insert_all (ValaList* self,
56 gint index,
57 ValaCollection* collection);
58 static void vala_list_real_sort (ValaList* self,
59 GCompareDataFunc compare_func,
60 gpointer compare_func_target,
61 GDestroyNotify compare_func_target_destroy_notify);
62 G_GNUC_INTERNAL void vala_tim_sort_sort (GType g_type,
63 GBoxedCopyFunc g_dup_func,
64 GDestroyNotify g_destroy_func,
65 ValaList* list,
66 GCompareDataFunc compare,
67 gpointer compare_target);
68 static GType vala_list_get_type_once (void);
69
70 static inline gpointer
vala_list_get_instance_private(ValaList * self)71 vala_list_get_instance_private (ValaList* self)
72 {
73 return G_STRUCT_MEMBER_P (self, ValaList_private_offset);
74 }
75
76 /**
77 * Returns the item at the specified index in this list.
78 *
79 * @param index zero-based index of the item to be returned
80 *
81 * @return the item at the specified index in the list
82 */
83 static gpointer
vala_list_real_get(ValaList * self,gint index)84 vala_list_real_get (ValaList* self,
85 gint index)
86 {
87 g_critical ("Type `%s' does not implement abstract method `vala_list_get'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
88 return NULL;
89 }
90
91 gpointer
vala_list_get(ValaList * self,gint index)92 vala_list_get (ValaList* self,
93 gint index)
94 {
95 g_return_val_if_fail (self != NULL, NULL);
96 return VALA_LIST_GET_CLASS (self)->get (self, index);
97 }
98
99 /**
100 * Sets the item at the specified index in this list.
101 *
102 * @param index zero-based index of the item to be set
103 */
104 static void
vala_list_real_set(ValaList * self,gint index,gconstpointer item)105 vala_list_real_set (ValaList* self,
106 gint index,
107 gconstpointer item)
108 {
109 g_critical ("Type `%s' does not implement abstract method `vala_list_set'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
110 return;
111 }
112
113 void
vala_list_set(ValaList * self,gint index,gconstpointer item)114 vala_list_set (ValaList* self,
115 gint index,
116 gconstpointer item)
117 {
118 g_return_if_fail (self != NULL);
119 VALA_LIST_GET_CLASS (self)->set (self, index, item);
120 }
121
122 /**
123 * Returns the index of the first occurrence of the specified item in
124 * this list.
125 *
126 * @return the index of the first occurrence of the specified item, or
127 * -1 if the item could not be found
128 */
129 static gint
vala_list_real_index_of(ValaList * self,gconstpointer item)130 vala_list_real_index_of (ValaList* self,
131 gconstpointer item)
132 {
133 gint _tmp0_ = 0;
134 g_critical ("Type `%s' does not implement abstract method `vala_list_index_of'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
135 return _tmp0_;
136 }
137
138 gint
vala_list_index_of(ValaList * self,gconstpointer item)139 vala_list_index_of (ValaList* self,
140 gconstpointer item)
141 {
142 g_return_val_if_fail (self != NULL, 0);
143 return VALA_LIST_GET_CLASS (self)->index_of (self, item);
144 }
145
146 /**
147 * Inserts an item into this list at the specified position.
148 *
149 * @param index zero-based index at which item is inserted
150 * @param item item to insert into the list
151 */
152 static void
vala_list_real_insert(ValaList * self,gint index,gconstpointer item)153 vala_list_real_insert (ValaList* self,
154 gint index,
155 gconstpointer item)
156 {
157 g_critical ("Type `%s' does not implement abstract method `vala_list_insert'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
158 return;
159 }
160
161 void
vala_list_insert(ValaList * self,gint index,gconstpointer item)162 vala_list_insert (ValaList* self,
163 gint index,
164 gconstpointer item)
165 {
166 g_return_if_fail (self != NULL);
167 VALA_LIST_GET_CLASS (self)->insert (self, index, item);
168 }
169
170 /**
171 * Removes the item at the specified index of this list.
172 *
173 * @param index zero-based index of the item to be removed
174 *
175 * @return the removed element
176 */
177 static gpointer
vala_list_real_remove_at(ValaList * self,gint index)178 vala_list_real_remove_at (ValaList* self,
179 gint index)
180 {
181 g_critical ("Type `%s' does not implement abstract method `vala_list_remove_at'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
182 return NULL;
183 }
184
185 gpointer
vala_list_remove_at(ValaList * self,gint index)186 vala_list_remove_at (ValaList* self,
187 gint index)
188 {
189 g_return_val_if_fail (self != NULL, NULL);
190 return VALA_LIST_GET_CLASS (self)->remove_at (self, index);
191 }
192
193 /**
194 * Returns the first item of the list. Fails if the list is empty.
195 *
196 * @return first item in the list
197 */
198 static gpointer
vala_list_real_first(ValaList * self)199 vala_list_real_first (ValaList* self)
200 {
201 gpointer _tmp0_;
202 gpointer result = NULL;
203 _tmp0_ = vala_list_get (self, 0);
204 result = _tmp0_;
205 return result;
206 }
207
208 gpointer
vala_list_first(ValaList * self)209 vala_list_first (ValaList* self)
210 {
211 g_return_val_if_fail (self != NULL, NULL);
212 return VALA_LIST_GET_CLASS (self)->first (self);
213 }
214
215 /**
216 * Returns the last item of the list. Fails if the list is empty.
217 *
218 * @return last item in the list
219 */
220 static gpointer
vala_list_real_last(ValaList * self)221 vala_list_real_last (ValaList* self)
222 {
223 gint _tmp0_;
224 gint _tmp1_;
225 gpointer _tmp2_;
226 gpointer result = NULL;
227 _tmp0_ = vala_collection_get_size ((ValaCollection*) self);
228 _tmp1_ = _tmp0_;
229 _tmp2_ = vala_list_get (self, _tmp1_ - 1);
230 result = _tmp2_;
231 return result;
232 }
233
234 gpointer
vala_list_last(ValaList * self)235 vala_list_last (ValaList* self)
236 {
237 g_return_val_if_fail (self != NULL, NULL);
238 return VALA_LIST_GET_CLASS (self)->last (self);
239 }
240
241 /**
242 * Inserts items into this list for the input collection at the
243 * specified position.
244 *
245 * @param index zero-based index of the items to be inserted
246 * @param collection collection of items to be inserted
247 */
248 static void
vala_list_real_insert_all(ValaList * self,gint index,ValaCollection * collection)249 vala_list_real_insert_all (ValaList* self,
250 gint index,
251 ValaCollection* collection)
252 {
253 g_return_if_fail (collection != NULL);
254 {
255 ValaIterator* iter = NULL;
256 ValaIterator* _tmp0_;
257 _tmp0_ = vala_iterable_iterator ((ValaIterable*) collection);
258 iter = _tmp0_;
259 {
260 gboolean _tmp1_ = FALSE;
261 _tmp1_ = TRUE;
262 while (TRUE) {
263 ValaIterator* _tmp2_;
264 gpointer item = NULL;
265 ValaIterator* _tmp3_;
266 gpointer _tmp4_;
267 gconstpointer _tmp5_;
268 gint _tmp6_;
269 if (!_tmp1_) {
270 }
271 _tmp1_ = FALSE;
272 _tmp2_ = iter;
273 if (!vala_iterator_next (_tmp2_)) {
274 break;
275 }
276 _tmp3_ = iter;
277 _tmp4_ = vala_iterator_get (_tmp3_);
278 item = _tmp4_;
279 _tmp5_ = item;
280 vala_list_insert (self, index, _tmp5_);
281 _tmp6_ = index;
282 index = _tmp6_ + 1;
283 ((item == NULL) || (self->priv->g_destroy_func == NULL)) ? NULL : (item = (self->priv->g_destroy_func (item), NULL));
284 }
285 }
286 _vala_iterator_unref0 (iter);
287 }
288 }
289
290 void
vala_list_insert_all(ValaList * self,gint index,ValaCollection * collection)291 vala_list_insert_all (ValaList* self,
292 gint index,
293 ValaCollection* collection)
294 {
295 g_return_if_fail (self != NULL);
296 VALA_LIST_GET_CLASS (self)->insert_all (self, index, collection);
297 }
298
299 /**
300 * Sorts items by comparing with the specified compare function.
301 *
302 * @param compare_func compare function to use to compare items
303 */
304 static void
vala_list_real_sort(ValaList * self,GCompareDataFunc compare_func,gpointer compare_func_target,GDestroyNotify compare_func_target_destroy_notify)305 vala_list_real_sort (ValaList* self,
306 GCompareDataFunc compare_func,
307 gpointer compare_func_target,
308 GDestroyNotify compare_func_target_destroy_notify)
309 {
310 vala_tim_sort_sort (self->priv->g_type, (GBoxedCopyFunc) self->priv->g_dup_func, (GDestroyNotify) self->priv->g_destroy_func, self, compare_func, compare_func_target);
311 (compare_func_target_destroy_notify == NULL) ? NULL : (compare_func_target_destroy_notify (compare_func_target), NULL);
312 compare_func = NULL;
313 compare_func_target = NULL;
314 compare_func_target_destroy_notify = NULL;
315 }
316
317 void
vala_list_sort(ValaList * self,GCompareDataFunc compare_func,gpointer compare_func_target,GDestroyNotify compare_func_target_destroy_notify)318 vala_list_sort (ValaList* self,
319 GCompareDataFunc compare_func,
320 gpointer compare_func_target,
321 GDestroyNotify compare_func_target_destroy_notify)
322 {
323 g_return_if_fail (self != NULL);
324 VALA_LIST_GET_CLASS (self)->sort (self, compare_func, compare_func_target, compare_func_target_destroy_notify);
325 }
326
327 ValaList*
vala_list_construct(GType object_type,GType g_type,GBoxedCopyFunc g_dup_func,GDestroyNotify g_destroy_func)328 vala_list_construct (GType object_type,
329 GType g_type,
330 GBoxedCopyFunc g_dup_func,
331 GDestroyNotify g_destroy_func)
332 {
333 ValaList* self = NULL;
334 self = (ValaList*) vala_collection_construct (object_type, g_type, (GBoxedCopyFunc) g_dup_func, (GDestroyNotify) g_destroy_func);
335 self->priv->g_type = g_type;
336 self->priv->g_dup_func = g_dup_func;
337 self->priv->g_destroy_func = g_destroy_func;
338 return self;
339 }
340
341 static void
vala_list_class_init(ValaListClass * klass,gpointer klass_data)342 vala_list_class_init (ValaListClass * klass,
343 gpointer klass_data)
344 {
345 vala_list_parent_class = g_type_class_peek_parent (klass);
346 g_type_class_adjust_private_offset (klass, &ValaList_private_offset);
347 ((ValaListClass *) klass)->get = (gpointer (*) (ValaList*, gint)) vala_list_real_get;
348 ((ValaListClass *) klass)->set = (void (*) (ValaList*, gint, gconstpointer)) vala_list_real_set;
349 ((ValaListClass *) klass)->index_of = (gint (*) (ValaList*, gconstpointer)) vala_list_real_index_of;
350 ((ValaListClass *) klass)->insert = (void (*) (ValaList*, gint, gconstpointer)) vala_list_real_insert;
351 ((ValaListClass *) klass)->remove_at = (gpointer (*) (ValaList*, gint)) vala_list_real_remove_at;
352 ((ValaListClass *) klass)->first = (gpointer (*) (ValaList*)) vala_list_real_first;
353 ((ValaListClass *) klass)->last = (gpointer (*) (ValaList*)) vala_list_real_last;
354 ((ValaListClass *) klass)->insert_all = (void (*) (ValaList*, gint, ValaCollection*)) vala_list_real_insert_all;
355 ((ValaListClass *) klass)->sort = (void (*) (ValaList*, GCompareDataFunc, gpointer, GDestroyNotify)) vala_list_real_sort;
356 }
357
358 static void
vala_list_instance_init(ValaList * self,gpointer klass)359 vala_list_instance_init (ValaList * self,
360 gpointer klass)
361 {
362 self->priv = vala_list_get_instance_private (self);
363 }
364
365 /**
366 * Represents a collection of items in a well-defined order.
367 */
368 static GType
vala_list_get_type_once(void)369 vala_list_get_type_once (void)
370 {
371 static const GTypeInfo g_define_type_info = { sizeof (ValaListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaList), 0, (GInstanceInitFunc) vala_list_instance_init, NULL };
372 GType vala_list_type_id;
373 vala_list_type_id = g_type_register_static (VALA_TYPE_COLLECTION, "ValaList", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
374 ValaList_private_offset = g_type_add_instance_private (vala_list_type_id, sizeof (ValaListPrivate));
375 return vala_list_type_id;
376 }
377
378 GType
vala_list_get_type(void)379 vala_list_get_type (void)
380 {
381 static volatile gsize vala_list_type_id__volatile = 0;
382 if (g_once_init_enter (&vala_list_type_id__volatile)) {
383 GType vala_list_type_id;
384 vala_list_type_id = vala_list_get_type_once ();
385 g_once_init_leave (&vala_list_type_id__volatile, vala_list_type_id);
386 }
387 return vala_list_type_id__volatile;
388 }
389
390