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