~ubuntu-branches/ubuntu/utopic/glib2.0/utopic

« back to all changes in this revision

Viewing changes to docs/reference/gobject/tmpl/enumerations_flags.sgml

Tags: upstream-2.12.12
ImportĀ upstreamĀ versionĀ 2.12.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!-- ##### SECTION Title ##### -->
 
2
Enums and Flags
 
3
 
 
4
<!-- ##### SECTION Short_Description ##### -->
 
5
Enumeration and flags types
 
6
 
 
7
<!-- ##### SECTION Long_Description ##### -->
 
8
<para>
 
9
The GLib type system provides fundamental types for enumeration and flags types. (Flags types
 
10
are like enumerations, but allow their values to be combined by bitwise or). A registered 
 
11
enumeration or flags type associates a name and a nickname with each allowed value, and 
 
12
the methods g_enum_get_value_by_name(), g_enum_get_value_by_nick(), g_flags_get_value_by_name()
 
13
and g_flags_get_value_by_nick() can look up values by their name or nickname.
 
14
When an enumeration or flags type is registered with the GLib type system, it can
 
15
be used as value type for object properties, using g_param_spec_enum() or 
 
16
g_param_spec_flags().
 
17
</para>
 
18
<para>
 
19
GObject ships with a utility called <link linkend="glib-mkenums">glib-mkenums</link> that can 
 
20
construct suitable type registration functions from C enumeration definitions.
 
21
</para>
 
22
 
 
23
<!-- ##### SECTION See_Also ##### -->
 
24
<para>
 
25
#GParamSpecEnum, #GParamSpecFlags, g_param_spec_enum(), g_param_spec_flags(), 
 
26
<link linkend="glib-mkenums">glib-mkenums</link>
 
27
</para>
 
28
 
 
29
<!-- ##### SECTION Stability_Level ##### -->
 
30
 
 
31
 
 
32
<!-- ##### STRUCT GEnumClass ##### -->
 
33
<para>
 
34
The class of an enumeration type holds information about its 
 
35
possible values.
 
36
</para>
 
37
 
 
38
@g_type_class: the parent class
 
39
@minimum: the smallest possible value.
 
40
@maximum: the largest possible value.
 
41
@n_values: the number of possible values.
 
42
@values: an array of #GEnumValue structs describing the 
 
43
individual values.
 
44
 
 
45
<!-- ##### STRUCT GFlagsClass ##### -->
 
46
<para>
 
47
The class of a flags type holds information about its 
 
48
possible values.
 
49
</para>
 
50
 
 
51
@g_type_class: the parent class
 
52
@mask: a mask covering all possible values.
 
53
@n_values: the number of possible values.
 
54
@values: an array of #GFlagsValue structs describing the 
 
55
individual values.
 
56
 
 
57
<!-- ##### MACRO G_ENUM_CLASS_TYPE ##### -->
 
58
<para>
 
59
Returns the type identifier from a given #GEnumClass structure.
 
60
</para>
 
61
 
 
62
@class: a #GEnumClass
 
63
 
 
64
 
 
65
<!-- ##### MACRO G_ENUM_CLASS_TYPE_NAME ##### -->
 
66
<para>
 
67
Returns the static type name from a given #GEnumClass structure.
 
68
</para>
 
69
 
 
70
@class: a #GEnumClass
 
71
 
 
72
 
 
73
<!-- ##### MACRO G_TYPE_IS_ENUM ##### -->
 
74
<para>
 
75
Returns whether @type "is a" %G_TYPE_ENUM.
 
76
</para>
 
77
 
 
78
@type: a #GType ID.
 
79
 
 
80
 
 
81
<!-- ##### MACRO G_ENUM_CLASS ##### -->
 
82
<para>
 
83
Casts a derived #GEnumClass structure into a #GEnumClass structure.
 
84
</para>
 
85
 
 
86
@class: a valid #GEnumClass
 
87
 
 
88
 
 
89
<!-- ##### MACRO G_IS_ENUM_CLASS ##### -->
 
90
<para>
 
91
Checks whether @class "is a" valid #GEnumClass structure of type %G_TYPE_ENUM
 
92
or derived.
 
93
</para>
 
94
 
 
95
@class: a #GEnumClass
 
