| 1 |
/*** BEGIN file-header ***/ |
| 2 |
|
| 3 |
/*** END file-header ***/ |
| 4 |
|
| 5 |
/*** BEGIN file-production ***/ |
| 6 |
/* enumerations from "@filename@" */ |
| 7 |
/*** END file-production ***/ |
| 8 |
|
| 9 |
/*** BEGIN value-header ***/ |
| 10 |
static const G@Type@Value @enum_name@_values[] = { |
| 11 |
/*** END value-header ***/ |
| 12 |
/*** BEGIN value-production ***/ |
| 13 |
{ @VALUENAME@, "@VALUENAME@", "@valuenick@" }, |
| 14 |
/*** END value-production ***/ |
| 15 |
/*** BEGIN value-tail ***/ |
| 16 |
{ 0, NULL, NULL } |
| 17 |
}; |
| 18 |
|
| 19 |
/* Define type-specific symbols */ |
| 20 |
|
| 21 |
GType |
| 22 |
@enum_name@_get_type (void) |
| 23 |
{ |
| 24 |
static gsize g_define_type_id_initialized = 0; |
| 25 |
|
| 26 |
if (g_once_init_enter (&g_define_type_id_initialized)) { |
| 27 |
GType g_define_type_id = |
| 28 |
g_@type@_register_static (g_intern_static_string ("@EnumName@"), |
| 29 |
@enum_name@_values); |
| 30 |
g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); |
| 31 |
} |
| 32 |
|
| 33 |
return g_define_type_id_initialized; |
| 34 |
} |
| 35 |
|
| 36 |
/* Flags-specific method to build a string with the given mask. |
| 37 |
* We get a comma separated list of the nicks of the GFlagsValues. |
| 38 |
* Note that this will be valid even if the GFlagsClass is not referenced |
| 39 |
* anywhere. */ |
| 40 |
gchar * |
| 41 |
@enum_name@_build_string_from_mask (@EnumName@ mask) |
| 42 |
{ |
| 43 |
guint i; |
| 44 |
gboolean first = TRUE; |
| 45 |
GString *str = NULL; |
| 46 |
|
| 47 |
for (i = 0; @enum_name@_values[i].value_nick; i++) { |
| 48 |
/* We also look for exact matches */ |
| 49 |
if ((guint)mask == @enum_name@_values[i].value) { |
| 50 |
if (str) |
| 51 |
g_string_free (str, TRUE); |
| 52 |
return g_strdup (@enum_name@_values[i].value_nick); |
| 53 |
} |
| 54 |
|
| 55 |
/* Build list with single-bit masks */ |
| 56 |
if (mask & @enum_name@_values[i].value) { |
| 57 |
guint c; |
| 58 |
gulong number = @enum_name@_values[i].value; |
| 59 |
|
| 60 |
for (c = 0; number; c++) |
| 61 |
number &= number - 1; |
| 62 |
|
| 63 |
if (c == 1) { |
| 64 |
if (!str) |
| 65 |
str = g_string_new (""); |
| 66 |
g_string_append_printf (str, "%s%s", |
| 67 |
first ? "" : ", ", |
| 68 |
@enum_name@_values[i].value_nick); |
| 69 |
if (first) |
| 70 |
first = FALSE; |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
return (str ? g_string_free (str, FALSE) : NULL); |
| 76 |
} |
| 77 |
|
| 78 |
/*** END value-tail ***/ |
| 79 |
|
| 80 |
/*** BEGIN file-tail ***/ |
| 81 |
/*** END file-tail ***/ |