~elementary-os/ubuntu-package-imports/geoclue-2.0-bionic

« back to all changes in this revision

Viewing changes to build-aux/gclue-enums-template.c

  • Committer: RabbitBot
  • Date: 2018-03-13 02:28:15 UTC
  • Revision ID: rabbitbot@elementary.io-20180313022815-09zi5rzcm3grfnxe
Initial import, version 2.4.7-1ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#undef __GCLUE_IS_ENUM__
 
21
#undef __GCLUE_IS_FLAGS__
 
22
#define __GCLUE_IS_@TYPE@__
 
23
 
 
24
GType
 
25
@enum_name@_get_type (void)
 
26
{
 
27
    static volatile gsize g_define_type_id__volatile = 0;
 
28
 
 
29
    if (g_once_init_enter (&g_define_type_id__volatile)) {
 
30
        GType g_define_type_id =
 
31
            g_@type@_register_static (g_intern_static_string ("@EnumName@"),
 
32
                                      @enum_name@_values);
 
33
        g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
 
34
    }
 
35
 
 
36
    return g_define_type_id__volatile;
 
37
}
 
38
 
 
39
/**
 
40
 * @enum_name@_get_string:
 
41
 * @val: a @EnumName@.
 
42
 *
 
43
 * Gets the nickname string for the #@EnumName@ specified at @val.
 
44
 *
 
45
 * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value.
 
46
 */
 
47
#if defined __GCLUE_IS_ENUM__
 
48
const gchar *
 
49
@enum_name@_get_string (@EnumName@ val)
 
50
{
 
51
    guint i;
 
52
 
 
53
    for (i = 0; @enum_name@_values[i].value_nick; i++) {
 
54
        if (val == @enum_name@_values[i].value)
 
55
            return @enum_name@_values[i].value_nick;
 
56
    }
 
57
 
 
58
    return NULL;
 
59
}
 
60
#endif /* __GCLUE_IS_ENUM_ */
 
61
 
 
62
/**
 
63
 * @enum_name@_build_string_from_mask:
 
64
 * @mask: bitmask of @EnumName@ values.
 
65
 *
 
66
 * Builds a string containing a comma-separated list of nicknames for
 
67
 * each #@EnumName@ in @mask.
 
68
 *
 
69
 * Returns: (transfer full): a string with the list of nicknames, or %NULL if none given. The returned value should be freed with g_free().
 
70
 */
 
71
#if defined __GCLUE_IS_FLAGS__
 
72
gchar *
 
73
@enum_name@_build_string_from_mask (@EnumName@ mask)
 
74
{
 
75
    guint i;
 
76
    gboolean first = TRUE;
 
77
    GString *str = NULL;
 
78
 
 
79
    for (i = 0; @enum_name@_values[i].value_nick; i++) {
 
80
        /* We also look for exact matches */
 
81
        if (mask == @enum_name@_values[i].value) {
 
82
            if (str)
 
83
                g_string_free (str, TRUE);
 
84
            return g_strdup (@enum_name@_values[i].value_nick);
 
85
        }
 
86
 
 
87
        /* Build list with single-bit masks */
 
88
        if (mask & @enum_name@_values[i].value) {
 
89
            guint c;
 
90
            gulong number = @enum_name@_values[i].value;
 
91
 
 
92
            for (c = 0; number; c++)
 
93
                number &= number - 1;
 
94
 
 
95
            if (c == 1) {
 
96
                if (!str)
 
97
                    str = g_string_new ("");
 
98
                g_string_append_printf (str, "%s%s",
 
99
                                        first ? "" : ", ",
 
100
                                        @enum_name@_values[i].value_nick);
 
101
                if (first)
 
102
                    first = FALSE;
 
103
            }
 
104
        }
 
105
    }
 
106
 
 
107
    return (str ? g_string_free (str, FALSE) : NULL);
 
108
}
 
109
#endif /* __GCLUE_IS_FLAGS__ */
 
110
 
 
111
/*** END value-tail ***/
 
112
 
 
113
/*** BEGIN file-tail ***/
 
114
/*** END file-tail ***/