96
 
 
97
 
 
98
<!-- ##### MACRO G_TYPE_IS_FLAGS ##### -->
 
99
<para>
 
100
Returns whether @type "is a" %G_TYPE_FLAGS.
 
101
</para>
 
102
 
 
103
@type: a #GType ID.
 
104
 
 
105
 
 
106
<!-- ##### MACRO G_FLAGS_CLASS ##### -->
 
107
<para>
 
108
Casts a derived #GFlagsClass structure into a #GFlagsClass structure.
 
109
</para>
 
110
 
 
111
@class: a valid #GFlagsClass
 
112
 
 
113
 
 
114
<!-- ##### MACRO G_IS_FLAGS_CLASS ##### -->
 
115
<para>
 
116
Checks whether @class "is a" valid #GFlagsClass structure of type %G_TYPE_FLAGS
 
117
or derived.
 
118
</para>
 
119
 
 
120
@class: a #GFlagsClass
 
121
 
 
122
 
 
123
<!-- ##### MACRO G_FLAGS_CLASS_TYPE ##### -->
 
124
<para>
 
125
Returns the type identifier from a given #GFlagsClass structure.
 
126
</para>
 
127
 
 
128
@class: a #GFlagsClass
 
129
 
 
130
 
 
131
<!-- ##### MACRO G_FLAGS_CLASS_TYPE_NAME ##### -->
 
132
<para>
 
133
Returns the static type name from a given #GFlagsClass structure.
 
134
</para>
 
135
 
 
136
@class: a #GFlagsClass
 
137
 
 
138
 
 
139
<!-- ##### STRUCT GEnumValue ##### -->
 
140
<para>
 
141
A structure which contains a single enum value, it's name, and it's
 
142
nickname.
 
143
</para>
 
144
 
 
145
@value: the enum value
 
146
@value_name: the name of the value
 
147
@value_nick: the nickname of the value
 
148
 
 
149
<!-- ##### STRUCT GFlagsValue ##### -->
 
150
<para>
 
151
A structure which contains a single flags value, it's name, and it's
 
152
nickname.
 
153
</para>
 
154
 
 
155
@value: the flags value
 
156
@value_name: the name of the value
 
157
@value_nick: the nickname of the value
 
158
 
 
159
<!-- ##### FUNCTION g_enum_get_value ##### -->
 
160
<para>
 
161
Returns the #GEnumValue for a value.
 
162
</para>
 
163
 
 
164
@enum_class: a #GEnumClass
 
165
@value: the value to look up
 
166
@Returns: the #GEnumValue for @value, or %NULL if @value is not 
 
167
a member of the enumeration
 
168
 
 
169
 
 
170
<!-- ##### FUNCTION g_enum_get_value_by_name ##### -->
 
171
<para>
 
172
Looks up a #GEnumValue by name.
 
173
</para>
 
174
 
 
175
@enum_class: a #GEnumClass
 
176
@name: the name to look up
 
177
@Returns: the #GEnumValue with name @name, or %NULL if the enumeration doesn'
 
178
t have a member with that name
 
179
 
 
180
 
 
181
<!-- ##### FUNCTION g_enum_get_value_by_nick ##### -->
 
182
<para>
 
183
Looks up a #GEnumValue by nickname.
 
184
</para>
 
185
 
 
186
@enum_class: a #GEnumClass
 
187
@nick: the nickname to look up
 
188
@Returns: the #GEnumValue with nickname @nick, or %NULL if the enumeration doesn'
 
189
t have a member with that nickname
 
190
 
 
191
 
 
192
<!-- ##### FUNCTION g_flags_get_first_value ##### -->
 
193
<para>
 
194
Returns the first #GFlagsValue which is set in @value.
 
195
</para>
 
196
 
 
197
@flags_class: a #GFlagsClass
 
198
@value: the value
 
199
@Returns: the first #GFlagsValue which is set in @value, or %NULL if none is set
 
200
 
 
201
 
 
202
<!-- ##### FUNCTION g_flags_get_value_by_name ##### -->
 
203
<para>
 
204
Looks up a #GFlagsValue by name.
 
205
</para>
 
206
 
 
207
@flags_class: a #GFlagsClass
 
208
@name: the name to look up
 
209
@Returns: the #GFlagsValue with name @name, or %NULL if there is no flag with
 
