File: readonlymap.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 (285 lines) | stat: -rw-r--r-- 11,600 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
/* readonlymap.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/readonlymap.h>
#include <gee/readonlyset.h>
#include <gee/readonlycollection.h>




struct _GeeReadOnlyMapPrivate {
	GeeMap* _map;
	GType k_type;
	GBoxedCopyFunc k_dup_func;
	GDestroyNotify k_destroy_func;
	GType v_type;
	GBoxedCopyFunc v_dup_func;
	GDestroyNotify v_destroy_func;
};

#define GEE_READ_ONLY_MAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GEE_TYPE_READ_ONLY_MAP, GeeReadOnlyMapPrivate))
enum  {
	GEE_READ_ONLY_MAP_DUMMY_PROPERTY,
	GEE_READ_ONLY_MAP_SIZE,
	GEE_READ_ONLY_MAP_MAP,
	GEE_READ_ONLY_MAP_K_TYPE,
	GEE_READ_ONLY_MAP_K_DUP_FUNC,
	GEE_READ_ONLY_MAP_K_DESTROY_FUNC,
	GEE_READ_ONLY_MAP_V_TYPE,
	GEE_READ_ONLY_MAP_V_DUP_FUNC,
	GEE_READ_ONLY_MAP_V_DESTROY_FUNC
};
static GeeSet* gee_read_only_map_real_get_keys (GeeMap* base);
static GeeCollection* gee_read_only_map_real_get_values (GeeMap* base);
static gboolean gee_read_only_map_real_contains (GeeMap* base, gconstpointer key);
static gpointer gee_read_only_map_real_get (GeeMap* base, gconstpointer key);
static void gee_read_only_map_real_set (GeeMap* base, gconstpointer key, gconstpointer value);
static gboolean gee_read_only_map_real_remove (GeeMap* base, gconstpointer key);
static void gee_read_only_map_real_clear (GeeMap* base);
static gpointer gee_read_only_map_parent_class = NULL;
static GeeMapIface* gee_read_only_map_gee_map_parent_iface = NULL;
static void gee_read_only_map_dispose (GObject * obj);



GeeReadOnlyMap* gee_read_only_map_new (GType k_type, GBoxedCopyFunc k_dup_func, GDestroyNotify k_destroy_func, GType v_type, GBoxedCopyFunc v_dup_func, GDestroyNotify v_destroy_func, GeeMap* map) {
	GParameter * __params;
	GParameter * __params_it;
	GeeReadOnlyMap * self;
	g_return_val_if_fail (map == NULL || GEE_IS_MAP (map), NULL);
	__params = g_new0 (GParameter, 6);
	__params_it = __params;
	__params_it->name = "k-type";
	g_value_init (&__params_it->value, G_TYPE_GTYPE);
	g_value_set_gtype (&__params_it->value, k_type);
	__params_it++;
	__params_it->name = "k-dup-func";
	g_value_init (&__params_it->value, G_TYPE_POINTER);
	g_value_set_pointer (&__params_it->value, k_dup_func);
	__params_it++;
	__params_it->name = "k-destroy-func";
	g_value_init (&__params_it->value, G_TYPE_POINTER);
	g_value_set_pointer (&__params_it->value, k_destroy_func);
	__params_it++;
	__params_it->name = "v-type";
	g_value_init (&__params_it->value, G_TYPE_GTYPE);
	g_value_set_gtype (&__params_it->value, v_type);
	__params_it++;
	__params_it->name = "v-dup-func";
	g_value_init (&__params_it->value, G_TYPE_POINTER);
	g_value_set_pointer (&__params_it->value, v_dup_func);
	__params_it++;
	__params_it->name = "v-destroy-func";
	g_value_init (&__params_it->value, G_TYPE_POINTER);
	g_value_set_pointer (&__params_it->value, v_destroy_func);
	__params_it++;
	self = g_object_newv (GEE_TYPE_READ_ONLY_MAP, __params_it - __params, __params);
	gee_read_only_map_set_map (self, map);
	while (__params_it > __params) {
		--__params_it;
		g_value_unset (&__params_it->value);
	}
	g_free (__params);
	return self;
}


static GeeSet* gee_read_only_map_real_get_keys (GeeMap* base) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (base);
	if (self->priv->_map == NULL) {
		return GEE_SET (gee_read_only_set_new (self->priv->k_type, ((GBoxedCopyFunc) (self->priv->k_dup_func)), self->priv->k_destroy_func, NULL));
	}
	return gee_map_get_keys (self->priv->_map);
}


static GeeCollection* gee_read_only_map_real_get_values (GeeMap* base) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (base);
	if (self->priv->_map == NULL) {
		return GEE_COLLECTION (gee_read_only_collection_new (self->priv->v_type, ((GBoxedCopyFunc) (self->priv->v_dup_func)), self->priv->v_destroy_func, NULL));
	}
	return gee_map_get_values (self->priv->_map);
}


static gboolean gee_read_only_map_real_contains (GeeMap* base, gconstpointer key) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (base);
	if (self->priv->_map == NULL) {
		return FALSE;
	}
	return gee_map_contains (self->priv->_map, key);
}


static gpointer gee_read_only_map_real_get (GeeMap* base, gconstpointer key) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (base);
	if (self->priv->_map == NULL) {
		return NULL;
	}
	return gee_map_get (self->priv->_map, key);
}


static void gee_read_only_map_real_set (GeeMap* base, gconstpointer key, gconstpointer value) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (base);
	g_assert_not_reached ();
}


static gboolean gee_read_only_map_real_remove (GeeMap* base, gconstpointer key) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (base);
	g_assert_not_reached ();
}


static void gee_read_only_map_real_clear (GeeMap* base) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (base);
	g_assert_not_reached ();
}


static gint gee_read_only_map_real_get_size (GeeReadOnlyMap* self) {
	g_return_val_if_fail (GEE_IS_READ_ONLY_MAP (self), 0);
	return gee_map_get_size (self->priv->_map);
}


void gee_read_only_map_set_map (GeeReadOnlyMap* self, GeeMap* value) {
	GeeMap* _tmp1;
	GeeMap* _tmp0;
	g_return_if_fail (GEE_IS_READ_ONLY_MAP (self));
	_tmp1 = NULL;
	_tmp0 = NULL;
	self->priv->_map = (_tmp1 = (_tmp0 = value, (_tmp0 == NULL ? NULL : g_object_ref (_tmp0))), (self->priv->_map == NULL ? NULL : (self->priv->_map = (g_object_unref (self->priv->_map), NULL))), _tmp1);
}


static void gee_read_only_map_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (object);
	switch (property_id) {
		case GEE_READ_ONLY_MAP_SIZE:
		g_value_set_int (value, gee_read_only_map_real_get_size (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void gee_read_only_map_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (object);
	switch (property_id) {
		case GEE_READ_ONLY_MAP_MAP:
		gee_read_only_map_set_map (self, g_value_get_object (value));
		break;
		case GEE_READ_ONLY_MAP_K_TYPE:
		self->priv->k_type = g_value_get_gtype (value);
		break;
		case GEE_READ_ONLY_MAP_K_DUP_FUNC:
		self->priv->k_dup_func = g_value_get_pointer (value);
		break;
		case GEE_READ_ONLY_MAP_K_DESTROY_FUNC:
		self->priv->k_destroy_func = g_value_get_pointer (value);
		break;
		case GEE_READ_ONLY_MAP_V_TYPE:
		self->priv->v_type = g_value_get_gtype (value);
		break;
		case GEE_READ_ONLY_MAP_V_DUP_FUNC:
		self->priv->v_dup_func = g_value_get_pointer (value);
		break;
		case GEE_READ_ONLY_MAP_V_DESTROY_FUNC:
		self->priv->v_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_map_class_init (GeeReadOnlyMapClass * klass) {
	gee_read_only_map_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GeeReadOnlyMapPrivate));
	G_OBJECT_CLASS (klass)->get_property = gee_read_only_map_get_property;
	G_OBJECT_CLASS (klass)->set_property = gee_read_only_map_set_property;
	G_OBJECT_CLASS (klass)->dispose = gee_read_only_map_dispose;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_MAP_K_TYPE, g_param_spec_gtype ("k-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_MAP_K_DUP_FUNC, g_param_spec_pointer ("k-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_MAP_K_DESTROY_FUNC, g_param_spec_pointer ("k-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_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_MAP_V_TYPE, g_param_spec_gtype ("v-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_MAP_V_DUP_FUNC, g_param_spec_pointer ("v-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_MAP_V_DESTROY_FUNC, g_param_spec_pointer ("v-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_MAP_SIZE, "size");
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEE_READ_ONLY_MAP_MAP, g_param_spec_object ("map", "map", "map", GEE_TYPE_MAP, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
}


static void gee_read_only_map_gee_map_interface_init (GeeMapIface * iface) {
	gee_read_only_map_gee_map_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_keys = gee_read_only_map_real_get_keys;
	iface->get_values = gee_read_only_map_real_get_values;
	iface->contains = gee_read_only_map_real_contains;
	iface->get = gee_read_only_map_real_get;
	iface->set = gee_read_only_map_real_set;
	iface->remove = gee_read_only_map_real_remove;
	iface->clear = gee_read_only_map_real_clear;
}


static void gee_read_only_map_instance_init (GeeReadOnlyMap * self) {
	self->priv = GEE_READ_ONLY_MAP_GET_PRIVATE (self);
}


static void gee_read_only_map_dispose (GObject * obj) {
	GeeReadOnlyMap * self;
	self = GEE_READ_ONLY_MAP (obj);
	(self->priv->_map == NULL ? NULL : (self->priv->_map = (g_object_unref (self->priv->_map), NULL)));
	G_OBJECT_CLASS (gee_read_only_map_parent_class)->dispose (obj);
}


GType gee_read_only_map_get_type (void) {
	static GType gee_read_only_map_type_id = 0;
	if (G_UNLIKELY (gee_read_only_map_type_id == 0)) {
		static const GTypeInfo g_define_type_info = { sizeof (GeeReadOnlyMapClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gee_read_only_map_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GeeReadOnlyMap), 0, (GInstanceInitFunc) gee_read_only_map_instance_init };
		static const GInterfaceInfo gee_map_info = { (GInterfaceInitFunc) gee_read_only_map_gee_map_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		gee_read_only_map_type_id = g_type_register_static (G_TYPE_OBJECT, "GeeReadOnlyMap", &g_define_type_info, 0);
		g_type_add_interface_static (gee_read_only_map_type_id, GEE_TYPE_MAP, &gee_map_info);
	}
	return gee_read_only_map_type_id;
}