File: readonlyset.c

package info (click to toggle)
vala 0.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,756 kB
  • ctags: 12,353
  • sloc: ansic: 116,516; sh: 9,897; yacc: 1,218; makefile: 837; xml: 657; lex: 285
file content (401 lines) | stat: -rw-r--r-- 17,317 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/* readonlyset.vala
 *
 * Copyright (C) 2007-2008  Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 */

#include <gee/readonlyset.h>


#define GEE_READ_ONLY_SET_TYPE_ITERATOR (gee_read_only_set_iterator_get_type ())
#define GEE_READ_ONLY_SET_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_READ_ONLY_SET_TYPE_ITERATOR, GeeReadOnlySetIterator))
#define GEE_READ_ONLY_SET_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_READ_ONLY_SET_TYPE_ITERATOR, GeeReadOnlySetIteratorClass))
#define GEE_READ_ONLY_SET_IS_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_READ_ONLY_SET_TYPE_ITERATOR))
#define GEE_READ_ONLY_SET_IS_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_READ_ONLY_SET_TYPE_ITERATOR))
#define GEE_READ_ONLY_SET_ITERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_READ_ONLY_SET_TYPE_ITERATOR, GeeReadOnlySetIteratorClass))

typedef struct _GeeReadOnlySetIterator GeeReadOnlySetIterator;
typedef struct _GeeReadOnlySetIteratorClass GeeReadOnlySetIteratorClass;
typedef struct _GeeReadOnlySetIteratorPrivate GeeReadOnlySetIteratorPrivate;

struct _GeeReadOnlySetIterator {
	GObject parent_instance;
	GeeReadOnlySetIteratorPrivate * priv;
};

struct _GeeReadOnlySetIteratorClass {
	GObjectClass parent_class;
};



struct _GeeReadOnlySetPrivate {
	GeeSet* _set;
	GType g_type;
	GBoxedCopyFunc g_dup_func;
	GDestroyNotify g_destroy_func;
};

#define GEE_READ_ONLY_SET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GEE_TYPE_READ_ONLY_SET, GeeReadOnlySetPrivate))
enum  {
	GEE_READ_ONLY_SET_DUMMY_PROPERTY,
	GEE_READ_ONLY_SET_SIZE,
	GEE_READ_ONLY_SET_SET,
	GEE_READ_ONLY_SET_G_TYPE,
	GEE_READ_ONLY_SET_G_DUP_FUNC,
	GEE_READ_ONLY_SET_G_DESTROY_FUNC
};
static GType gee_read_only_set_real_get_element_type (GeeIterable* base);
static GeeIterator* gee_read_only_set_real_iterator (GeeIterable* base);
static gboolean gee_read_only_set_real_contains (GeeCollection* base, gconstpointer item);
static gboolean gee_read_only_set_real_add (GeeCollection* base, gconstpointer item);
static gboolean gee_read_only_set_real_remove (GeeCollection* base, gconstpointer item);
static void gee_read_only_set_real_clear (GeeCollection* base);
struct _GeeReadOnlySetIteratorPrivate {
	GType g_type;
	GBoxedCopyFunc g_dup_func;
	GDestroyNotify g_destroy_func;
};

#define GEE_READ_ONLY_SET_ITERATOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GEE_READ_ONLY_SET_TYPE_ITERATOR, GeeReadOnlySetIteratorPrivate))
enum  {
	GEE_READ_ONLY_SET_ITERATOR_DUMMY_PROPERTY,
	GEE_READ_ONLY_SET_ITERATOR_G_TYPE,
	GEE_READ_ONLY_SET_ITERATOR_G_DUP_FUNC,
	GEE_READ_ONLY_SET_ITERATOR_G_DESTROY_FUNC
};
static gboolean gee_read_only_set_iterator_real_next (GeeIterator* base);
static gpointer gee_read_only_set_iterator_real_get (GeeIterator* base);
static GeeReadOnlySetIterator* gee_read_only_set_iterator_new (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func);
static gpointer gee_read_only_set_iterator_parent_class = NULL;
static GeeIteratorIface* gee_read_only_set_iterator_gee_iterator_parent_iface = NULL;
static GType gee_read_only_set_iterator_get_type (void);
static gpointer gee_read_only_set_parent_class = NULL;
static GeeIterableIface* gee_read_only_set_gee_iterable_parent_iface = NULL;
static GeeCollectionIface* gee_read_only_set_gee_collection_parent_iface = NULL;
static GeeSetIface* gee_read_only_set_gee_set_parent_iface = NULL;
static void gee_read_only_set_dispose (GObject * obj);



