sl@0
|
1 |
/* GObject - GLib Type, Object, Parameter and Signal Library
|
sl@0
|
2 |
* Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
|
sl@0
|
3 |
* Portions copyright (c) 2006-2009 Nokia Corporation. All rights reserved.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* This library is free software; you can redistribute it and/or
|
sl@0
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
sl@0
|
7 |
* License as published by the Free Software Foundation; either
|
sl@0
|
8 |
* version 2 of the License, or (at your option) any later version.
|
sl@0
|
9 |
*
|
sl@0
|
10 |
* This library is distributed in the hope that it will be useful,
|
sl@0
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
sl@0
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
sl@0
|
13 |
* Lesser General Public License for more details.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* You should have received a copy of the GNU Lesser General
|
sl@0
|
16 |
* Public License along with this library; if not, write to the
|
sl@0
|
17 |
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
sl@0
|
18 |
* Boston, MA 02111-1307, USA.
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
/*
|
sl@0
|
22 |
* MT safe
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#include "config.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
#include <string.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
#include "genums.h"
|
sl@0
|
30 |
#include "gvalue.h"
|
sl@0
|
31 |
#include "gvaluecollector.h"
|
sl@0
|
32 |
#include "gobjectalias.h"
|
sl@0
|
33 |
|
sl@0
|
34 |
#ifdef __SYMBIAN32__
|
sl@0
|
35 |
#include "gobject_wsd.h"
|
sl@0
|
36 |
#endif /* __SYMBIAN32__ */
|
sl@0
|
37 |
|
sl@0
|
38 |
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
* SECTION:enumerations_flags
|
sl@0
|
41 |
* @short_description: Enumeration and flags types
|
sl@0
|
42 |
* @see_also:#GParamSpecEnum, #GParamSpecFlags, g_param_spec_enum(),
|
sl@0
|
43 |
* g_param_spec_flags(),
|
sl@0
|
44 |
*
|
sl@0
|
45 |
* <link linkend="glib-mkenums">glib-mkenums</link>
|
sl@0
|
46 |
* @title: Enumeration and Flag Types
|
sl@0
|
47 |
*
|
sl@0
|
48 |
* The GLib type system provides fundamental types for enumeration and
|
sl@0
|
49 |
* flags types. (Flags types are like enumerations, but allow their
|
sl@0
|
50 |
* values to be combined by bitwise or). A registered enumeration or
|
sl@0
|
51 |
* flags type associates a name and a nickname with each allowed
|
sl@0
|
52 |
* value, and the methods g_enum_get_value_by_name(),
|
sl@0
|
53 |
* g_enum_get_value_by_nick(), g_flags_get_value_by_name() and
|
sl@0
|
54 |
* g_flags_get_value_by_nick() can look up values by their name or
|
sl@0
|
55 |
* nickname. When an enumeration or flags type is registered with the
|
sl@0
|
56 |
* GLib type system, it can be used as value type for object
|
sl@0
|
57 |
* properties, using g_param_spec_enum() or g_param_spec_flags().
|
sl@0
|
58 |
*
|
sl@0
|
59 |
* GObject ships with a utility called <link
|
sl@0
|
60 |
* linkend="glib-mkenums">glib-mkenums</link> that can construct
|
sl@0
|
61 |
* suitable type registration functions from C enumeration
|
sl@0
|
62 |
* definitions.
|
sl@0
|
63 |
*/
|
sl@0
|
64 |
|
sl@0
|
65 |
|
sl@0
|
66 |
/* --- prototypes --- */
|
sl@0
|
67 |
static void g_enum_class_init (GEnumClass *class,
|
sl@0
|
68 |
gpointer class_data);
|
sl@0
|
69 |
static void g_flags_class_init (GFlagsClass *class,
|
sl@0
|
70 |
gpointer class_data);
|
sl@0
|
71 |
static void value_flags_enum_init (GValue *value);
|
sl@0
|
72 |
static void value_flags_enum_copy_value (const GValue *src_value,
|
sl@0
|
73 |
GValue *dest_value);
|
sl@0
|
74 |
static gchar* value_flags_enum_collect_value (GValue *value,
|
sl@0
|
75 |
guint n_collect_values,
|
sl@0
|
76 |
GTypeCValue *collect_values,
|
sl@0
|
77 |
guint collect_flags);
|
sl@0
|
78 |
static gchar* value_flags_enum_lcopy_value (const GValue *value,
|
sl@0
|
79 |
guint n_collect_values,
|
sl@0
|
80 |
GTypeCValue *collect_values,
|
sl@0
|
81 |
guint collect_flags);
|
sl@0
|
82 |
|
sl@0
|
83 |
/* --- functions --- */
|
sl@0
|
84 |
#if EMULATOR
|
sl@0
|
85 |
|
sl@0
|
86 |
PLS(initialized ,g_enum_types_init,gboolean)
|
sl@0
|
87 |
PLS(info,g_enum_types_init,GTypeInfo)
|
sl@0
|
88 |
|
sl@0
|
89 |
#define initialized (*FUNCTION_NAME(initialized ,g_enum_types_init)())
|
sl@0
|
90 |
#define info (*FUNCTION_NAME(info ,g_enum_types_init)())
|
sl@0
|
91 |
|
sl@0
|
92 |
const GTypeValueTable temp_flags_enum_value_table = {
|
sl@0
|
93 |
value_flags_enum_init, /* value_init */
|
sl@0
|
94 |
NULL, /* value_free */
|
sl@0
|
95 |
value_flags_enum_copy_value, /* value_copy */
|
sl@0
|
96 |
NULL, /* value_peek_pointer */
|
sl@0
|
97 |
"i", /* collect_format */
|
sl@0
|
98 |
value_flags_enum_collect_value, /* collect_value */
|
sl@0
|
99 |
"p", /* lcopy_format */
|
sl@0
|
100 |
value_flags_enum_lcopy_value, /* lcopy_value */
|
sl@0
|
101 |
};
|
sl@0
|
102 |
|
sl@0
|
103 |
const GTypeInfo temp_info = {
|
sl@0
|
104 |
0, /* class_size */
|
sl@0
|
105 |
NULL, /* base_init */
|
sl@0
|
106 |
NULL, /* base_destroy */
|
sl@0
|
107 |
NULL, /* class_init */
|
sl@0
|
108 |
NULL, /* class_destroy */
|
sl@0
|
109 |
NULL, /* class_data */
|
sl@0
|
110 |
0, /* instance_size */
|
sl@0
|
111 |
0, /* n_preallocs */
|
sl@0
|
112 |
NULL, /* instance_init */
|
sl@0
|
113 |
&temp_flags_enum_value_table, /* value_table */
|
sl@0
|
114 |
};
|
sl@0
|
115 |
|
sl@0
|
116 |
#endif /* EMULATOR */
|
sl@0
|
117 |
|
sl@0
|
118 |
void
|
sl@0
|
119 |
g_enum_types_init (void)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
#if !(EMULATOR)
|
sl@0
|
122 |
static gboolean initialized = FALSE;
|
sl@0
|
123 |
#endif /*EMULATOR */
|
sl@0
|
124 |
static const GTypeValueTable flags_enum_value_table = {
|
sl@0
|
125 |
value_flags_enum_init, /* value_init */
|
sl@0
|
126 |
NULL, /* value_free */
|
sl@0
|
127 |
value_flags_enum_copy_value, /* value_copy */
|
sl@0
|
128 |
NULL, /* value_peek_pointer */
|
sl@0
|
129 |
"i", /* collect_format */
|
sl@0
|
130 |
value_flags_enum_collect_value, /* collect_value */
|
sl@0
|
131 |
"p", /* lcopy_format */
|
sl@0
|
132 |
value_flags_enum_lcopy_value, /* lcopy_value */
|
sl@0
|
133 |
};
|
sl@0
|
134 |
|
sl@0
|
135 |
#if !(EMULATOR)
|
sl@0
|
136 |
static GTypeInfo info = {
|
sl@0
|
137 |
0, /* class_size */
|
sl@0
|
138 |
NULL, /* base_init */
|
sl@0
|
139 |
NULL, /* base_destroy */
|
sl@0
|
140 |
NULL, /* class_init */
|
sl@0
|
141 |
NULL, /* class_destroy */
|
sl@0
|
142 |
NULL, /* class_data */
|
sl@0
|
143 |
0, /* instance_size */
|
sl@0
|
144 |
0, /* n_preallocs */
|
sl@0
|
145 |
NULL, /* instance_init */
|
sl@0
|
146 |
&flags_enum_value_table, /* value_table */
|
sl@0
|
147 |
};
|
sl@0
|
148 |
#endif /*EMULATOR */
|
sl@0
|
149 |
|
sl@0
|
150 |
static const GTypeFundamentalInfo finfo = {
|
sl@0
|
151 |
G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE,
|
sl@0
|
152 |
};
|
sl@0
|
153 |
GType type;
|
sl@0
|
154 |
|
sl@0
|
155 |
g_return_if_fail (initialized == FALSE);
|
sl@0
|
156 |
initialized = TRUE;
|
sl@0
|
157 |
|
sl@0
|
158 |
/* G_TYPE_ENUM
|
sl@0
|
159 |
*/
|
sl@0
|
160 |
info.class_size = sizeof (GEnumClass);
|
sl@0
|
161 |
type = g_type_register_fundamental (G_TYPE_ENUM, g_intern_static_string ("GEnum"), &info, &finfo,
|
sl@0
|
162 |
G_TYPE_FLAG_ABSTRACT | G_TYPE_FLAG_VALUE_ABSTRACT);
|
sl@0
|
163 |
g_assert (type == G_TYPE_ENUM);
|
sl@0
|
164 |
|
sl@0
|
165 |
/* G_TYPE_FLAGS
|
sl@0
|
166 |
*/
|
sl@0
|
167 |
info.class_size = sizeof (GFlagsClass);
|
sl@0
|
168 |
type = g_type_register_fundamental (G_TYPE_FLAGS, g_intern_static_string ("GFlags"), &info, &finfo,
|
sl@0
|
169 |
G_TYPE_FLAG_ABSTRACT | G_TYPE_FLAG_VALUE_ABSTRACT);
|
sl@0
|
170 |
g_assert (type == G_TYPE_FLAGS);
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
#if EMULATOR
|
sl@0
|
174 |
#undef initialized
|
sl@0
|
175 |
#undef info
|
sl@0
|
176 |
#endif /* EMULATOR */
|
sl@0
|
177 |
|
sl@0
|
178 |
static void
|
sl@0
|
179 |
value_flags_enum_init (GValue *value)
|
sl@0
|
180 |
{
|
sl@0
|
181 |
value->data[0].v_long = 0;
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
static void
|
sl@0
|
185 |
value_flags_enum_copy_value (const GValue *src_value,
|
sl@0
|
186 |
GValue *dest_value)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
dest_value->data[0].v_long = src_value->data[0].v_long;
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
static gchar*
|
sl@0
|
192 |
value_flags_enum_collect_value (GValue *value,
|
sl@0
|
193 |
guint n_collect_values,
|
sl@0
|
194 |
GTypeCValue *collect_values,
|
sl@0
|
195 |
guint collect_flags)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
value->data[0].v_long = collect_values[0].v_int;
|
sl@0
|
198 |
|
sl@0
|
199 |
return NULL;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
static gchar*
|
sl@0
|
203 |
value_flags_enum_lcopy_value (const GValue *value,
|
sl@0
|
204 |
guint n_collect_values,
|
sl@0
|
205 |
GTypeCValue *collect_values,
|
sl@0
|
206 |
guint collect_flags)
|
sl@0
|
207 |
{
|
sl@0
|
208 |
gint *int_p = collect_values[0].v_pointer;
|
sl@0
|
209 |
|
sl@0
|
210 |
if (!int_p)
|
sl@0
|
211 |
return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
|
sl@0
|
212 |
|
sl@0
|
213 |
*int_p = value->data[0].v_long;
|
sl@0
|
214 |
|
sl@0
|
215 |
return NULL;
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
/**
|
sl@0
|
219 |
* g_enum_register_static:
|
sl@0
|
220 |
* @name: A nul-terminated string used as the name of the new type.
|
sl@0
|
221 |
* @const_static_values: An array of #GEnumValue structs for the possible
|
sl@0
|
222 |
* enumeration values. The array is terminated by a struct with all
|
sl@0
|
223 |
* members being 0. GObject keeps a reference to the data, so it cannot
|
sl@0
|
224 |
* be stack-allocated.
|
sl@0
|
225 |
*
|
sl@0
|
226 |
* Registers a new static enumeration type with the name @name.
|
sl@0
|
227 |
*
|
sl@0
|
228 |
* It is normally more convenient to let <link
|
sl@0
|
229 |
* linkend="glib-mkenums">glib-mkenums</link> generate a
|
sl@0
|
230 |
* my_enum_get_type() function from a usual C enumeration definition
|
sl@0
|
231 |
* than to write one yourself using g_enum_register_static().
|
sl@0
|
232 |
*
|
sl@0
|
233 |
* Returns: The new type identifier.
|
sl@0
|
234 |
*/
|
sl@0
|
235 |
EXPORT_C GType
|
sl@0
|
236 |
g_enum_register_static (const gchar *name,
|
sl@0
|
237 |
const GEnumValue *const_static_values)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
GTypeInfo enum_type_info = {
|
sl@0
|
240 |
sizeof (GEnumClass), /* class_size */
|
sl@0
|
241 |
NULL, /* base_init */
|
sl@0
|
242 |
NULL, /* base_finalize */
|
sl@0
|
243 |
(GClassInitFunc) g_enum_class_init,
|
sl@0
|
244 |
NULL, /* class_finalize */
|
sl@0
|
245 |
NULL, /* class_data */
|
sl@0
|
246 |
0, /* instance_size */
|
sl@0
|
247 |
0, /* n_preallocs */
|
sl@0
|
248 |
NULL, /* instance_init */
|
sl@0
|
249 |
NULL, /* value_table */
|
sl@0
|
250 |
};
|
sl@0
|
251 |
GType type;
|
sl@0
|
252 |
|
sl@0
|
253 |
g_return_val_if_fail (name != NULL, 0);
|
sl@0
|
254 |
g_return_val_if_fail (const_static_values != NULL, 0);
|
sl@0
|
255 |
|
sl@0
|
256 |
enum_type_info.class_data = const_static_values;
|
sl@0
|
257 |
|
sl@0
|
258 |
type = g_type_register_static (G_TYPE_ENUM, name, &enum_type_info, 0);
|
sl@0
|
259 |
|
sl@0
|
260 |
return type;
|
sl@0
|
261 |
}
|
sl@0
|
262 |
|
sl@0
|
263 |
/**
|
sl@0
|
264 |
* g_flags_register_static:
|
sl@0
|
265 |
* @name: A nul-terminated string used as the name of the new type.
|
sl@0
|
266 |
* @const_static_values: An array of #GFlagsValue structs for the possible
|
sl@0
|
267 |
* flags values. The array is terminated by a struct with all members being 0.
|
sl@0
|
268 |
* GObject keeps a reference to the data, so it cannot be stack-allocated.
|
sl@0
|
269 |
*
|
sl@0
|
270 |
* Registers a new static flags type with the name @name.
|
sl@0
|
271 |
*
|
sl@0
|
272 |
* It is normally more convenient to let <link
|
sl@0
|
273 |
* linkend="glib-mkenums">glib-mkenums</link> generate a
|
sl@0
|
274 |
* my_flags_get_type() function from a usual C enumeration definition
|
sl@0
|
275 |
* than to write one yourself using g_flags_register_static().
|
sl@0
|
276 |
*
|
sl@0
|
277 |
* Returns: The new type identifier.
|
sl@0
|
278 |
*/
|
sl@0
|
279 |
EXPORT_C GType
|
sl@0
|
280 |
g_flags_register_static (const gchar *name,
|
sl@0
|
281 |
const GFlagsValue *const_static_values)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
GTypeInfo flags_type_info = {
|
sl@0
|
284 |
sizeof (GFlagsClass), /* class_size */
|
sl@0
|
285 |
NULL, /* base_init */
|
sl@0
|
286 |
NULL, /* base_finalize */
|
sl@0
|
287 |
(GClassInitFunc) g_flags_class_init,
|
sl@0
|
288 |
NULL, /* class_finalize */
|
sl@0
|
289 |
NULL, /* class_data */
|
sl@0
|
290 |
0, /* instance_size */
|
sl@0
|
291 |
0, /* n_preallocs */
|
sl@0
|
292 |
NULL, /* instance_init */
|
sl@0
|
293 |
NULL, /* value_table */
|
sl@0
|
294 |
};
|
sl@0
|
295 |
GType type;
|
sl@0
|
296 |
|
sl@0
|
297 |
g_return_val_if_fail (name != NULL, 0);
|
sl@0
|
298 |
g_return_val_if_fail (const_static_values != NULL, 0);
|
sl@0
|
299 |
|
sl@0
|
300 |
flags_type_info.class_data = const_static_values;
|
sl@0
|
301 |
|
sl@0
|
302 |
type = g_type_register_static (G_TYPE_FLAGS, name, &flags_type_info, 0);
|
sl@0
|
303 |
|
sl@0
|
304 |
return type;
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
/**
|
sl@0
|
308 |
* g_enum_complete_type_info:
|
sl@0
|
309 |
* @g_enum_type: the type identifier of the type being completed
|
sl@0
|
310 |
* @info: the #GTypeInfo struct to be filled in
|
sl@0
|
311 |
* @const_values: An array of #GEnumValue structs for the possible
|
sl@0
|
312 |
* enumeration values. The array is terminated by a struct with all
|
sl@0
|
313 |
* members being 0.
|
sl@0
|
314 |
*
|
sl@0
|
315 |
* This function is meant to be called from the complete_type_info()
|
sl@0
|
316 |
* function of a #GTypePlugin implementation, as in the following
|
sl@0
|
317 |
* example:
|
sl@0
|
318 |
*
|
sl@0
|
319 |
* |[
|
sl@0
|
320 |
* static void
|
sl@0
|
321 |
* my_enum_complete_type_info (GTypePlugin *plugin,
|
sl@0
|
322 |
* GType g_type,
|
sl@0
|
323 |
* GTypeInfo *info,
|
sl@0
|
324 |
* GTypeValueTable *value_table)
|
sl@0
|
325 |
* {
|
sl@0
|
326 |
* static const GEnumValue values[] = {
|
sl@0
|
327 |
* { MY_ENUM_FOO, "MY_ENUM_FOO", "foo" },
|
sl@0
|
328 |
* { MY_ENUM_BAR, "MY_ENUM_BAR", "bar" },
|
sl@0
|
329 |
* { 0, NULL, NULL }
|
sl@0
|
330 |
* };
|
sl@0
|
331 |
*
|
sl@0
|
332 |
* g_enum_complete_type_info (type, info, values);
|
sl@0
|
333 |
* }
|
sl@0
|
334 |
* ]|
|
sl@0
|
335 |
*/
|
sl@0
|
336 |
EXPORT_C void
|
sl@0
|
337 |
g_enum_complete_type_info (GType g_enum_type,
|
sl@0
|
338 |
GTypeInfo *info,
|
sl@0
|
339 |
const GEnumValue *const_values)
|
sl@0
|
340 |
{
|
sl@0
|
341 |
g_return_if_fail (G_TYPE_IS_ENUM (g_enum_type));
|
sl@0
|
342 |
g_return_if_fail (info != NULL);
|
sl@0
|
343 |
g_return_if_fail (const_values != NULL);
|
sl@0
|
344 |
|
sl@0
|
345 |
info->class_size = sizeof (GEnumClass);
|
sl@0
|
346 |
info->base_init = NULL;
|
sl@0
|
347 |
info->base_finalize = NULL;
|
sl@0
|
348 |
info->class_init = (GClassInitFunc) g_enum_class_init;
|
sl@0
|
349 |
info->class_finalize = NULL;
|
sl@0
|
350 |
info->class_data = const_values;
|
sl@0
|
351 |
}
|
sl@0
|
352 |
|
sl@0
|
353 |
/**
|
sl@0
|
354 |
* g_flags_complete_type_info:
|
sl@0
|
355 |
* @g_flags_type: the type identifier of the type being completed
|
sl@0
|
356 |
* @info: the #GTypeInfo struct to be filled in
|
sl@0
|
357 |
* @const_values: An array of #GFlagsValue structs for the possible
|
sl@0
|
358 |
* enumeration values. The array is terminated by a struct with all
|
sl@0
|
359 |
* members being 0.
|
sl@0
|
360 |
*
|
sl@0
|
361 |
* This function is meant to be called from the complete_type_info()
|
sl@0
|
362 |
* function of a #GTypePlugin implementation, see the example for
|
sl@0
|
363 |
* g_enum_complete_type_info() above.
|
sl@0
|
364 |
*/
|
sl@0
|
365 |
EXPORT_C void
|
sl@0
|
366 |
g_flags_complete_type_info (GType g_flags_type,
|
sl@0
|
367 |
GTypeInfo *info,
|
sl@0
|
368 |
const GFlagsValue *const_values)
|
sl@0
|
369 |
{
|
sl@0
|
370 |
g_return_if_fail (G_TYPE_IS_FLAGS (g_flags_type));
|
sl@0
|
371 |
g_return_if_fail (info != NULL);
|
sl@0
|
372 |
g_return_if_fail (const_values != NULL);
|
sl@0
|
373 |
|
sl@0
|
374 |
info->class_size = sizeof (GFlagsClass);
|
sl@0
|
375 |
info->base_init = NULL;
|
sl@0
|
376 |
info->base_finalize = NULL;
|
sl@0
|
377 |
info->class_init = (GClassInitFunc) g_flags_class_init;
|
sl@0
|
378 |
info->class_finalize = NULL;
|
sl@0
|
379 |
info->class_data = const_values;
|
sl@0
|
380 |
}
|
sl@0
|
381 |
|
sl@0
|
382 |
static void
|
sl@0
|
383 |
g_enum_class_init (GEnumClass *class,
|
sl@0
|
384 |
gpointer class_data)
|
sl@0
|
385 |
{
|
sl@0
|
386 |
g_return_if_fail (G_IS_ENUM_CLASS (class));
|
sl@0
|
387 |
|
sl@0
|
388 |
class->minimum = 0;
|
sl@0
|
389 |
class->maximum = 0;
|
sl@0
|
390 |
class->n_values = 0;
|
sl@0
|
391 |
class->values = class_data;
|
sl@0
|
392 |
|
sl@0
|
393 |
if (class->values)
|
sl@0
|
394 |
{
|
sl@0
|
395 |
GEnumValue *values;
|
sl@0
|
396 |
|
sl@0
|
397 |
class->minimum = class->values->value;
|
sl@0
|
398 |
class->maximum = class->values->value;
|
sl@0
|
399 |
for (values = class->values; values->value_name; values++)
|
sl@0
|
400 |
{
|
sl@0
|
401 |
class->minimum = MIN (class->minimum, values->value);
|
sl@0
|
402 |
class->maximum = MAX (class->maximum, values->value);
|
sl@0
|
403 |
class->n_values++;
|
sl@0
|
404 |
}
|
sl@0
|
405 |
}
|
sl@0
|
406 |
}
|
sl@0
|
407 |
|
sl@0
|
408 |
static void
|
sl@0
|
409 |
g_flags_class_init (GFlagsClass *class,
|
sl@0
|
410 |
gpointer class_data)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
g_return_if_fail (G_IS_FLAGS_CLASS (class));
|
sl@0
|
413 |
|
sl@0
|
414 |
class->mask = 0;
|
sl@0
|
415 |
class->n_values = 0;
|
sl@0
|
416 |
class->values = class_data;
|
sl@0
|
417 |
|
sl@0
|
418 |
if (class->values)
|
sl@0
|
419 |
{
|
sl@0
|
420 |
GFlagsValue *values;
|
sl@0
|
421 |
|
sl@0
|
422 |
for (values = class->values; values->value_name; values++)
|
sl@0
|
423 |
{
|
sl@0
|
424 |
class->mask |= values->value;
|
sl@0
|
425 |
class->n_values++;
|
sl@0
|
426 |
}
|
sl@0
|
427 |
}
|
sl@0
|
428 |
}
|
sl@0
|
429 |
|
sl@0
|
430 |
/**
|
sl@0
|
431 |
* g_enum_get_value_by_name:
|
sl@0
|
432 |
* @enum_class: a #GEnumClass
|
sl@0
|
433 |
* @name: the name to look up
|
sl@0
|
434 |
*
|
sl@0
|
435 |
* Looks up a #GEnumValue by name.
|
sl@0
|
436 |
*
|
sl@0
|
437 |
* Returns: the #GEnumValue with name @name, or %NULL if the
|
sl@0
|
438 |
* enumeration doesn't have a member with that name
|
sl@0
|
439 |
*/
|
sl@0
|
440 |
EXPORT_C GEnumValue*
|
sl@0
|
441 |
g_enum_get_value_by_name (GEnumClass *enum_class,
|
sl@0
|
442 |
const gchar *name)
|
sl@0
|
443 |
{
|
sl@0
|
444 |
g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), NULL);
|
sl@0
|
445 |
g_return_val_if_fail (name != NULL, NULL);
|
sl@0
|
446 |
|
sl@0
|
447 |
if (enum_class->n_values)
|
sl@0
|
448 |
{
|
sl@0
|
449 |
GEnumValue *enum_value;
|
sl@0
|
450 |
|
sl@0
|
451 |
for (enum_value = enum_class->values; enum_value->value_name; enum_value++)
|
sl@0
|
452 |
if (strcmp (name, enum_value->value_name) == 0)
|
sl@0
|
453 |
return enum_value;
|
sl@0
|
454 |
}
|
sl@0
|
455 |
|
sl@0
|
456 |
return NULL;
|
sl@0
|
457 |
}
|
sl@0
|
458 |
|
sl@0
|
459 |
/**
|
sl@0
|
460 |
* g_flags_get_value_by_name:
|
sl@0
|
461 |
* @flags_class: a #GFlagsClass
|
sl@0
|
462 |
* @name: the name to look up
|
sl@0
|
463 |
*
|
sl@0
|
464 |
* Looks up a #GFlagsValue by name.
|
sl@0
|
465 |
*
|
sl@0
|
466 |
* Returns: the #GFlagsValue with name @name, or %NULL if there is no
|
sl@0
|
467 |
* flag with that name
|
sl@0
|
468 |
*/
|
sl@0
|
469 |
EXPORT_C GFlagsValue*
|
sl@0
|
470 |
g_flags_get_value_by_name (GFlagsClass *flags_class,
|
sl@0
|
471 |
const gchar *name)
|
sl@0
|
472 |
{
|
sl@0
|
473 |
g_return_val_if_fail (G_IS_FLAGS_CLASS (flags_class), NULL);
|
sl@0
|
474 |
g_return_val_if_fail (name != NULL, NULL);
|
sl@0
|
475 |
|
sl@0
|
476 |
if (flags_class->n_values)
|
sl@0
|
477 |
{
|
sl@0
|
478 |
GFlagsValue *flags_value;
|
sl@0
|
479 |
|
sl@0
|
480 |
for (flags_value = flags_class->values; flags_value->value_name; flags_value++)
|
sl@0
|
481 |
if (strcmp (name, flags_value->value_name) == 0)
|
sl@0
|
482 |
return flags_value;
|
sl@0
|
483 |
}
|
sl@0
|
484 |
|
sl@0
|
485 |
return NULL;
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
/**
|
sl@0
|
489 |
* g_enum_get_value_by_nick:
|
sl@0
|
490 |
* @enum_class: a #GEnumClass
|
sl@0
|
491 |
* @nick: the nickname to look up
|
sl@0
|
492 |
*
|
sl@0
|
493 |
* Looks up a #GEnumValue by nickname.
|
sl@0
|
494 |
*
|
sl@0
|
495 |
* Returns: the #GEnumValue with nickname @nick, or %NULL if the
|
sl@0
|
496 |
* enumeration doesn't have a member with that nickname
|
sl@0
|
497 |
*/
|
sl@0
|
498 |
EXPORT_C GEnumValue*
|
sl@0
|
499 |
g_enum_get_value_by_nick (GEnumClass *enum_class,
|
sl@0
|
500 |
const gchar *nick)
|
sl@0
|
501 |
{
|
sl@0
|
502 |
g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), NULL);
|
sl@0
|
503 |
g_return_val_if_fail (nick != NULL, NULL);
|
sl@0
|
504 |
|
sl@0
|
505 |
if (enum_class->n_values)
|
sl@0
|
506 |
{
|
sl@0
|
507 |
GEnumValue *enum_value;
|
sl@0
|
508 |
|
sl@0
|
509 |
for (enum_value = enum_class->values; enum_value->value_name; enum_value++)
|
sl@0
|
510 |
if (enum_value->value_nick && strcmp (nick, enum_value->value_nick) == 0)
|
sl@0
|
511 |
return enum_value;
|
sl@0
|
512 |
}
|
sl@0
|
513 |
|
sl@0
|
514 |
return NULL;
|
sl@0
|
515 |
}
|
sl@0
|
516 |
|
sl@0
|
517 |
/**
|
sl@0
|
518 |
* g_flags_get_value_by_nick:
|
sl@0
|
519 |
* @flags_class: a #GFlagsClass
|
sl@0
|
520 |
* @nick: the nickname to look up
|
sl@0
|
521 |
*
|
sl@0
|
522 |
* Looks up a #GFlagsValue by nickname.
|
sl@0
|
523 |
*
|
sl@0
|
524 |
* Returns: the #GFlagsValue with nickname @nick, or %NULL if there is
|
sl@0
|
525 |
* no flag with that nickname
|
sl@0
|
526 |
*/
|
sl@0
|
527 |
EXPORT_C GFlagsValue*
|
sl@0
|
528 |
g_flags_get_value_by_nick (GFlagsClass *flags_class,
|
sl@0
|
529 |
const gchar *nick)
|
sl@0
|
530 |
{
|
sl@0
|
531 |
g_return_val_if_fail (G_IS_FLAGS_CLASS (flags_class), NULL);
|
sl@0
|
532 |
g_return_val_if_fail (nick != NULL, NULL);
|
sl@0
|
533 |
|
sl@0
|
534 |
if (flags_class->n_values)
|
sl@0
|
535 |
{
|
sl@0
|
536 |
GFlagsValue *flags_value;
|
sl@0
|
537 |
|
sl@0
|
538 |
for (flags_value = flags_class->values; flags_value->value_nick; flags_value++)
|
sl@0
|
539 |
if (flags_value->value_nick && strcmp (nick, flags_value->value_nick) == 0)
|
sl@0
|
540 |
return flags_value;
|
sl@0
|
541 |
}
|
sl@0
|
542 |
|
sl@0
|
543 |
return NULL;
|
sl@0
|
544 |
}
|
sl@0
|
545 |
|
sl@0
|
546 |
/**
|
sl@0
|
547 |
* g_enum_get_value:
|
sl@0
|
548 |
* @enum_class: a #GEnumClass
|
sl@0
|
549 |
* @value: the value to look up
|
sl@0
|
550 |
*
|
sl@0
|
551 |
* Returns the #GEnumValue for a value.
|
sl@0
|
552 |
*
|
sl@0
|
553 |
* Returns: the #GEnumValue for @value, or %NULL if @value is not a
|
sl@0
|
554 |
* member of the enumeration
|
sl@0
|
555 |
*/
|
sl@0
|
556 |
EXPORT_C GEnumValue*
|
sl@0
|
557 |
g_enum_get_value (GEnumClass *enum_class,
|
sl@0
|
558 |
gint value)
|
sl@0
|
559 |
{
|
sl@0
|
560 |
g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), NULL);
|
sl@0
|
561 |
|
sl@0
|
562 |
if (enum_class->n_values)
|
sl@0
|
563 |
{
|
sl@0
|
564 |
GEnumValue *enum_value;
|
sl@0
|
565 |
|
sl@0
|
566 |
for (enum_value = enum_class->values; enum_value->value_name; enum_value++)
|
sl@0
|
567 |
if (enum_value->value == value)
|
sl@0
|
568 |
return enum_value;
|
sl@0
|
569 |
}
|
sl@0
|
570 |
|
sl@0
|
571 |
return NULL;
|
sl@0
|
572 |
}
|
sl@0
|
573 |
|
sl@0
|
574 |
/**
|
sl@0
|
575 |
* g_flags_get_first_value:
|
sl@0
|
576 |
* @flags_class: a #GFlagsClass
|
sl@0
|
577 |
* @value: the value
|
sl@0
|
578 |
*
|
sl@0
|
579 |
* Returns the first #GFlagsValue which is set in @value.
|
sl@0
|
580 |
*
|
sl@0
|
581 |
* Returns: the first #GFlagsValue which is set in @value, or %NULL if
|
sl@0
|
582 |
* none is set
|
sl@0
|
583 |
*/
|
sl@0
|
584 |
EXPORT_C GFlagsValue*
|
sl@0
|
585 |
g_flags_get_first_value (GFlagsClass *flags_class,
|
sl@0
|
586 |
guint value)
|
sl@0
|
587 |
{
|
sl@0
|
588 |
g_return_val_if_fail (G_IS_FLAGS_CLASS (flags_class), NULL);
|
sl@0
|
589 |
|
sl@0
|
590 |
if (flags_class->n_values)
|
sl@0
|
591 |
{
|
sl@0
|
592 |
GFlagsValue *flags_value;
|
sl@0
|
593 |
|
sl@0
|
594 |
if (value == 0)
|
sl@0
|
595 |
{
|
sl@0
|
596 |
for (flags_value = flags_class->values; flags_value->value_name; flags_value++)
|
sl@0
|
597 |
if (flags_value->value == 0)
|
sl@0
|
598 |
return flags_value;
|
sl@0
|
599 |
}
|
sl@0
|
600 |
else
|
sl@0
|
601 |
{
|
sl@0
|
602 |
for (flags_value = flags_class->values; flags_value->value_name; flags_value++)
|
sl@0
|
603 |
if (flags_value->value != 0 && (flags_value->value & value) == flags_value->value)
|
sl@0
|
604 |
return flags_value;
|
sl@0
|
605 |
}
|
sl@0
|
606 |
}
|
sl@0
|
607 |
|
sl@0
|
608 |
return NULL;
|
sl@0
|
609 |
}
|
sl@0
|
610 |
|
sl@0
|
611 |
/**
|
sl@0
|
612 |
* g_value_set_enum:
|
sl@0
|
613 |
* @value: a valid #GValue whose type is derived from %G_TYPE_ENUM
|
sl@0
|
614 |
* @v_enum: enum value to be set
|
sl@0
|
615 |
*
|
sl@0
|
616 |
* Set the contents of a %G_TYPE_ENUM #GValue to @v_enum.
|
sl@0
|
617 |
*/
|
sl@0
|
618 |
EXPORT_C void
|
sl@0
|
619 |
g_value_set_enum (GValue *value,
|
sl@0
|
620 |
gint v_enum)
|
sl@0
|
621 |
{
|
sl@0
|
622 |
g_return_if_fail (G_VALUE_HOLDS_ENUM (value));
|
sl@0
|
623 |
|
sl@0
|
624 |
value->data[0].v_long = v_enum;
|
sl@0
|
625 |
}
|
sl@0
|
626 |
|
sl@0
|
627 |
/**
|
sl@0
|
628 |
* g_value_get_enum:
|
sl@0
|
629 |
* @value: a valid #GValue whose type is derived from %G_TYPE_ENUM
|
sl@0
|
630 |
*
|
sl@0
|
631 |
* Get the contents of a %G_TYPE_ENUM #GValue.
|
sl@0
|
632 |
*
|
sl@0
|
633 |
* Returns: enum contents of @value
|
sl@0
|
634 |
*/
|
sl@0
|
635 |
EXPORT_C gint
|
sl@0
|
636 |
g_value_get_enum (const GValue *value)
|
sl@0
|
637 |
{
|
sl@0
|
638 |
g_return_val_if_fail (G_VALUE_HOLDS_ENUM (value), 0);
|
sl@0
|
639 |
|
sl@0
|
640 |
return value->data[0].v_long;
|
sl@0
|
641 |
}
|
sl@0
|
642 |
|
sl@0
|
643 |
/**
|
sl@0
|
644 |
* g_value_set_flags:
|
sl@0
|
645 |
* @value: a valid #GValue whose type is derived from %G_TYPE_FLAGS
|
sl@0
|
646 |
* @v_flags: flags value to be set
|
sl@0
|
647 |
*
|
sl@0
|
648 |
* Set the contents of a %G_TYPE_FLAGS #GValue to @v_flags.
|
sl@0
|
649 |
*/
|
sl@0
|
650 |
EXPORT_C void
|
sl@0
|
651 |
g_value_set_flags (GValue *value,
|
sl@0
|
652 |
guint v_flags)
|
sl@0
|
653 |
{
|
sl@0
|
654 |
g_return_if_fail (G_VALUE_HOLDS_FLAGS (value));
|
sl@0
|
655 |
|
sl@0
|
656 |
value->data[0].v_ulong = v_flags;
|
sl@0
|
657 |
}
|
sl@0
|
658 |
|
sl@0
|
659 |
/**
|
sl@0
|
660 |
* g_value_get_flags:
|
sl@0
|
661 |
* @value: a valid #GValue whose type is derived from %G_TYPE_FLAGS
|
sl@0
|
662 |
*
|
sl@0
|
663 |
* Get the contents of a %G_TYPE_FLAGS #GValue.
|
sl@0
|
664 |
*
|
sl@0
|
665 |
* Returns: flags contents of @value
|
sl@0
|
666 |
*/
|
sl@0
|
667 |
EXPORT_C guint
|
sl@0
|
668 |
g_value_get_flags (const GValue *value)
|
sl@0
|
669 |
{
|
sl@0
|
670 |
g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (value), 0);
|
sl@0
|
671 |
|
sl@0
|
672 |
return value->data[0].v_ulong;
|
sl@0
|
673 |
}
|
sl@0
|
674 |
|
sl@0
|
675 |
#define __G_ENUMS_C__
|
sl@0
|
676 |
#include "gobjectaliasdef.c"
|