210
that name
 
211
 
 
212
 
 
213
<!-- ##### FUNCTION g_flags_get_value_by_nick ##### -->
 
214
<para>
 
215
Looks up a #GFlagsValue by nickname.
 
216
</para>
 
217
 
 
218
@flags_class: a #GFlagsClass
 
219
@nick: the nickname to look up
 
220
@Returns: the #GFlagsValue with nickname @nick, or %NULL if there is no flag
 
221
with that nickname
 
222
 
 
223
 
 
224
<!-- ##### FUNCTION g_enum_register_static ##### -->
 
225
<para>
 
226
Registers a new static enumeration type with the name @name. 
 
227
</para>
 
228
<para>
 
229
It is normally more convenient to let <link linkend="glib-mkenums">glib-mkenums</link> 
 
230
generate a my_enum_get_type() function from a usual C enumeration definition
 
231
than to write one yourself using g_enum_register_static().
 
232
</para>
 
233
 
 
234
@name: A nul-terminated string used as the name of the new type.
 
235
@_static_values: 
 
236
@Returns: The new type identifier.
 
237
<!-- # Unused Parameters # -->
 
238
@const_static_values: An array of #GEnumValue structs for the possible
 
239
  enumeration values. The array is terminated by a struct with all 
 
240
  members being 0.
 
241
 
 
242
 
 
243
<!-- ##### FUNCTION g_flags_register_static ##### -->
 
244
<para>
 
245
Registers a new static flags type with the name @name. 
 
246
</para>
 
247
<para>
 
248
It is normally more convenient to let <link linkend="glib-mkenums">glib-mkenums</link> 
 
249
generate a my_flags_get_type() function from a usual C enumeration definition
 
250
than to write one yourself using g_flags_register_static().
 
251
</para>
 
252
 
 
253
@name: A nul-terminated string used as the name of the new type.
 
254
@_static_values: 
 
255
@Returns: The new type identifier.
 
256
<!-- # Unused Parameters # -->
 
257
@const_static_values: An array of #GFlagsValue structs for the possible
 
258
  flags values. The array is terminated by a struct with all members being 0.
 
259
 
 
260
 
 
261
<!-- ##### FUNCTION g_enum_complete_type_info ##### -->
 
262
<para>
 
263
This function is meant to be called from the complete_type_info() function 
 
264
of a #GTypePlugin implementation, as in the following example:
 
265
<informalexample>
 
266
<programlisting>
 
267
static void
 
268
my_enum_complete_type_info (GTypePlugin     *plugin,
 
269
                            GType            g_type,
 
270
                            GTypeInfo       *info,
 
271
                            GTypeValueTable *value_table)
 
272
{
 
273
  static const GEnumValue values[] = {
 
274
    { MY_ENUM_FOO, "MY_ENUM_FOO", "foo" },
 
275
    { MY_ENUM_BAR, "MY_ENUM_BAR", "bar" },
 
276
    { 0, NULL, NULL }
 
277
  };  
 
278
   
 
279
  g_enum_complete_type_info (type, info, values);  
 
280
}
 
281
</programlisting>
 
282
</informalexample>
 
283
</para>
 
284
 
 
285
@g_enum_type: the type identifier of the type being completed
 
286
@info: the #GTypeInfo struct to be filled in
 
287
@_values: 
 
288
<!-- # Unused Parameters # -->
 
289
@const_values: An array of #GEnumValue structs for the possible
 
290
  enumeration values. The array is terminated by a struct with all 
 
291
  members being 0.
 
292
 
 
293
 
 
294
<!-- ##### FUNCTION g_flags_complete_type_info ##### -->
 
295
<para>
 
296
This function is meant to be called from the complete_type_info() function 
 
297
of a #GTypePlugin implementation, see the example for 
 
298
g_enumeration_complete_type_info() above.
 
299
</para>
 
300
 
 
301
@g_flags_type: the type identifier of the type being completed
 
302
@info: the #GTypeInfo struct to be filled in
 
303
@_values: 
 
304
<!-- # Unused Parameters # -->
 
305
@const_values: An array of #GFlagsValue structs for the possible
 
306
  enumeration values. The array is terminated by a struct with all 
 
307
  members being 0.
 
308
 
 
309