GeeReadOnlySet* gee_read_only_set_new (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func, GeeSet* set) {
	GParameter * __params;
	GParameter * __params_it;
	GeeReadOnlySet * self;
	g_return_val_if_fail (set == NULL || GEE_IS_SET (set), NULL);
	__params = g_new0 (GParameter, 3);
	__params_it = __params;
	__params_it->name = "g-type";
	g_value_init (&__params_it->value, G_TYPE_GTYPE);
	g_value_set_gtype (&__params_it->value, g_type);
	__params_it++;
	__params_it->name = "g-dup-func";
	g_value_init (&__params_it->value, G_TYPE_POINTER);
	g_value_set_pointer (&__params_it->value, g_dup_func);
	__params_it++;
	__params_it->name = "g-destroy-func";
	g_value_init (&__params_it->value, G_TYPE_POINTER);
	g_value_set_pointer (&__params_it->value, g_destroy_func);
	__params_it++;
	self = g_object_newv (GEE_TYPE_READ_ONLY_SET, __params_it - __params, __params);
	gee_read_only_set_set_set (self, set);
	while (__params_it > __params) {
		--__params_it;
		g_value_unset (&__params_it->value);
	}
	g_free (__params);
	return self;
}


static GType gee_read_only_set_real_get_element_type (GeeIterable* base) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (base);
	return self->priv->g_type;
}


static GeeIterator* gee_read_only_set_real_iterator (GeeIterable* base) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (base);
	if (self->priv->_set == NULL) {
		return GEE_ITERATOR (gee_read_only_set_iterator_new (self->priv->g_type, ((GBoxedCopyFunc) (self->priv->g_dup_func)), self->priv->g_destroy_func));
	}
	return gee_iterable_iterator (GEE_ITERABLE (self->priv->_set));
}


static gboolean gee_read_only_set_real_contains (GeeCollection* base, gconstpointer item) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (base);
	if (self->priv->_set == NULL) {
		return FALSE;
	}
	return gee_collection_contains (GEE_COLLECTION (self->priv->_set), item);
}


static gboolean gee_read_only_set_real_add (GeeCollection* base, gconstpointer item) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (base);
	g_assert_not_reached ();
}


static gboolean gee_read_only_set_real_remove (GeeCollection* base, gconstpointer item) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (base);
	g_assert_not_reached ();
}


static void gee_read_only_set_real_clear (GeeCollection* base) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (base);
	g_assert_not_reached ();
}


static gint gee_read_only_set_real_get_size (GeeReadOnlySet* self) {
	g_return_val_if_fail (GEE_IS_READ_ONLY_SET (self), 0);
	return gee_collection_get_size (GEE_COLLECTION (self->priv->_set));
}


void gee_read_only_set_set_set (GeeReadOnlySet* self, GeeSet* value) {
	GeeSet* _tmp1;
	GeeSet* _tmp0;
	g_return_if_fail (GEE_IS_READ_ONLY_SET (self));
	_tmp1 = NULL;
	_tmp0 = NULL;
	self->priv->_set = (_tmp1 = (_tmp0 = value, (_tmp0 == NULL ? NULL : g_object_ref (_tmp0))), (self->priv->_set == NULL ? NULL : (self->priv->_set = (g_object_unref (self->priv->_set), NULL))), _tmp1);
}


static gboolean gee_read_only_set_iterator_real_next (GeeIterator* base) {
	GeeReadOnlySetIterator * self;
	self = GEE_READ_ONLY_SET_ITERATOR (base);
	return FALSE;
}


static gpointer gee_read_only_set_iterator_real_get (GeeIterator* base) {
	GeeReadOnlySetIterator * self;
	self = GEE_READ_ONLY_SET_ITERATOR (base);
	return NULL;
}


