1 /* mapiterator.c generated by valac 0.18.0, the Vala compiler
2 * generated from mapiterator.vala, do not modify */
6 * Copyright (C) 2009 Didier Villevalois
7 * Copyright (C) 2011 Maciej Piechotka
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.
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.
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
24 * Didier 'Ptitjes Villevalois <ptitjes@free.fr>
28 #include <glib-object.h>
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))
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)))
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);
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);
82 * Advances to the next entry in the iteration.
84 * @return ``true`` if the iterator has a next entry
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);
93 * Checks whether there is a next entry in the iteration.
95 * @return ``true`` if the iterator has a next entry
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);
104 * Returns the current key in the iteration.
106 * @return the current key in the iteration
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);
115 * Returns the value associated with the current key in the iteration.
117 * @return the value for the current key
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);
126 * Sets the value associated with the current key in the iteration.
128 * @param value the new value for the current key
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);
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
142 void gee_map_iterator_unset (GeeMapIterator* self) {
143 g_return_if_fail (self != NULL);
144 GEE_MAP_ITERATOR_GET_INTERFACE (self)->unset (self);
149 * Standard aggragation function.
151 * It takes a function, seed and first element, returns the new seed and
152 * progress to next element when the operation repeats.
154 * Operation moves the iterator to last element in iteration. If iterator
155 * points at some element it will be included in iteration.
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;
162 _tmp0_ = gee_map_iterator_get_valid (self);
165 GeeFoldMapFunc _tmp2_;
167 gpointer _tmp3_ = NULL;
169 gpointer _tmp5_ = NULL;
172 gpointer _tmp8_ = NULL;
174 _tmp2__target = f_target;
175 _tmp3_ = gee_map_iterator_get_key (self);
177 _tmp5_ = gee_map_iterator_get_value (self);
181 _tmp8_ = _tmp2_ (_tmp4_, _tmp6_, _tmp7_, _tmp2__target);
182 _a_destroy_func0 (seed);
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));
188 gboolean _tmp9_ = FALSE;
189 GeeFoldMapFunc _tmp10_;
190 void* _tmp10__target;
191 gpointer _tmp11_ = NULL;
193 gpointer _tmp13_ = NULL;
196 gpointer _tmp16_ = NULL;
197 _tmp9_ = gee_map_iterator_next (self);
202 _tmp10__target = f_target;
203 _tmp11_ = gee_map_iterator_get_key (self);
205 _tmp13_ = gee_map_iterator_get_value (self);
209 _tmp16_ = _tmp10_ (_tmp12_, _tmp14_, _tmp15_, _tmp10__target);
210 _a_destroy_func0 (seed);
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));
218 _a_destroy_func0 (seed);
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);
230 * Apply function to each element returned by iterator.
232 * Operation moves the iterator to last element in iteration. If iterator
233 * points at some element it will be included in iteration.
235 static gboolean gee_map_iterator_real_foreach (GeeMapIterator* self, GeeForallMapFunc f, void* f_target) {
236 gboolean result = FALSE;
239 _tmp0_ = gee_map_iterator_get_valid (self);
242 GeeForallMapFunc _tmp2_;
244 gpointer _tmp3_ = NULL;
246 gpointer _tmp5_ = NULL;
248 gboolean _tmp7_ = FALSE;
251 _tmp2__target = f_target;
252 _tmp3_ = gee_map_iterator_get_key (self);
254 _tmp5_ = gee_map_iterator_get_value (self);
256 _tmp7_ = _tmp2_ (_tmp4_, _tmp6_, _tmp2__target);
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));
266 gboolean _tmp9_ = FALSE;
267 GeeForallMapFunc _tmp10_;
268 void* _tmp10__target;
269 gpointer _tmp11_ = NULL;
271 gpointer _tmp13_ = NULL;
273 gboolean _tmp15_ = FALSE;
275 _tmp9_ = gee_map_iterator_next (self);
280 _tmp10__target = f_target;
281 _tmp11_ = gee_map_iterator_get_key (self);
283 _tmp13_ = gee_map_iterator_get_value (self);
285 _tmp15_ = _tmp10_ (_tmp12_, _tmp14_, _tmp10__target);
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));
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);
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);
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);
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);
323 static void gee_map_iterator_base_init (GeeMapIteratorIface * iface) {
324 static gboolean initialized = FALSE;
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.
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));
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.
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));
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.
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;
352 * An iterator over a map.
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}.
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
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);
372 return gee_map_iterator_type_id__volatile;