Update Changelog
[profile/ivi/libgee.git] / gee / mapiterator.c
1 /* mapiterator.c generated by valac 0.18.0, the Vala compiler
2  * generated from mapiterator.vala, do not modify */
3
4 /* mapiterator.vala
5  *
6  * Copyright (C) 2009  Didier Villevalois
7  * Copyright (C) 2011  Maciej Piechotka
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
22  *
23  * Author:
24  *      Didier 'Ptitjes Villevalois <ptitjes@free.fr>
25  */
26
27 #include <glib.h>
28 #include <glib-object.h>
29
30
31 #define GEE_TYPE_MAP_ITERATOR (gee_map_iterator_get_type ())
32 #define GEE_MAP_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_MAP_ITERATOR, GeeMapIterator))
33 #define GEE_IS_MAP_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_MAP_ITERATOR))
34 #define GEE_MAP_ITERATOR_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEE_TYPE_MAP_ITERATOR, GeeMapIteratorIface))
35
36 typedef struct _GeeMapIterator GeeMapIterator;
37 typedef struct _GeeMapIteratorIface GeeMapIteratorIface;
38 #define _a_destroy_func0(var) (((var == NULL) || (a_destroy_func == NULL)) ? NULL : (var = (a_destroy_func (var), NULL)))
39
40 typedef gpointer (*GeeFoldMapFunc) (gconstpointer k, gconstpointer v, gpointer a, void* user_data);
41 typedef gboolean (*GeeForallMapFunc) (gconstpointer k, gconstpointer v, void* user_data);
42 struct _GeeMapIteratorIface {
43         GTypeInterface parent_iface;
44         GType (*get_k_type) (GeeMapIterator* self);
45         GBoxedCopyFunc (*get_k_dup_func) (GeeMapIterator* self);
46         GDestroyNotify (*get_k_destroy_func) (GeeMapIterator* self);
47         GType (*get_v_type) (GeeMapIterator* self);
48         GBoxedCopyFunc (*get_v_dup_func) (GeeMapIterator* self);
49         GDestroyNotify (*get_v_destroy_func) (GeeMapIterator* self);
50         gboolean (*next) (GeeMapIterator* self);
51         gboolean (*has_next) (GeeMapIterator* self);
52         gpointer (*get_key) (GeeMapIterator* self);
53         gpointer (*get_value) (GeeMapIterator* self);
54         void (*set_value) (GeeMapIterator* self, gconstpointer value);
55         void (*unset) (GeeMapIterator* self);
56         gpointer (*fold) (GeeMapIterator* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldMapFunc f, void* f_target, gpointer seed);
57         gboolean (*foreach) (GeeMapIterator* self, GeeForallMapFunc f, void* f_target);
58         gboolean (*get_valid) (GeeMapIterator* self);
59         gboolean (*get_mutable) (GeeMapIterator* self);
60         gboolean (*get_read_only) (GeeMapIterator* self);
61 };
62
63
64
65 GType gee_map_iterator_get_type (void) G_GNUC_CONST;
66 gboolean gee_map_iterator_next (GeeMapIterator* self);
67 gboolean gee_map_iterator_has_next (GeeMapIterator* self);
68 gpointer gee_map_iterator_get_key (GeeMapIterator* self);
69 gpointer gee_map_iterator_get_value (GeeMapIterator* self);
70 void gee_map_iterator_set_value (GeeMapIterator* self, gconstpointer value);
71 void gee_map_iterator_unset (GeeMapIterator* self);
72 gpointer gee_map_iterator_fold (GeeMapIterator* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldMapFunc f, void* f_target, gpointer seed);
73 static gpointer gee_map_iterator_real_fold (GeeMapIterator* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldMapFunc f, void* f_target, gpointer seed);
74 gboolean gee_map_iterator_get_valid (GeeMapIterator* self);
75 gboolean gee_map_iterator_foreach (GeeMapIterator* self, GeeForallMapFunc f, void* f_target);
76 static gboolean gee_map_iterator_real_foreach (GeeMapIterator* self, GeeForallMapFunc f, void* f_target);
77 gboolean gee_map_iterator_get_mutable (GeeMapIterator* self);
78 gboolean gee_map_iterator_get_read_only (GeeMapIterator* self);
79
80
81 /**
82  * Advances to the next entry in the iteration.
83  *
84  * @return ``true`` if the iterator has a next entry
85  */
86 gboolean gee_map_iterator_next (GeeMapIterator* self) {
87         g_return_val_if_fail (self != NULL, FALSE);
88         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->next (self);
89 }
90
91
92 /**
93  * Checks whether there is a next entry in the iteration.
94  *
95  * @return ``true`` if the iterator has a next entry
96  */
97 gboolean gee_map_iterator_has_next (GeeMapIterator* self) {
98         g_return_val_if_fail (self != NULL, FALSE);
99         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->has_next (self);
100 }
101
102
103 /**
104  * Returns the current key in the iteration.
105  *
106  * @return the current key in the iteration
107  */
108 gpointer gee_map_iterator_get_key (GeeMapIterator* self) {
109         g_return_val_if_fail (self != NULL, NULL);
110         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_key (self);
111 }
112
113
114 /**
115  * Returns the value associated with the current key in the iteration.
116  *
117  * @return the value for the current key
118  */
119 gpointer gee_map_iterator_get_value (GeeMapIterator* self) {
120         g_return_val_if_fail (self != NULL, NULL);
121         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_value (self);
122 }
123
124
125 /**
126  * Sets the value associated with the current key in the iteration.
127  *
128  * @param value the new value for the current key
129  */
130 void gee_map_iterator_set_value (GeeMapIterator* self, gconstpointer value) {
131         g_return_if_fail (self != NULL);
132         GEE_MAP_ITERATOR_GET_INTERFACE (self)->set_value (self, value);
133 }
134
135
136 /**
137  * Unsets the current entry in the iteration. The cursor is set in an
138  * in-between state. {@link get_key}, {@link get_value}, {@link set_value}
139  * and {@link unset} will fail until the next move of the cursor (calling
140  * {@link next}).
141  */
142 void gee_map_iterator_unset (GeeMapIterator* self) {
143         g_return_if_fail (self != NULL);
144         GEE_MAP_ITERATOR_GET_INTERFACE (self)->unset (self);
145 }
146
147
148 /**
149  * Standard aggragation function.
150  *
151  * It takes a function, seed and first element, returns the new seed and
152  * progress to next element when the operation repeats.
153  *
154  * Operation moves the iterator to last element in iteration. If iterator
155  * points at some element it will be included in iteration.
156  */
157 static gpointer gee_map_iterator_real_fold (GeeMapIterator* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldMapFunc f, void* f_target, gpointer seed) {
158         gpointer result = NULL;
159         gboolean _tmp0_;
160         gboolean _tmp1_;
161         gpointer _tmp17_;
162         _tmp0_ = gee_map_iterator_get_valid (self);
163         _tmp1_ = _tmp0_;
164         if (_tmp1_) {
165                 GeeFoldMapFunc _tmp2_;
166                 void* _tmp2__target;
167                 gpointer _tmp3_ = NULL;
168                 gpointer _tmp4_;
169                 gpointer _tmp5_ = NULL;
170                 gpointer _tmp6_;
171                 gpointer _tmp7_;
172                 gpointer _tmp8_ = NULL;
173                 _tmp2_ = f;
174                 _tmp2__target = f_target;
175                 _tmp3_ = gee_map_iterator_get_key (self);
176                 _tmp4_ = _tmp3_;
177                 _tmp5_ = gee_map_iterator_get_value (self);
178                 _tmp6_ = _tmp5_;
179                 _tmp7_ = seed;
180                 seed = NULL;
181                 _tmp8_ = _tmp2_ (_tmp4_, _tmp6_, _tmp7_, _tmp2__target);
182                 _a_destroy_func0 (seed);
183                 seed = _tmp8_;
184                 ((_tmp6_ == NULL) || (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_v_destroy_func (self) == NULL)) ? NULL : (_tmp6_ = (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_v_destroy_func (self) (_tmp6_), NULL));
185                 ((_tmp4_ == NULL) || (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_k_destroy_func (self) == NULL)) ? NULL : (_tmp4_ = (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_k_destroy_func (self) (_tmp4_), NULL));
186         }
187         while (TRUE) {
188                 gboolean _tmp9_ = FALSE;
189                 GeeFoldMapFunc _tmp10_;
190                 void* _tmp10__target;
191                 gpointer _tmp11_ = NULL;
192                 gpointer _tmp12_;
193                 gpointer _tmp13_ = NULL;
194                 gpointer _tmp14_;
195                 gpointer _tmp15_;
196                 gpointer _tmp16_ = NULL;
197                 _tmp9_ = gee_map_iterator_next (self);
198                 if (!_tmp9_) {
199                         break;
200                 }
201                 _tmp10_ = f;
202                 _tmp10__target = f_target;
203                 _tmp11_ = gee_map_iterator_get_key (self);
204                 _tmp12_ = _tmp11_;
205                 _tmp13_ = gee_map_iterator_get_value (self);
206                 _tmp14_ = _tmp13_;
207                 _tmp15_ = seed;
208                 seed = NULL;
209                 _tmp16_ = _tmp10_ (_tmp12_, _tmp14_, _tmp15_, _tmp10__target);
210                 _a_destroy_func0 (seed);
211                 seed = _tmp16_;
212                 ((_tmp14_ == NULL) || (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_v_destroy_func (self) == NULL)) ? NULL : (_tmp14_ = (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_v_destroy_func (self) (_tmp14_), NULL));
213                 ((_tmp12_ == NULL) || (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_k_destroy_func (self) == NULL)) ? NULL : (_tmp12_ = (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_k_destroy_func (self) (_tmp12_), NULL));
214         }
215         _tmp17_ = seed;
216         seed = NULL;
217         result = _tmp17_;
218         _a_destroy_func0 (seed);
219         return result;
220 }
221
222
223 gpointer gee_map_iterator_fold (GeeMapIterator* self, GType a_type, GBoxedCopyFunc a_dup_func, GDestroyNotify a_destroy_func, GeeFoldMapFunc f, void* f_target, gpointer seed) {
224         g_return_val_if_fail (self != NULL, NULL);
225         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->fold (self, a_type, a_dup_func, a_destroy_func, f, f_target, seed);
226 }
227
228
229 /**
230  * Apply function to each element returned by iterator. 
231  *
232  * Operation moves the iterator to last element in iteration. If iterator
233  * points at some element it will be included in iteration.
234  */
235 static gboolean gee_map_iterator_real_foreach (GeeMapIterator* self, GeeForallMapFunc f, void* f_target) {
236         gboolean result = FALSE;
237         gboolean _tmp0_;
238         gboolean _tmp1_;
239         _tmp0_ = gee_map_iterator_get_valid (self);
240         _tmp1_ = _tmp0_;
241         if (_tmp1_) {
242                 GeeForallMapFunc _tmp2_;
243                 void* _tmp2__target;
244                 gpointer _tmp3_ = NULL;
245                 gpointer _tmp4_;
246                 gpointer _tmp5_ = NULL;
247                 gpointer _tmp6_;
248                 gboolean _tmp7_ = FALSE;
249                 gboolean _tmp8_;
250                 _tmp2_ = f;
251                 _tmp2__target = f_target;
252                 _tmp3_ = gee_map_iterator_get_key (self);
253                 _tmp4_ = _tmp3_;
254                 _tmp5_ = gee_map_iterator_get_value (self);
255                 _tmp6_ = _tmp5_;
256                 _tmp7_ = _tmp2_ (_tmp4_, _tmp6_, _tmp2__target);
257                 _tmp8_ = !_tmp7_;
258                 ((_tmp6_ == NULL) || (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_v_destroy_func (self) == NULL)) ? NULL : (_tmp6_ = (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_v_destroy_func (self) (_tmp6_), NULL));
259                 ((_tmp4_ == NULL) || (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_k_destroy_func (self) == NULL)) ? NULL : (_tmp4_ = (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_k_destroy_func (self) (_tmp4_), NULL));
260                 if (_tmp8_) {
261                         result = FALSE;
262                         return result;
263                 }
264         }
265         while (TRUE) {
266                 gboolean _tmp9_ = FALSE;
267                 GeeForallMapFunc _tmp10_;
268                 void* _tmp10__target;
269                 gpointer _tmp11_ = NULL;
270                 gpointer _tmp12_;
271                 gpointer _tmp13_ = NULL;
272                 gpointer _tmp14_;
273                 gboolean _tmp15_ = FALSE;
274                 gboolean _tmp16_;
275                 _tmp9_ = gee_map_iterator_next (self);
276                 if (!_tmp9_) {
277                         break;
278                 }
279                 _tmp10_ = f;
280                 _tmp10__target = f_target;
281                 _tmp11_ = gee_map_iterator_get_key (self);
282                 _tmp12_ = _tmp11_;
283                 _tmp13_ = gee_map_iterator_get_value (self);
284                 _tmp14_ = _tmp13_;
285                 _tmp15_ = _tmp10_ (_tmp12_, _tmp14_, _tmp10__target);
286                 _tmp16_ = !_tmp15_;
287                 ((_tmp14_ == NULL) || (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_v_destroy_func (self) == NULL)) ? NULL : (_tmp14_ = (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_v_destroy_func (self) (_tmp14_), NULL));
288                 ((_tmp12_ == NULL) || (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_k_destroy_func (self) == NULL)) ? NULL : (_tmp12_ = (GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_k_destroy_func (self) (_tmp12_), NULL));
289                 if (_tmp16_) {
290                         result = FALSE;
291                         return result;
292                 }
293         }
294         result = TRUE;
295         return result;
296 }
297
298
299 gboolean gee_map_iterator_foreach (GeeMapIterator* self, GeeForallMapFunc f, void* f_target) {
300         g_return_val_if_fail (self != NULL, FALSE);
301         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->foreach (self, f, f_target);
302 }
303
304
305 gboolean gee_map_iterator_get_valid (GeeMapIterator* self) {
306         g_return_val_if_fail (self != NULL, FALSE);
307         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_valid (self);
308 }
309
310
311 gboolean gee_map_iterator_get_mutable (GeeMapIterator* self) {
312         g_return_val_if_fail (self != NULL, FALSE);
313         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_mutable (self);
314 }
315
316
317 gboolean gee_map_iterator_get_read_only (GeeMapIterator* self) {
318         g_return_val_if_fail (self != NULL, FALSE);
319         return GEE_MAP_ITERATOR_GET_INTERFACE (self)->get_read_only (self);
320 }
321
322
323 static void gee_map_iterator_base_init (GeeMapIteratorIface * iface) {
324         static gboolean initialized = FALSE;
325         if (!initialized) {
326                 initialized = TRUE;
327                 /**
328                  * Determines wheather the call to {@link get_key}, {@link get_value} and 
329                  * {@link set_value} is legal. It is false at the beginning and after
330                  * {@link unset} call and true otherwise.
331                  */
332                 g_object_interface_install_property (iface, g_param_spec_boolean ("valid", "valid", "valid", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
333                 /**
334                  * Determines wheather the call to {@link set_value} is legal assuming the
335                  * iterator is valid. The value must not change in runtime hence the user
336                  * of iterator may cache it.
337                  */
338                 g_object_interface_install_property (iface, g_param_spec_boolean ("mutable", "mutable", "mutable", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
339                 /**
340                  * Determines wheather the call to {@link unset} is legal assuming the
341                  * iterator is valid. The value must not change in runtime hence the user
342                  * of iterator may cache it.
343                  */
344                 g_object_interface_install_property (iface, g_param_spec_boolean ("read-only", "read-only", "read-only", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
345                 iface->fold = gee_map_iterator_real_fold;
346                 iface->foreach = gee_map_iterator_real_foreach;
347         }
348 }
349
350
351 /**
352  * An iterator over a map.
353  *
354  * Gee's iterators are "on-track" iterators. They always point to an item
355  * except before the first call to {@link next}, or, when an
356  * item has been removed, until the next call to {@link next}.
357  *
358  * Please note that when the iterator is out of track, neither {@link get_key},
359  * {@link get_value}, {@link set_value} nor {@link unset} are defined and all
360  * will fail. After the next call to {@link next}, they will
361  * be defined again.
362  */
363 GType gee_map_iterator_get_type (void) {
364         static volatile gsize gee_map_iterator_type_id__volatile = 0;
365         if (g_once_init_enter (&gee_map_iterator_type_id__volatile)) {
366                 static const GTypeInfo g_define_type_info = { sizeof (GeeMapIteratorIface), (GBaseInitFunc) gee_map_iterator_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
367                 GType gee_map_iterator_type_id;
368                 gee_map_iterator_type_id = g_type_register_static (G_TYPE_INTERFACE, "GeeMapIterator", &g_define_type_info, 0);
369                 g_type_interface_add_prerequisite (gee_map_iterator_type_id, G_TYPE_OBJECT);
370                 g_once_init_leave (&gee_map_iterator_type_id__volatile, gee_map_iterator_type_id);
371         }
372         return gee_map_iterator_type_id__volatile;
373 }
374
375
376