static GeeReadOnlySetIterator* gee_read_only_set_iterator_new (GType g_type, GBoxedCopyFunc g_dup_func, GDestroyNotify g_destroy_func) {
	GParameter * __params;
	GParameter * __params_it;
	GeeReadOnlySetIterator * self;
	__params = g_new0 (GParameter, 3);
	__params_it = __params;
	__params_it->name = "g-type";
	g_value_init (&__params_it->value, G_TYPE_GTYPE);
	g_value_set_gtype (&__params_it->value, g_type);
	__params_it++;
	__params_it->name = "g-dup-func";
	g_value_init (&__params_it->value, G_TYPE_POINTER);
	g_value_set_pointer (&__params_it->value, g_dup_func);
	__params_it++;
	__params_it->name = "g-destroy-func";
	g_value_init (&__params_it->value, G_TYPE_POINTER);
	g_value_set_pointer (&__params_it->value, g_destroy_func);
	__params_it++;
	self = g_object_newv (GEE_READ_ONLY_SET_TYPE_ITERATOR, __params_it - __params, __params);
	while (__params_it > __params) {
		--__params_it;
		g_value_unset (&__params_it->value);
	}
	g_free (__params);
	return self;
}


static void gee_read_only_set_iterator_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GeeReadOnlySetIterator * self;
	self = GEE_READ_ONLY_SET_ITERATOR (object);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void gee_read_only_set_iterator_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GeeReadOnlySetIterator * self;
	self = GEE_READ_ONLY_SET_ITERATOR (object);
	switch (property_id) {
		case GEE_READ_ONLY_SET_ITERATOR_G_TYPE:
		self->priv->g_type = g_value_get_gtype (value);
		break;
		case GEE_READ_ONLY_SET_ITERATOR_G_DUP_FUNC:
		self->priv->g_dup_func = g_value_get_pointer (value);
		break;
		case GEE_READ_ONLY_SET_ITERATOR_G_DESTROY_FUNC:
		self->priv->g_destroy_func = g_value_get_pointer (value);
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void gee_read_only_set_iterator_class_init (GeeReadOnlySetIteratorClass * klass) {
	gee_read_only_set_iterator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GeeReadOnlySetIteratorPrivate));
	G_OBJECT_CLASS (klass)->get_property = gee_read_only_set_iterator_get_property;
	G_OBJECT_CLASS (klass)->set_property = gee_read_only_set_iterator_set_property;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_ITERATOR_G_TYPE, g_param_spec_gtype ("g-type", "type", "type", G_TYPE_NONE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_ITERATOR_G_DUP_FUNC, g_param_spec_pointer ("g-dup-func", "dup func", "dup func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_ITERATOR_G_DESTROY_FUNC, g_param_spec_pointer ("g-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}


static void gee_read_only_set_iterator_gee_iterator_interface_init (GeeIteratorIface * iface) {
	gee_read_only_set_iterator_gee_iterator_parent_iface = g_type_interface_peek_parent (iface);
	iface->next = gee_read_only_set_iterator_real_next;
	iface->get = gee_read_only_set_iterator_real_get;
}


static void gee_read_only_set_iterator_instance_init (GeeReadOnlySetIterator * self) {
	self->priv = GEE_READ_ONLY_SET_ITERATOR_GET_PRIVATE (self);
}


static GType gee_read_only_set_iterator_get_type (void) {
	static GType gee_read_only_set_iterator_type_id = 0;
	if (G_UNLIKELY (gee_read_only_set_iterator_type_id == 0)) {
		static const GTypeInfo g_define_type_info = { sizeof (GeeReadOnlySetIteratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gee_read_only_set_iterator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GeeReadOnlySetIterator), 0, (GInstanceInitFunc) gee_read_only_set_iterator_instance_init };
		static const GInterfaceInfo gee_iterator_info = { (GInterfaceInitFunc) gee_read_only_set_iterator_gee_iterator_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		gee_read_only_set_iterator_type_id = g_type_register_static (G_TYPE_OBJECT, "GeeReadOnlySetIterator", &g_define_type_info, 0);
		g_type_add_interface_static (gee_read_only_set_iterator_type_id, GEE_TYPE_ITERATOR, &gee_iterator_info);
	}
	return gee_read_only_set_iterator_type_id;
}


static void gee_read_only_set_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (object);
	switch (property_id) {
		case GEE_READ_ONLY_SET_SIZE:
		g_value_set_int (value, gee_read_only_set_real_get_size (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void gee_read_only_set_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (object);
	switch (property_id) {
		case GEE_READ_ONLY_SET_SET:
		gee_read_only_set_set_set (self, g_value_get_object (value));
		break;
		case GEE_READ_ONLY_SET_G_TYPE:
		self->priv->g_type = g_value_get_gtype (value);
		break;
		case GEE_READ_ONLY_SET_G_DUP_FUNC:
		self->priv->g_dup_func = g_value_get_pointer (value);
		break;
		case GEE_READ_ONLY_SET_G_DESTROY_FUNC:
		self->priv->g_destroy_func = g_value_get_pointer (value);
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void gee_read_only_set_class_init (GeeReadOnlySetClass * klass) {
	gee_read_only_set_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GeeReadOnlySetPrivate));
	G_OBJECT_CLASS (klass)->get_property = gee_read_only_set_get_property;
	G_OBJECT_CLASS (klass)->set_property = gee_read_only_set_set_property;
	G_OBJECT_CLASS (klass)->dispose = gee_read_only_set_dispose;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_G_TYPE, g_param_spec_gtype ("g-type", "type", "type", G_TYPE_NONE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_G_DUP_FUNC, g_param_spec_pointer ("g-dup-func", "dup func", "dup func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_G_DESTROY_FUNC, g_param_spec_pointer ("g-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_override_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_SIZE, "size");
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_SET_SET, g_param_spec_object ("set", "set", "set", GEE_TYPE_SET, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
}


static void gee_read_only_set_gee_iterable_interface_init (GeeIterableIface * iface) {
	gee_read_only_set_gee_iterable_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_element_type = gee_read_only_set_real_get_element_type;
	iface->iterator = gee_read_only_set_real_iterator;
}


static void gee_read_only_set_gee_collection_interface_init (GeeCollectionIface * iface) {
	gee_read_only_set_gee_collection_parent_iface = g_type_interface_peek_parent (iface);
	iface->contains = gee_read_only_set_real_contains;
	iface->add = gee_read_only_set_real_add;
	iface->remove = gee_read_only_set_real_remove;
	iface->clear = gee_read_only_set_real_clear;
}


static void gee_read_only_set_gee_set_interface_init (GeeSetIface * iface) {
	gee_read_only_set_gee_set_parent_iface = g_type_interface_peek_parent (iface);
}


static void gee_read_only_set_instance_init (GeeReadOnlySet * self) {
	self->priv = GEE_READ_ONLY_SET_GET_PRIVATE (self);
}


static void gee_read_only_set_dispose (GObject * obj) {
	GeeReadOnlySet * self;
	self = GEE_READ_ONLY_SET (obj);
	(self->priv->_set == NULL ? NULL : (self->priv->_set = (g_object_unref (self->priv->_set), NULL)));
	G_OBJECT_CLASS (gee_read_only_set_parent_class)->dispose (obj);
}


GType gee_read_only_set_get_type (void) {
	static GType gee_read_only_set_type_id = 0;
	if (G_UNLIKELY (gee_read_only_set_type_id == 0)) {
		static const GTypeInfo g_define_type_info = { sizeof (GeeReadOnlySetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gee_read_only_set_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GeeReadOnlySet), 0, (GInstanceInitFunc) gee_read_only_set_instance_init };
		static const GInterfaceInfo gee_iterable_info = { (GInterfaceInitFunc) gee_read_only_set_gee_iterable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		static const GInterfaceInfo gee_collection_info = { (GInterfaceInitFunc) gee_read_only_set_gee_collection_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		static const GInterfaceInfo gee_set_info = { (GInterfaceInitFunc) gee_read_only_set_gee_set_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		gee_read_only_set_type_id = g_type_register_static (G_TYPE_OBJECT, "GeeReadOnlySet", &g_define_type_info, 0);
		g_type_add_interface_static (gee_read_only_set_type_id, GEE_TYPE_ITERABLE, &gee_iterable_info);
		g_type_add_interface_static (gee_read_only_set_type_id, GEE_TYPE_COLLECTION, &gee_collection_info);
		g_type_add_interface_static (gee_read_only_set_type_id, GEE_TYPE_SET, &gee_set_info);
	}
	return gee_read_only_set_type_id;
}